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
Jekyll with Ruby 2.4 ignores timezone for date field of posts #5963
Comments
/cc @jekyll/stability |
I found out that SafeYAML.load changed the way how dates are handled. I don't know whether this change is intended or a bug. The behavior until 2.3 was that the parsed date is converted to the local timezone (that's also what Ruby's YAML.load does): RUBY_VERSION # => "2.3.3"
ENV["TZ"] = "UTC"
data = "date: 2017-01-01 06:00:00 +1200"
require "yaml"
YAML.load data # => {"date"=>2016-12-31 18:00:00 +0000}
require "safe_yaml"
SafeYAML.load data # => {"date"=>2016-12-31 18:00:00 +0000}
require "safe_yaml/version"
SafeYAML::VERSION # => "1.0.4" With 2.4, for the same SafeYAML version, this changes to keeping the timezone as provided in the RUBY_VERSION # => "2.4.0"
ENV["TZ"] = "UTC"
data = "date: 2017-01-01 06:00:00 +1200"
require "yaml"
YAML.load data # => {"date"=>2016-12-31 18:00:00 +0000}
require "safe_yaml"
SafeYAML.load data # => {"date"=>2017-01-01 06:00:00 +1200}
require "safe_yaml/version"
SafeYAML::VERSION # => "1.0.4" (Note that YAML.load has the same behavior for 2.3 and 2.4.) Jekyll then simply takes the date part of the post's |
I basically monkeypatched SafeYAML to fix this https://github.com/Manishearth/manishearth.github.io/blob/source/plugins/manish_custom_slug.rb |
This issue has been automatically marked as stale because it has not been commented on for at least two months. The resources of the Jekyll team are limited, and so we are asking for your help. If this is a bug and you can still reproduce this error on the If this is a feature request, please consider building it first as a plugin. Jekyll 3 introduced hooks which provide convenient access points throughout the Jekyll build pipeline whereby most needs can be fulfilled. If this is something that cannot be built as a plugin, then please provide more information about why in order to keep this issue open. This issue will automatically be closed in two months if no further activity occurs. Thank you for all your contributions. |
This is still a bug, and can be easily reproduced by writing a post with a given timezone specified, and then generating the blog with a different system time. |
I also can reproduce this bug, which makes me stick with Ruby 2.3. Here is some test code regarding timezone: https://github.com/yous/yous.github.io/blob/source/spec/site_spec.rb. |
https://pages.github.com/versions/ Github Pages has recently switched to Ruby 2.4.0. Most of the permalinks on my website are currently broken, and I think it's because of this. |
This issue has been automatically marked as stale because it has not been commented on for at least two months. The resources of the Jekyll team are limited, and so we are asking for your help. If this is a bug and you can still reproduce this error on the If this is a feature request, please consider building it first as a plugin. Jekyll 3 introduced hooks which provide convenient access points throughout the Jekyll build pipeline whereby most needs can be fulfilled. If this is something that cannot be built as a plugin, then please provide more information about why in order to keep this issue open. This issue will automatically be closed in two months if no further activity occurs. Thank you for all your contributions. |
This still exists, and I still have to work around it with the monkeypatch |
@Manishearth Do you have time to turn that monkeypatch into a pull request? |
I'm unsure if it's such a good idea to have such a monkeypatch in the jekyll tree? It's possible it will break other things. But sure, I can submit it if you can point me to where such monkeypatches go. |
@Manishearth I'm sorry, I misunderstood. You are patching SafeYAML rather than Jekyll. There is a PR for SafeYAML to preserve timezones of dates: dtao/safe_yaml#87 This is a pretty bad situation. I wonder if we need our own fork of SafeYAML? |
@Crunch09 That's not a bad thought. The nice thing about SafeYAML is that it is pure Ruby and doesn't require any C dependencies, which has been a source of frustration in the past. The nice thing about Psych is that it is actually maintained. How much work would it be to create a PR that removed SameYAML in favor of Psych? |
Don't think it would be too much work but i can try to come up with a PR sometime this week if you want and we can go from there? |
Does Psych offer "safe loading"? |
Still a bug. For the same reasons. |
Note that with Ruby 2.5, Psych will preserve the timezone offset of dates parsed from YAML, similar to what SafeYAML (accidently?) already seems to do in 2.4. This probably means that Jekyll has to handle the conversion to localtime or specified timezone itself, instead of relying on the YAML parser doing that. |
Would anyone here be willing to come up with some tests to help us get this one right? It sounds like Ruby and our YAML parsers are changing out from under us so we would ideally behave the same in all cases. Anecdotally, the dates change for me quite a bit when I travel to Europe/Asia/east of the Prime Meridian. That’s not super desirable. |
it fails with ruby 2.4 onwards and passes up to ruby 2.3
Fixed in #6697 |
We have posts with a date field in the YAML front matter that includes a timezone offset. The site is generated with UTC as local timezone.
The expected and established behavior in this setting is that post URL's are generated based on the date converted to UTC, such that e.g. a post with date
2017-01-01 06:00:00 +1200
appears under the URL.../2016/12/31/...
.This ensures for example that posts authored in different timezones will still be sorted and displayed in the proper chronological order.
Strangely, this behavior changes when switching from Ruby 2.3 to Ruby 2.4: with 2.4, the timezone offset seems to be ignored, and the post appears under the URL
.../2017/01/01/...
.This occurs without changing the Jekyll version; here I tested with Jekyll 3.3.1, but observed the same behavior also for earlier Jekyll releases.
For Ruby 2.4:
For Ruby 2.3 the URL is as expected:
The text was updated successfully, but these errors were encountered: