Inserts a date expanded from natural language when
>>date string< is typed.
- Natural language
- Unzip the archive and open the folder in Finder
- Move the file
makeadate.jsto a location on your hard drive where it can be referenced
- Install the
.kmmacrosfile in Keyboard Maestro
- Optionally, modify the default date and time format variables (dateFormat, timeFormat)
For the record, this script includes the entire Sugar.js library for handling the natural language. It was too much script to put into the KM editor, so placing it in an external file was the easiest solution.
To start converting a date (with the macro enabled), type
>>, then an optional format shortcut and modifiers, and the natural language version of the date and/or time. Type
< at the end of the string and Keyboard Maestro will run the script, replacing the entire string (including
<) with the result. If the string isn’t parseable, the original is returned.
You can type dates in many basic formats. Whether it’s absolute (e.g. “Nov 5 3pm”) or relative (e.g. “in 20 minutes”), most phrasings will work as long as the language doesn’t get too complex.
To create a relative date type
>>tomorrow< (or just
>>in 3 days<. Add a time to it using
3:30 pm (or any permutation). Create an absolute date by using a month and day, optionally a year and time:
>>jul 19 1978<, or
>>n 7/19/78 6am< to get “Wednesday, July 19th at 6:00 AM.”
Increments and shortcuts
When using relative times, you can increment and decrement by typing “in 3 days” or “3 days ago,” but you can abbreviate these with m, h, d, y, days, months, years, and min(utes). A number followed by one of these will increment the current time by that amount, and preceding with a minus symbol (
-3d) will decrement. Note that
3m is three minutes not months. To perform relative date calculation using months, you have to type the word out, e.g.
f: full → Saturday, November 12, 2016 12:00 AM
l: long → November 12, 2016 12:00 AM
m: medium → November 12, 2016
n: nice (ordinal date, “at” for time) → Saturday, November 12th at 3:00 PM
N: nice with year → Sunday, November 13th, 2016 at 3:00 PM
s: short → 11/12/2016
d: hyphenated date only → 2016-11-13
i: ISO timestamp → Sat Nov 12 2016 3:00 PM
t: time (12hr) → 06:30 PM
T: time (24hr) → 16:30
U: unix timestamp (milliseconds) → 1478984400000
u: unix timestamp → 1478984400
x: localized date/time string → Sat Nov 12 2016 1:20 PM
Examples created on 2016-11-12
Relative date and time:
>>5 days<→ 2016-11-17
>>5 days ago<→ 2016-11-07
>>15m<→ 2016-11-12 12:10pm
>>15m ago<→ 2016-11-12 11:40am
>>-30m<→ 2016-11-12 11:25am
Most recent Wednesday:
>>- wednesday<→ 2016-11-09
“last” skips to previous week:
>>last wed<→ 2016-11-02
>>sep 25<→ 2016-09-25
>>sep 25 1965<→ 1965-09-25
>>sep 25 2017 3pm<→ 2017-09-25 3:00pm
Relative date, absolute time:
>>3p tom<→ 2016-11-13 3:00pm
Full date format:
>>f sept 25 1965<→ Saturday, September 25, 1965 12:00 AM
“Nice” format with time:
>>n 3p tom<→ Sunday, November 13th at 3:00 PM
>>i now<→ Sat Nov 12 2016 1:19 PM
The format string uses strftime parameters and LDML tokens, which can be combined. See https://sugarjs.com/dates/#/Formatting for more information.
By default, if no time is specified in natural language, the output date in most formats will not include it. If an input string includes a time, the format specified in the
timeFormat variable will be appended to the date format. This doesn’t apply to
full, date-only (
You can include
r after or instead of a format shortcut to round times to the nearest half hour. If you add a number to it, you can change the amount that it rounds (
r60 to round to the nearest hour). This modifier should come after any format shortcuts:
>>lr30 in 4 hours<.
Why? Because most of the time when I write “in 2 hours” I don’t mean to the minute. At 12:36PM, I wanted “2 hours” to be 2:30PM.
If a string contains a weekday name or 3-letter abbreviation and does not include the words “last” or “ago”, future dates will automatically be forced. Thus typing “wed” will always assume you mean next wed by default.
You can include a
- (minus symbol) at the beginning (or immediately after a format option and modifiers), followed by a space to force allow past dates when they’re deemed appropriate. So
>>- thursday would allow it to return the most recent thursday instead of forcing it to find the next one. If using
a format option and/or modifiers, it must come at the end: