September 12, 2020 at 9:08 AM by Dr. Drang
I don’t want to keep talking about dates in Shortcuts, but I keep learning new things.
Yesterday, I said
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, 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.
This was wrong. There is no bug in the date picker. The source of the problem was a date parsing error later in the shortcut.
This morning, I was thinking about this “bug” and decided it didn’t make any sense. If the date picker didn’t work, surely there’d have been an outcry long ago; I wouldn’t be the first to run across it. So I started testing.
Here’s the simple testing shortcut:
I started out setting the custom date format of
Provided Input in Step 2 to the format Tony suggested:
yyyy MM dd 21:00:00.
When the date picker came up, I set it to September 10.
And the alert popped up with the time I wanted, 9:00 PM, but the date set to September 17—five days from today, not five days from the date I chose in the picker.
Adding hyphens to the custom date format,
fixed the problem. That weird format Europeans like,
dd MMM yyyy 21:00:00
also worked. Both of them gave a result of “Sep 15, 2020 at 9:00 PM” when I chose September 10 in the picker.
While I understand that there are limits to what Shortcuts can parse, I don’t understand the reversion to the current date when the parsing fails. By the time we get to the second step, Shortcuts should already know that I’ve chosen September 10 in the picker. But whatever the reason, the upshot is this: If you’re going to use a custom format to adjust a date or time, use the simplest format you can for the part that isn’t getting adjusted.
September 11, 2020 at 9:04 AM by Dr. Drang
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.
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 thestep at the top of the shortcut allows me to choose a date other than the default of the current date,
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.
With that in mind, here’s the new Contact Lens Calendar shortcut:
|1||Get today’s date.|
|2||Choose the day I threw away the last set of contacts.|
|3||If it was today…|
|5||If it was yesterday…|
|6||Get yesterday’s date…|
|9||Now get the event date three weeks from
|10||And get the day after
|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.
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. ↩
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. ↩
September 9, 2020 at 5:33 PM by Dr. Drang
The only question I want asked of the legendary journalist while he goes on another of his legendary promotional tours, is whether he ever ran across, in one of his legendary deep background interviews, anyone who estimated how many Americans died because he sat on Trump’s lies for six months to avoid spoiling his legendary book and depressing its legendary sales.
September 4, 2020 at 11:39 PM by Dr. Drang
I didn’t realize until today that Shortcuts has a date parser. It doesn’t call itself a date parser, and the documentation doesn’t explain what kinds of text strings it can parse, but it’s Shortcuts, so what would you expect?
I found it more or less by accident as I was writing a shortcut similar to this one from a few months ago. Last year, I switched from monthly contact lenses to semi-monthly. They’re thinner, more comfortable, and settle in place almost immediately.1 But without a big, obvious change in the calendar, I’ve found it harder to remember to change them in the middle of the month. On the plus side, I’ve inadvertently learned that I can wear them much longer than 15–16 days with no ill effects.
Based on this experience, I’ve decided I should switch them out every three weeks. Again, this is not a schedule I’m going to remember on my own, so I built a shortcut to run on the night I throw a set of lenses away. It adds an event to my personal calendar to remind me to throw the next set away in three weeks.
I expect to run the shortcut at any time of day, possibly even the next morning when I open up a new set of contacts. But I want the event—and the alert associated with it—to be at a particular time in the evening. This means I can’t get the date and time of the event by just adding three weeks to the date and time at which I run the shortcut. And I certainly wasn’t going to force myself to use those idiotic spinners to set the time—the time is fixed and the shortcut should handle it automatically.
Here’s my solution, which you can download:
|1||Get the date I threw away the last set of contacts. This should be the current date, but I allow an adjustment in case I run this the next morning.|
|2||Create a text string with the date from Step 1 and a time of 9:00 pm. The format of Provided Input is shown later in the post.|
|3||Here’s the parsing step. It turns the date string from Step 1 into a date/time combo.|
|4||This is the date/time for the calendar event. The magic variable for this step is called End Date.|
|5||If I throw the contacts away on the date set in Step 1, I start wearing a new set a day later. This magic variable is called Start Date.|
|6||Here we create a new calendar event for throwing away the next set of contacts. There’s an alarm and some information in the Notes field.|
Here’s how the Provided Input date is formatted:
As I said at the top, I don’t know all the formats the
yyyy-mm-dd HH:MM:SS would work, and it does.
Most scripting languages I’ve used have a way to change some date/time fields while leaving the others untouched, but Shortcuts apparently doesn’t. I was searching and scrolling, trying to find such a command, when I ran across. It does the job.
Why don’t I just set up an event that repeats every three weeks? Mainly because of my poor experience with doing that for switching out my CPAP supplies: the real world often intervenes, forcing you to change your carefully planned schedule. I find it easier to run a shortcut than to reset a recurring event. If I find that my contact lens schedule doesn’t change after several months of using this, I’ll switch to a long-running recurring event.
Update Sep 12, 2020 7:27 AM An updated shortcut, with a different way of setting the time and a workaround for a Shortcuts bug, is here.
I have astigmatism, so my contacts aren’t axisymmetric; they have to be oriented a particular way to work. They’re weighted to help them spin around to the right angle. When I was wearing monthlies, the right contact would usually take at least five minutes to rotate to the correct position and sometimes wouldn’t settle in for half an hour or so. ↩