New flexible timestamps in Drafts

One of the least-well-kept secrets in the iOS app world is the big jump in functionality that Drafts has made in the revisions released in last few weeks. I’m pretty sure that by the time I’m done writing this post Federico Viticci will have figured out a URL scheme that will have it making his breakfast. I’m going to focus on a more mundane feature: time and date stamps.

A couple of revisions ago, the good folks at Agile Tortoise added Dropbox Actions, which allow you to take the text in your current draft and use it to create, append to, or prepend to files in your Dropbox. To give you more control over these actions, a sort of macro language to Drafts was created. Certain words enclosed in double brackets will trigger the inclusion of meta information: [[title]] inserts the first line of the draft, for example, and [[body]] inserts all but the first line.

A few of the macros inserted time and date stamps, but unfortunately, the formatting of the stamps was fixed and didn’t match up with the kind of formatting I like to use. But with the most recent revision, Drafts has a time and date stamp macro that gives you the full power of the C/Unix strftime mini-language.

You’ve probably seen strftime formatting before. Because it’s a standard C library, lots of developers leverage it when they want to add time and date formatting to their language or application—it’s well-documented and familiar to many. Perl, Python, and Ruby all use it, as do apps like TextExpander (although TextExpander puts a user-friendly gloss over it).

The strftime formatting works by replacing certain codes in a text string with parts of the date or time. Each code starts with a percentage sign (%) and is followed by a letter that determines which date/time part is inserted. Characters that aren’t preceded by a % are taken literally. So

%m/%d/%y

will insert the current date in the American style, with the two-digit month, day of month, and year separated by slashes. Today, that would be replaced by

02/10/13

Similarly,

%I:%M %p

will be turned into

06:05 PM

Drafts has added strftime formatting by extending its existing macro system. To include codes like these in your Dropbox Action, you’d add

[[date|%m/%d/%y]]

or

[[date|%I:%M %p]]

to it. Just add a vertical bar and the strftime code after date in double brackets.

In the blog post introducing this new feature, Agile Tortoise linked to this summary of the strftime codes. It’s a good summary, but it’s missing a useful extensions that isn’t in every strftime implementation, but is in iOS and OSX. The extension—a hyphen that goes between the % and the letter code—gets rid of leading zeros.

You can see in the examples I gave where that would be useful. Although leading zeros in months and days can be helpful when you want to make sure all your date stamps are the same length, they aren’t the way we usually write dates. To suppress them, the datestamp code would be

[[date|%-m/%-d/%y]]

to give

2/10/13

and the timestamp code would be

[[date|%-I:%M %p]]

to give

6:05 PM

(You wouldn’t want to suppress the leading zero for minutes.)

If you look through the various codes available in strftime, you’ll see a couple—like %e for the day of the month and %l for the hour of the day—that you might think will do the same thing as the hyphen. They do eliminate the leading zero, but they replace it with a space, which probably isn’t what you want.

So how can this be used? I’m not an obsessive tracker of myself, but there are days when I need to carefully monitor what I’m doing and when. Here’s an action I’ve set up that’ll append a timestamped note to a Dropbox file named “Diary.txt.”

Dropbox Action for Diary

Hidden in the template is the blank line at the bottom. That gives me some separation between the entries, like this:

2/10/13 1:14 PM
Started 200° test

2/10/13 1:45 PM
Ended 200° test

2/10/13 1:54 PM
Started 300° test

The advantages of doing this in Drafts instead of directly editing a file in, say, Notesy and using TextExpander to add the timestamp are

The disadvantage of using Drafts is that it requires an Internet connection. Notesy can save everything on the phone and sync to Dropbox when a connection is available. This is less of a concern now than it was even a couple of years ago. And internetless areas will only get rarer.

Once you get the hang of it, automatic timestamps like this will seem natural, and you’ll want to use them more and more. After all, why should you be entering the time and date by hand when your phone already knows it?