Jim Nielsen is asking the internet, or at least those building websites with static site generators, how they handle dates and times.
Heās running into some weirdness with dates, times, and timezones because heās using Metalsmith.
For me, I record the publish date once: in the filename (e.g.Ā 2023-05-16-my-slug.md). That YYYY-MM-DD string in the filename is the canonical location for my postsā publish date.
Now that date is fuzzy because, you know, timezones. If somebody looks at one of my blog posts and it says, āPublished 2023-05-16ā what does that mean? Is that today? Or yesterday? Well, it depends on where and when in the world youāre looking at that post. ā2023-05-16ā in Denver is not the same as ā2023-05-16ā in Melbourne.
This is something Iāve had to consider lately because after migrating from Mastodon to Friendica I had tried adding my siteās RSS feed as a contact so that its posts would get syndicated as my own. It doesnāt seem to work, and I thought it was because my RSS feed wasnāt valid. And why wasnāt it valid? Because the post dates in my metadata werenāt RFC 822 dates.
Why werenāt my post dates in RFC 822 format? It was my own damn fault. I had taken to inserting dates in Emacs using date -R
. However, I didnāt
read the fucking manual carefully enough, because the -R
switch is for RFC 53221.
-R, --rfc-email
- output date and time in RFC 5322 format. Example:
Mon, 14 Aug 2006 02:34:56 -0600
The long-form version of -R
, --rfc-email
should have been a dead giveaway. Likewise, if
I had bothered to actually read the RSS 2.0 spec. According to the spec, <pubDate>
needs to be Mon, 14 Aug 2006 02:34:56 EDT
.
Fortunately, date
can easily generate dates in that format, but the man page doesnāt tell you that you
need to use --rfc-822
. Maybe the info page does, but texinfo isnāt my favorite GNU project2 and Iād rather read a man
page than deal with the info
tool3.
So, once I figured that out I had to through all of my posts and fix the dates. Fortunately, I didnāt have
to do it manually. date
has a -d
switch that will let you specify a date and time other
than that given by the system clock. Thereās a catch, though. If you donāt specify the time zone youāll still get the
current time zone. So, if I run date --rfc-822 -d "2023-01-01 23:58:13"
today (May 19) the time will
will be given as EDT instead of EST, which which will result in an validation error in my RSS feed because we donāt do
Daylight Savings Time in January.
Thatās where the -u
or --utc
options come in handy. My postsā metadata gives all dates
and times as UTC (Universal Coordinated Time). That way, when the shell scripts I use to build my website process timestamps theyāll
apply the proper time zone and my feeds will validate. Also, I donāt just have timestamps in my RSS feeds. The date at
the top of each post? Thatās provided inside a <time>
element that prefers timestamps in ISO-8601 format.
So, thatās how my static site generator handles dates. I have a RFC-822 timestamp in UTC time in each postās ādateā
metadata field, and the varioous scripts I use feed it into date -d
with various options to generate
dates in the appropriate format.
Incidentally, when I was doing āview sourceā on Jim Nielsenās site to peek at the generator tag and see what he was using, I noticed the following.
<!--
š
Want to read the code behind this code?
Itās available on GitHub.
https://www.github.com/jimniels/blog/
-->
I like this, so Iām going to steal the idea for myself.