Contact lenses and date parsing again

After last week’s post on my contact lens calendar shortcut, a couple of readers tweeted1 me other ways to deal with dates in Shortcuts. I want to talk about one of them and how I used it in my rewrite of the shortcut. The rewrite was inspired less by the change in how the dates get parsed and more by a bug in another aspect of Shortcuts’s date handling. I’ll talk about that, too.

The date suggestion came from Tony (@stanthwaite), who showed how I could eliminate the parsing from my shortcut by setting the time directly in the date format.

Changing the time by reformatting

I am not a purist when it comes to variable typing. For many years, I programmed in Perl, where a string is a string, unless it looks like a number, in which case it’s a number, unless you treat it like a string, in which case it’s a string. You don’t hear Perl programmers talk much about language orthogonality. But I do find it distasteful to use a formatting command—which is there to set how the date and time are displayed as strings—to change the date and time themselves.

What bothers me most about this feature, though, is that it’s basically undiscoverable.2 Which gets to my main complaint about Shortcuts: its documentation is “try it and see.” That’s fine for a video game but not for a programming language.

Ultimately, I know I’ll get over my distaste, as using formatting to change a date or time can be really powerful. Thanks to Tony for teaching me this one weird trick.

As for the Shortcuts bug, it’s something I should have found in testing right away. Although the Ask for Input step at the top of the shortcut allows me to choose a date other than the default of the current date,

Old Contact Lens Calendar Step 01

the event that gets added to my calendar is always three weeks after the current date. No matter what I change the date to in the picker. Kind of makes the picker pointless.

Since I can’t fix the bug, I need to work around it. This got me thinking about how I expect to use the shortcut and whether I need the date picker at all. As I said in the original post, I expect to run this shortcut in the evening when I throw a set of contact lenses away. If I forget to do it then, I’ll run it the next morning when I start a new set. So I don’t really need to be able to choose any date. When asked for when I threw my contacts away, I just need to be able to answer Today or Yesterday. That calls for a menu, not a date picker.

Date choosing menu

With that in mind, here’s the new Contact Lens Calendar shortcut:

StepActionComment
1 Contact Lens Calendar Step 01 Get today’s date.
2 Contact Lens Calendar Step 02 Choose the day I threw away the last set of contacts.
3 Contact Lens Calendar Step 03 If it was today…
4 Contact Lens Calendar Step 04 Set the Throw Date variable to it. Hidden in this step is Tony’s trick to use formatting to set the time of Date (and therefore throwDate) to 9:00 PM.
5 Contact Lens Calendar Step 05 If it was yesterday…
6 Contact Lens Calendar Step 06 Get yesterday’s date…
7 Contact Lens Calendar Step 07 and set Throw Date to that. Use Tony’s trick again.
8 Contact Lens Calendar Step 08
9 Contact Lens Calendar Step 09 Now get the event date three weeks from Throw Date. This magic variable will be called End Date.
10 Contact Lens Calendar Step 10 And get the day after Throw Date. This magic variable will be called Start Date.
11 Contact Lens Calendar Step 11 Create an event for 9:00 PM with an alert. The event’s Notes tell me when I started wearing the current set and remind me to run this shortcut again to set the next event.

This is longer than the original shortcut, but it’s easier to use. And it actually works, which is helpful.


  1. I’m basically off Twitter. I do follow links that take me to Twitter’s website, and when I’m there I do look at my notifications. But email is really the best way to get in touch with me now. 

  2. It’s tempting to say this is part of Apple’s continuing trend toward hidden features—of a piece with long presses vs. long-but-not-that-long presses and swipes up from the bottom vs. swipes up-but-not-that-far-up from the bottom. But Shortcuts’ opacity can’t be blamed on Apple’s current design culture; it was a ball of undocumented features back when it was Workflow.