Jekyll timezones

Software

Photo I took of Singapore in 2012

UPDATE: This date issue seems to be resolved as of Jekyll 1.5.1. As such, this post should be considered hysterical historical.

With almost four thousand posts written in different countries over the last nine years, I often feel as though my use case really tests the limits of Jekyll. To be fair, it has performed admirably.

One area where I've continued to struggle is with timezones. According to the Jekyll documentation, you declare timezones within the date YAML front matter for a post, such as this:

date: 2014-01-10 12:06:21 +1100

For posts written in Singapore and KL, I set the date with "+0800", with Adelaide as "+0930" and Sydney as "+1000" or "+1100" depending on daylight savings. Suddently, my times are even more accurate than they were when I exported them from WordPress last year, a nice feature!

There's just one catch. When Jekyll generates my site, these dates are converted to UTC. Under most circumstances this is fine; it's a more universally understood representation of the same time. Where this becomes a problem is human readable dates.

Say for example I posted this entry at 01:00 +1100. This means I'd expect my site to say Friday 10 January. Because it gets converted to UTC internally however, my blog says it was posted Thursday 09 January.

A temporary workaround

It's not very elegant, but for now I define a separate timezone variable in my post YAML front matter:

layout: post
title: "Jekyll timezones"
date: "2014-01-10T12:06:21+1100
tz: "+1100"
[..]

Now, whenever I need to show the date in my Liquid markup, I substitute the default Jekyll date functions with these:

{{ page.date | date: "%Y-%m-%dT%H:%M:%S" }}{{ page.tz }}
{{ page.date | date: "%A %d %B %Y" }}

Which generates these:

(Update 2021: Seven years later, and while fixing some HTML I realised this post was truncated! I have no idea what was supposed to be here. I suppose it's a moot point, given the issue was resolved years ago. Cheers).

Author bio and support

Me!

Ruben Schade is a technical writer and infrastructure architect in Sydney, Australia who refers to himself in the third person. Hi!

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite bespoke cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or send a comment. Thanks ☺️.