-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing timezone in metadata date can lead to wrong date in url #1069
Comments
by chance, what is your system timezone set to? |
He says it's "+0200" above, which is my timezone as well. Central European. |
Didn't you add specification of timezone to support just this issue? |
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. |
I'm sorry, I should have added that bit of information: System timezone in |
i will look into this more, probably something i'd want to make into the gh pages release //cc @benbalter |
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. For the sake of completeness: Linux Debian 6 kernel 2.6.32-5-amd64 |
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? |
I've experienced this issue on my first taste of Jekyll today.
The generated example post (by
And after running
If I edit the date of the post in metadata to 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 Thanks~ |
Adding the timezone is a great idea! We also want to create generators which create new posts - we'll add it there as well. |
Rel: #1148. |
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? |
We can't make that assumption :( What if we provided a generator like in #1148? |
Hmm, breaking my head over this ;) When I use I'm reading above that this shouldn't happen, is there something I'm missing? |
I found that a bunch of my dates were off after an import even though it had given timezones. Changing Not sure if this is illegal yaml, a yaml parsing problem, or something after |
Very helpful, thanks for posting @zwippie |
I'm experiencing this as an issue too, and it definitely feels broken. I'd only expect the output of the date filter to match UTC if I were, in fact, on UTC +0000. I didn't notice this when working just with dates, but it was immediately apparent when trying to work with hours. IRB tells me I have my time set correctly
timezone: America/Detroit
markdown: kramdown
encoding: utf-8
... Post front matter has a dates array in local time
No funky tricks in the date rendering:
And the rendered HTML shows times in UTC. ( that should be 6pm (18:00) - 9pm(21:00), rather than 2pm and 5pm respectively ).
Miraculously, jekyll does correctly calculate daylight savings time by only rending the UTC time as -0400 instead of the usual -0500 for my part of the world. ps - jekyll 2.5.3 |
Update: setting my timezone to |
@alanguir This behaviour is per |
@parkr I understand how this could cause unexpected results if I'm writing my times assuming UTC +5, and jekyll has a build script that runs when I deploy on a heroku server living in UTC +8, but why ignore the explicit timezone setting in the config file? That seems like a perfectly good way to know what the time should be. What is the timezone config option used for if not helping jekyll parse dates at build time? |
All it does is set Think of it like excluded bits of data without a default. |
yep, I ran into the crappy support for timezones in Ruby when I switched to Jekyll too. In my case, I very specifically want to preserve the timezone of when a post was written, and display that on my site (for example, compare by-lines here vs here). For me, that additional bit of data is meaningful. I do this by ensuring that I always specify dates as strings in my frontmatter (otherwise the yaml module will "helpfully" parse them as |
@willnorris Do you see a bugfix path for safe_yaml or Jekyll in this regard? |
@parkr I've never actually looked closely at what safe_yaml does before, but now this does make sense: date.rb. It parses dates as |
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 |
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
Maybe? I'm not sure where else |
👍 This has also often bothered me. |
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? |
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. |
Also noticed that Jekyll has some issues with timezones. cf jekyll/jekyll#1069
Trying to follow years of timezone posts,,, It would be nice to be able to specify a time and have the
/shrug |
Setting the _config timezone didn't solve the issue. Maybe I should add timezone to all dates in all posts, but I'm going to try this first. I'm not concerned about capturing the local time (I think). Possibly related: jekyll/jekyll#1069
Following jekyll/jekyll#1069 to attempt to fix the incorrect dates
This issue seems to still exist. Look at 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. |
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
: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.
The text was updated successfully, but these errors were encountered: