You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Missing timezone in metadata date can lead to wrong date in url #1069
Starting with a fresh new Jekyll site with no modifications, I noticed that the first auto-generated post got the wrong page date when served. It looks like a missing timezone in the posts metadata can lead to the generated url being one day off when the time is close enough to midnight.
Metadata of file /_posts/2013-05-09/welcome-to-jekyll.markdown:
---
layout: post
title: "Welcome to Jekyll!"
date: 2013-05-09 22:39:53
categories: jekyll update
---
This leads to the post having url /jekyll/update/2013/05/10/welcome-to-jekyll.html, which can be explained by me being in a timezone with offset +0200.
The url I expected to see was /jekyll/update/2013/05/09/welcome-to-jekyll.html.
Changing or removing the time part of the metadata (or adding timezone info) fixes the problem as expected, but it left me puzzled for a moment.
I'm sorry, I should have added that bit of information: System timezone in /etc/timezone is Europe/Amsterdam. To my best knowledge, Ruby uses that info. Also, adding the timezone to the config file did not change the situation. So what parkr says seems to be the case: the time/date is converted to UTC where it probably should not.
So @parkr and I took a look at this and there seems to be nothing wrong with how the time / date are parsed (it always ends up in your local timezone).
I am not sure how your url would have rolled over like that. We checked to make sure the time didn't default to UTC or have any wonkiness.
Doesn't seem to be anything wrong at present with it.
@zachgersh I agree with you that no strange things seem to happen in ie. post.rb when it comes to parsing and formatting dates. If no one else experiences this one-day-off error then I guess there is something wrong on my side.
If I edit the date of the post in metadata to 2013-07-30 17:57:28+0800, everything works fine.
It seems that Jekyll parses the date in metadata with default timezone set to UTC (if no timezone info is specified in the date string), but then generates the link according to the system default timezone.
It would be better either 1) to generate system timezone aware date string in metadata when running jekyll new blog or 2) to parse the date in metadata with default timezone set to system timezone.
Having to add the timezone to the date metadata is pretty awful. Why do I have to specify it in _config.yml, then? Why not just assume every date without a specified timezone to have the one specified in _config.yml?
It parses dates as DateTime, but then converts them to Time and always returns the value in local time. In my opinion, this is totally the wrong thing to do since (if I'm correctly understanding how time is handled in ruby) you're throwing away any TZ data that was there.
So they fixed this in Ruby 2.2.0, which broke Jekyll's expectations that it'd be in your local timezone (that's what my blog post is about).
I imagine having safe_yaml return the DateTime object would be a pretty major breaking change for them and not realistic.
It parses dates as DateTime, but then converts them to Time and always returns the value in local time. In my opinion, this is totally the wrong thing to do since (if I'm correctly understanding how time is handled in ruby) you're throwing away any TZ data that was there.
So they fixed this in Ruby 2.2.0, which broke Jekyll's expectations that it'd be in your local timezone (that's what my blog post is about).
Oh, interesting.. so I somehow missed that. So now this means that ruby 2.2 is preserving the TZ information correctly, but now it's Jekyll that is throwing it away by always calling localtime 😞 I know that this is how Jekyll has always worked historically and perhaps has some assumptions built in for this, but it still makes me sad because we're throwing away the data. If a post date is specified without TZ information, then sure treat it as localtime. But if an author has taken the effort to specify the TZ in the post date, then it seems very unfortunate that we don't respect and preserve that.
if a date is specified as a string, then you could additionally parse it as a DateTime and preserve the TZ info that way.
Right now we use Time.parse – should we switch to using DateTime.parse?
Maybe? I'm not sure where else Time and DateTime differ and what problems this could potentially introduce. I seem to recall that some of our date-related liquid filters choked on a DateTime, but don't remember fully.
To solve my specific issue, I wrote a tiny Jekyll filter that will apply your local timezone offset to a custom front matter date. Be careful when using with something like a heroku deploy script - I haven't tested there, although tzinfo is explicitly setting the timezone based on Jekyll config:
I just started using Jeykll and just noticed this. I have converted posts from a legacy/proprietary system where each post had a date and a time (but no timezone). Everything was a full day off (My localtime is set to Australia/Melbourne).
I feel like if I don't specify a timezone, than those are the dates/times I want to use when displaying to the user. They really shouldn't go through any conversion at all. (and even if I do specify a timezone...there should really only be a conversion if the _config.yml has a different timezone). We're talking about static content here; not content that changes depending on the connecting browser.
There should be an option to disable any timezone alteration entirely, although judging from the comments, I'm not sure if that's entirely possibly if this is depending on the underlying YAML engine.
This is more than likely a problem with the object we use rather than the way we use the object, DateTime sucks when an explicit timezone isn't supplied and if I remember we are using DateTime objects?
Posted something at 1:22 AM New York time (UTC - 4 hours) and put in the data without time zone as '2015-05-22 01:22:00' (assuming it would show up correctly since I have 'timezone: America/New_York' in my _config.yml file), but the URL slug and the post date both show up as the day before. This doesn't seem like the type of behavior you'd expect by default.
Trying to follow years of timezone posts,,, It would be nice to be able to specify a time and have the timezone modify that time appropriately on compilation.
This issue affects a bunch of pages for me and also has an impact on some automatic redirection logic I have set up since the date portions of the links don't match up.
If there's something I need to change, I'm all for changing it but it seems like this is an issue with how Jekyll is parsing the date front matter variable to generate the URL. If the date has timezone information provided (which mine does) it should always use that timezone.
Interestingly enough, as I was writing this I decided to try setting the date to the corresponding UTC time (2015-05-29 03:23:39) which still had no effect. However, when I set the date back to the original and removed the time zone portion, it was generated with the correct date in the URL. This behavior seems widly inconsistent, as other pages seem to work just fine with the time zone in the date (as a string) (see https://github.com/scottdorman/scottdorman.github.io/blob/master/_posts/2018/2018-08-18-saving-bootstrap-component-state.md as an example). It seems like where things start to go wrong is when the time approaches that roll-over period in UTC (so, for my time zone any dates earlier than 19:00:00 generate with the correct date and anything after would appear to generate with the wrong date).
@scottdorman This is a very old ticket.
Please open a new ticket providing us with the relevant information about the issue and your Jekyll environment.
Activity
zachgersh commentedon May 10, 2013
by chance, what is your system timezone set to?
parkr commentedon May 10, 2013
He says it's "+0200" above, which is my timezone as well. Central European.
zachgersh commentedon May 10, 2013
Didn't you add specification of timezone to support just this issue?
parkr commentedon May 10, 2013
Yes, but there's an edgecase: if you don't specify the timezone when making posts and pages, it assumes it's UTC, I guess.
zwippie commentedon May 10, 2013
I'm sorry, I should have added that bit of information: System timezone in
/etc/timezoneisEurope/Amsterdam. To my best knowledge, Ruby uses that info. Also, adding the timezone to the config file did not change the situation. So what parkr says seems to be the case: the time/date is converted to UTC where it probably should not.parkr commentedon May 10, 2013
i will look into this more, probably something i'd want to make into the gh pages release //cc @benbalter
zachgersh commentedon May 11, 2013
So @parkr and I took a look at this and there seems to be nothing wrong with how the time / date are parsed (it always ends up in your local timezone).
I am not sure how your url would have rolled over like that. We checked to make sure the time didn't default to UTC or have any wonkiness.
Doesn't seem to be anything wrong at present with it.
zwippie commentedon May 12, 2013
@zachgersh I agree with you that no strange things seem to happen in ie. post.rb when it comes to parsing and formatting dates. If no one else experiences this one-day-off error then I guess there is something wrong on my side.
For the sake of completeness:
Linux Debian 6 kernel 2.6.32-5-amd64
rvm 1.15.7
ruby 1.9.3p194
Jekyll 1.01
zachgersh commentedon May 12, 2013
Well, I don't want to claim it is not there just because I didn't experience it 😄
The only thing I could possibly think of is daylight savings having something to do with it but that feels like a stretch.
Just out of curiosity can you double check in your IRB that your offset is what you expect it to be from Ruby?
zachgersh commentedon May 13, 2013
I think we can close this for now @parkr.
@zwippie please reopen if you stumble across this and have new info.
allxiao commentedon Aug 2, 2013
I've experienced this issue on my first taste of Jekyll today.
The default timezone of my Mac OS X system is set to CST (+0800).
The generated example post (by
jekyll new blog) have metadata as followed:And after running
jekyll serve, the URL for the post isIf I edit the date of the post in metadata to
2013-07-30 17:57:28+0800, everything works fine.It seems that Jekyll parses the date in metadata with default timezone set to UTC (if no timezone info is specified in the date string), but then generates the link according to the system default timezone.
It would be better either 1) to generate system timezone aware date string in metadata when running
jekyll new blogor 2) to parse the date in metadata with default timezone set to system timezone.Thanks~
parkr commentedon Aug 5, 2013
Adding the timezone is a great idea! We also want to create generators which create new posts - we'll add it there as well.
parkr commentedon Aug 6, 2013
Rel: #1148.
makkes commentedon Sep 3, 2013
Having to add the timezone to the date metadata is pretty awful. Why do I have to specify it in _config.yml, then? Why not just assume every date without a specified timezone to have the one specified in _config.yml?
13 remaining items
parkr commentedon Mar 7, 2015
So they fixed this in Ruby 2.2.0, which broke Jekyll's expectations that it'd be in your local timezone (that's what my blog post is about).
@dtao, how would you feel about this?
Right now we use
Time.parse– should we switch to usingDateTime.parse?willnorris commentedon Mar 7, 2015
Oh, interesting.. so I somehow missed that. So now this means that ruby 2.2 is preserving the TZ information correctly, but now it's Jekyll that is throwing it away by always calling
localtime😞 I know that this is how Jekyll has always worked historically and perhaps has some assumptions built in for this, but it still makes me sad because we're throwing away the data. If a post date is specified without TZ information, then sure treat it as localtime. But if an author has taken the effort to specify the TZ in the post date, then it seems very unfortunate that we don't respect and preserve that.Maybe? I'm not sure where else
TimeandDateTimediffer and what problems this could potentially introduce. I seem to recall that some of our date-related liquid filters choked on aDateTime, but don't remember fully.pathawks commentedon Mar 7, 2015
👍 This has also often bothered me.
13protons commentedon Mar 10, 2015
To solve my specific issue, I wrote a tiny Jekyll filter that will apply your local timezone offset to a custom front matter date. Be careful when using with something like a heroku deploy script - I haven't tested there, although tzinfo is explicitly setting the timezone based on Jekyll config:
https://gist.github.com/alanguir/72c6d22d95f3ed80a511
sumdog commentedon May 12, 2015
I just started using Jeykll and just noticed this. I have converted posts from a legacy/proprietary system where each post had a date and a time (but no timezone). Everything was a full day off (My localtime is set to Australia/Melbourne).
I feel like if I don't specify a timezone, than those are the dates/times I want to use when displaying to the user. They really shouldn't go through any conversion at all. (and even if I do specify a timezone...there should really only be a conversion if the _config.yml has a different timezone). We're talking about static content here; not content that changes depending on the connecting browser.
There should be an option to disable any timezone alteration entirely, although judging from the comments, I'm not sure if that's entirely possibly if this is depending on the underlying YAML engine.
envygeeks commentedon May 12, 2015
This is more than likely a problem with the object we use rather than the way we use the object, DateTime sucks when an explicit timezone isn't supplied and if I remember we are using DateTime objects?
jaypinho commentedon May 22, 2015
Just ran into the same problem here as well.
Posted something at 1:22 AM New York time (UTC - 4 hours) and put in the data without time zone as '2015-05-22 01:22:00' (assuming it would show up correctly since I have 'timezone: America/New_York' in my _config.yml file), but the URL slug and the post date both show up as the day before. This doesn't seem like the type of behavior you'd expect by default.
Add date to first post
chemoish commentedon Jul 21, 2016
Trying to follow years of timezone posts,,, It would be nice to be able to specify a time and have the
timezonemodify that time appropriately on compilation.2017-02-12 14:30:00+America/Los_Angeles=2017-02-12 14:30:00 -08002017-04-02 14:30:00+America/Los_Angeles=2017-04-02 14:30:00 -0700/shrug
Remove timezone from welcome post
attempt to fix date/time by setting timezone
scottdorman commentedon Feb 26, 2019
This issue seems to still exist. Look at
https://scottdorman.github.io/2015/05/29/introducing-jquery-gotop/https://scottdorman.github.io/2015/05/28/introducing-jquery-gotop/as an example. The date portion of the link gets set to2015/05/29even though the front matter hasdate: '2015-05-28 23:23:39.00000000 -05:00'and my _config.yml hastimezone: America/New_York. I have tried the front matter date in several variations and none of them seem to make any difference.This issue affects a bunch of pages for me and also has an impact on some automatic redirection logic I have set up since the date portions of the links don't match up.
If there's something I need to change, I'm all for changing it but it seems like this is an issue with how Jekyll is parsing the date front matter variable to generate the URL. If the date has timezone information provided (which mine does) it should always use that timezone.
Interestingly enough, as I was writing this I decided to try setting the date to the corresponding UTC time (2015-05-29 03:23:39) which still had no effect. However, when I set the date back to the original and removed the time zone portion, it was generated with the correct date in the URL. This behavior seems widly inconsistent, as other pages seem to work just fine with the time zone in the date (as a string) (see https://github.com/scottdorman/scottdorman.github.io/blob/master/_posts/2018/2018-08-18-saving-bootstrap-component-state.md as an example). It seems like where things start to go wrong is when the time approaches that roll-over period in UTC (so, for my time zone any dates earlier than 19:00:00 generate with the correct date and anything after would appear to generate with the wrong date).
ashmaroli commentedon Feb 26, 2019
@scottdorman This is a very old ticket.
Please open a new ticket providing us with the relevant information about the issue and your Jekyll environment.