-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
Time/Datetime conversion inconsistency with MRI #4810
Comments
Actually, I'm going to edit the title because I just verified that it isn't specific to BC times: JRuby:
MRI:
|
Sorry, I left out the Java version information:
|
I just tracked down that the point where this quirkiness starts to happen is in the years 1883-1884. Newer years appear to work correctly, older years are converted incorrectly. |
This is likely a similar problem to #4822, where it appears we use different logic to resolve historical dates. I can reproduce locally, and changing the chronology we use seems to help but does not completely solve it. Stock 9.1.14:
9.1.14 using ISO chronology in date.rb instead of Gregorian/Julian:
|
Note that the times in my last result are the same moment but have acquired a different timezone/offset. |
Oh I just realized that the last result from @rdubya also localizes the time zone, so it seems like the only fix needed is to use ISO chronology. The time zone localization was fixed in 2.4. @eregon My patch is obviously just brute force. I assume you arrived at this collection of conditionals for a reason...can you offer some insight into how we should handle this and #4822? |
I think the fix should be in Time#to_datetime, which seems buggy. |
The |
@eregon I'm a bit confused. You said:
And then you said:
Is it buggy or is there nothing to do? |
I meant there should be no need to mess with a chronology here, a Time converted to a DateTime just uses the default chronology. |
Ok, @eregon's suggested change does appear to fix #4822:
But it still does not match MRI for this bug:
|
@headius You should compare with MRI 2.4.0, before that MRI doesn't respect the timezone on DateTime#to_time. |
Ah but this issue is for JRuby 9.1, nevermind then. |
@eregon But I'm fixing this for 9.1, which is compatible with 2.3.0. And the time doesn't match anyway. |
Trying it locally I get:
So the Times do match at me. |
(My example above is without patch) |
Could MRI be rounding the timezone from -0550 to -0600 at you? |
@eregon I'm in America/Chicago TZ. Still unclear what the right fixes are. It would be nice to iron this out for 9.1.14. |
This should be fixed by 8da4e66 and spec added in 6c7ccbe. Both of these fixes use the original definition from date.rb in 1.9.2: Those methods were changed to optimize with Joda-DateTime but obviously the corner cases are wrong (e.g.: Joda throws an error when given a date which is in the middle of the reform) and there seems to be no simple solution, so I reverted to the original code. |
It looks like |
@rdubya JRuby appears to match expectations now. I think you may be seeing the difference between Ruby 2.4 (and later 2.3) that does not localize during to_time and 2.3 and earlier that still does. Here's my results for JRuby 9.1 versus Ruby 2.3:
And JRuby master (9.2) versus Ruby 2.4:
As you can see, the results match. There is an oddity on my local system where the time zone is coming back as -0550 rather than -0600 (I am in US Central Time, America/Chicago) but I don't think it's related to this issue.
|
Environment
Tested with JRuby 9.1.12.0 and JRuby 9.1.13.0 and compared to MRI 2.3.1
Expected Behavior
Actual Behavior
Example Cases
JRuby 9.1.13.0
MRI 2.3.1
The text was updated successfully, but these errors were encountered: