-
-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Fix timezone incosistencies between different ruby version #6697
Conversation
it fails with ruby 2.4 onwards and passes up to ruby 2.3
In a real application this would have already been read as a date so make sure our scenario replicates that behaviour.
This makes sure we don't have inconsistencies between different ruby versions.
@@ -426,7 +426,7 @@ def merge_categories!(other) | |||
|
|||
private | |||
def merge_date!(source) | |||
if data.key?("date") && !data["date"].is_a?(Time) | |||
if data.key?("date") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the addition of tests 👍
What’s this line about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, didn't had time yesterday to properly update this PR with more information.
This change actually fixes the inconsistent behaviour, because as long as data['date']
is set it will call Utils.parse_date
which transforms the given data into localtime
(as determined by ENV['TZ']
). This is exactly the behaviour that SafeYAML was doing automatically before Ruby 2.4.
Because of the old version of this line, there were no inconsistencies between the different Ruby versions when data['date']
was interpreted as a String
rather than a Time
.
That said, I am not sure the behaviour of Ruby 2.3 is my preferred one, i would actually prefer the behaviour of newer ruby versions but the most important thing is to fix the incosistency and i would argue that jekyll users are more used to the behaviour of everything gets converted into whatever ENV['TZ'] is
.
@stomar @yous @Manishearth @t-brink Would love to hear your thoughts on this as you were quite involved in past discussions of this issue. cc: @jekyll/build |
@parkr It's not visible in the changed files so i mention it now here: This scenario jekyll/features/site_configuration.feature Line 184 in 603f2ea
|
In my local machine with KST timezone, $ ruby -e 'puts ENV["TZ"].inspect'
nil
$ date +"%Z %z"
KST +0900 The test
Is this intentional? I didn't set |
@yous Thanks! Looking at that test. |
In a real world example the post frontmatter would only be read during the build step after the configuration has already been applied. In a cucumber scenario though the frontmatter is read outside of any configuration so in this case the `timezone` setting of `UTC` wasn't applied.
@yous This issue only occured in a test and wouldn't have happened in a real application. This is because unlike during a real build, the frontmatter of the post is read before any configuration has been applied (in this case Time.new # 2018-01-20 20:58:12 +0900 e3b32f3 now makes sure that the timezone of the scenario is set before reading any post frontmatter. |
@Crunch09 Now every test passes. Thanks for the quick fix and explanation. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love to have someone from @jekyll/build review this before we land it!
Additionally, we can probably squeeze this in v3.7.1. What do you think, @jekyll/core? |
Merging this, assuming nobody has any further qualms with it. |
@jekyllbot: merge +bug |
Thanks @pup ! 🙇 |
tl;dr SafeYAML with Ruby < 2.4 parses times in the timezone currently set in the environment while SafeYAML for Ruby 2.4 keeps times in the timezone in which they were dumped in.
As described in issues like #5963 and #6033 the current
SafeYAML.load
behaviour depends on the ruby version.This scenario should have caught this, but unfortunately the dates in our scenarios were read as
String
instead ofTime
(which doesn't happen with a real frontmatter, see unit tests) so the issue didn't occur.5365355 should fix that and make this scenario fail in Ruby 2.4
jekyll/features/site_configuration.feature
Lines 184 to 204 in 603f2ea
I couldn't test so far locally with Ruby 2.5 but think the behaviour should stay the same as it is with Ruby 2.4
cc: @parkr Made a PR out of this because it might be easier to discuss and also CI runs then.