Hi everyone,
I have the impression that the timezone global configuration documentation is not accurate - or is causing to render wrong offset times in Jekyll.
I tried several combinations, for page frontmatter “date: …”, and _config.yml
timezone: ...
".
Each time rebuilding the site and none give a reassuring result rendering the correct date in the page.
Situation:
I built my jekyll site locally on a mac running in the default timezone “Europe/Brussels”.
Just to be sure, I configure _config.yml
and set
timezone: Europe/Brussels
The docs say it has to be the IANA term “Europe/Brussels”.
So DST (Daylight Savings Time) is not active and my clock is +0100 offset from UTC.
A page has a date frontmatter value:
date: 2023-02-05 10:30:00
The time rendered on the page is one hour later: 11:30
OK. The documentation for page.date
states it assumes UTC. So 10:30 + 1 hour = 11:30
My bad. so I change page.date to:
date: 2023-02-05 10:30:00 +0100
The time rendered on the page is correct: 10:30
But here comes my problem: If the date is not in Februari but in Juli,
date: 2023-07-05 10:30:00 +0100
The time rendered on the page is wrong: 11:30
So I need to know whether Daylight Savings is active on a particular date, or not, and set page date with offset +0200 or +0100 instead!
So I fix it and set page.date to:
date: 2023-07-05 10:30:00 +0200
The time rendered on the page is now correct again: 10:30
Now what do I have to do to render the correct local time given February or July without having to know which date DST comes into effect?
Solution
Specify the page.date
time zone using a IANA term “Europe/Brussels” and not as an offset as mentioned in the “variables” chapter of the Jekyll docs. page.date
becomes then:
date: 2023-02-05 10:30:00 Europe/Brussels # February
… or …
date: 2023-07-05 10:30:00 Europe/Brussels # July
Both are rendered correctly now as 10:30 for a date in February or July.
“Europe/Brussels” causes the logic to take DST into account rendering the time - but only for page.date values - NOT as one would expect, because of the timezone in _config.yml
:
timezone: Europe/Brussels
Problem
The solution is undocumented, but tested - but I don’t know why it works.
A problem that goes away with no good reason will come back with no good reason?.
Stefaan Huysentruyt