Repository navigation
Conversation
DateTime.strptime('1.5', '%s.%N') dropped the fraction because
rt_rewrite_frags replaced sec_fraction with the fraction of seconds,
which is always 0 for %s. Add the parsed fraction to the seconds,
with the sign of the seconds as Time.strptime does (Bug #10904).
Member
|
You can use |
Author
|
Thanks, yes, If you would rather leave |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DateTime.strptimedrops the fraction when the seconds come from%s:Date._strptimeparses it fine ({seconds: 1, sec_fraction: (1/2)}), butrt_rewrite_fragsturnssecondsinto jd/hour/min/sec and then overwritessec_fractionwith the fraction ofseconds, which is always 0 for%s.This adds the parsed fraction to the seconds first, with the sign of the seconds, the same rule
Time.strptimeuses since Bug #10904 (-1.25is 1969-12-31 23:59:58.75). It only does this when the seconds are an Integer, so%Q(which already carries the milliseconds) behaves as before.I checked 20,000 random
%s.%Nvalues between 1874 and 2065, positive and negative:DateTime.strptimenow gives the same time asTime.strptimefor all of them (on master all 20,000 differ). The new test fails on master; the full suite passes on Ruby 4.0.9.One case still differs from what you'd expect, in both classes:
-0.5reads as +0.5, because_strptimereturnsseconds: 0and the minus sign is lost there.