Using Dates and Times in Snippets: Advanced
One of the most basic yet handy Snippets in TextExpander is the current date. When it comes to customizing the date’s layout, many users don’t realize that TextExpander has supported Unicode Date Format Patterns since version 3.1. In addition to what you can do with TextExpander’s built-in date formatting, this adds support for:
– week of year, month
– calendar quarter
– day of year
– time zone
– more elaborate options for hour, minute, seconds, month, day, and year
– era (AD/BC)
– cyclic years (Chinese, Hindu calendars)
How to enter unicode using legacy date formats
If you are familiar with the prior style of entering TextExpander date formats in TextExpander v5 and earlier, with the <Percentage+Letter> notation, and you would like to still use that format to enter dates, switch the Content of the snippet from “Plain Text” or “Formatted Text, Picture” to one of the script formats. The macro syntax will be revealed, and you may put in whatever you wish. This will strip all formating if you are switching from a “Formatted Text, Picture” snippet. Once you are done entering your dates, switch back to your initial snippet Content style.
This is how you can enter Unicode dates, which support other speciality date styles.
Here are a few examples:
Week of year with leading zero for single-digit weeks (e.g. 02):
%date:ww%
Current calendar quarter and year (e.g. Q12019)
%date:QQQyyyy%
Time with long time zone (e.g. 8:11:49 AM America/Los_Angeles)
%date:h:mm:ss a’ ‘VV%
Please see the Unicode Date Format Patterns documentation for complete details.
Here are a few examples of special Snippets that you can use to insert current date and time:
%e %B %Y = 26 August 2021
%m/%d/%y = 08/26/21
%A, %B %e, %Y = Friday, August 26, 2021
%1I:%1M:%S %p = 4:02:41 PM
Expand Dates in Other Languages
Let’s say you run your system in English, but you live and work in Germany. When TextExpander expands dates, you get “Monday” instead of “Montag” which can leave you feeling melancholisch.
As with macOS, TextExpander uses the Language & Region system preferences settings to determine day and month names for dates. If English is at the top of your Preferred Languages list, that’s what TextExpander will use.
How to expand dates in a language other than your system’s default
You can achieve this by using a shell script Snippet and explicitly setting the language:
- Choose File -> New Snippet
- Set the Content: popup to “Shell Script”
- Set the Snippet content to:#!/bin/bash LANG=de_DE.UTF-8 date “+%d %B %Y”
- Set the abbreviation to whatever you like
- Type your abbreviation in another app
Now, rather than “Monday, July 25, 2021”, you’ll get “Montag, 25 Juli, 2021”, which should leave you feeling froh.
You can use any of the standard TextExpander date macros in place of the “%d %B %Y” above. Please note that you can’t use TextExpander’s date math macros, which are a way to quickly expand a date several days in the future, or past.
To use a language other than German, change the “de_DE” portion of the Snippet content to the two character ISO 639-1 language code for your language, followed by an underscore, followed by your two character ISO 3166-1 country code. Here are some examples:
- French: fr_FR
- Canadian French: fr_CA
- Italian: it_IT
- Japanese: ja_JP
- Portuguese: pt_PT
- Brazilian Portuguese: pt_BR
The Future
I know what you’re thinking: can’t we do this in JavaScript so that it works on my iPhone, iPad, and Windows machine? The answer is: not yet, but we hope soon.
The JavaScript engine in the Safari Developer Preview supports the ECMA Internationalization Specification. As the JavaScript engines are updated in macOS and iOS, we expect it will be possible to create a JavaScript Snippet like this:
var date = new Date(Date.UTC(2021, 1, 1, 14, 0, 0)); var options = { weekday: "long", year: "numeric", month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" }; date.toLocaleDateString("de-DE", options);
That Snippet will expand to:
Freitag, 1. Feb. 2021, 06:00
And that should make you euphorisch!
Unicode Date Format
Use the following special codes to insert days, months, years, and times.
%Y = Year, 4 digits (2021)
%y = Year, 2 digits (11)
%B = Month, long name (January)
%b = Month, short name (Jan)
%m = Month, 2 digits (01-12)
%1m = Month, 1-2 digits (1-12)
%A = Day, long name (Monday)
%a = Day, short name (Mon)
%d = Day, 2 digits (01-31)
%e = Day, 1 digit (1-31)
%1H = Hour, 24-hour clock, 1-2 digits (0-23)
%H = Hour, 24-hour clock, 2 digits (00-23)
%I = Hour, 12-hour clock, 2 digits (00-12)*
%1I = Hour, 12-hour clock, 1-2 digits (0-12)*
%M = Minute, 2 digits (00-59)
%1M = Minute, 1-2 digits (0-59)
%S = Second, 2 digits (00-59)
%1S = Second, 1-2 digits (0-59)
%p = Time, AM/PM
*Note the codes for 12-hour clock use a capital letter i
%date:<Unicode Date Format>%
(where <Unicode Date Format> is defined here:
http://unicode.org/reports/tr35/#Date_Format_Patterns
You can also have TextExpander expand the date or time macros above based on a time relative to today, such as tomorrow’s date. See “Date / Time Math” on this help page for details.
import bckups