-
-
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
Rails parsing time ends with usec 1 instead of 0 #4866
Comments
Reduced repro: Time.utc(2000, 1, 1, 12, 30, 0, 9999r/10000).usec Something about how we're handling the fractional seconds. |
Also affects master (9.2). |
This patch appears to work, perhaps because it does more of the nanos/micros math in Rational form before converting to a double. @kares You had a patch in this code to adjust how it rounds. What do you think? diff --git a/core/src/main/java/org/jruby/RubyTime.java b/core/src/main/java/org/jruby/RubyTime.java
index 395e948aca..a986c77d68 100644
--- a/core/src/main/java/org/jruby/RubyTime.java
+++ b/core/src/main/java/org/jruby/RubyTime.java
@@ -1554,9 +1554,17 @@ public class RubyTime extends RubyObject {
boolean fractionalUSecGiven = args[6] instanceof RubyFloat || args[6] instanceof RubyRational;
if (fractionalUSecGiven) {
- double micros = RubyNumeric.num2dbl(args[6]);
- time.dt = dt.withMillis(dt.getMillis() + (long) (micros / 1000));
- nanos = (long) Math.rint((micros * 1000) % 1000000);
+ if (args[6] instanceof RubyRational) {
+ RubyRational usecRat = (RubyRational) args[6];
+ RubyRational nsecRat = (RubyRational) usecRat.op_mul(context, runtime.newFixnum(1000));
+ double tmpNanos = nsecRat.getDoubleValue(context);
+ time.dt = dt.withMillis((long) (dt.getMillis() + (tmpNanos / 1000000)));
+ nanos = (long) tmpNanos % 1000000;
+ } else {
+ double micros = RubyNumeric.num2dbl(args[6]);
+ time.dt = dt.withMillis(dt.getMillis() + (long) (micros / 1000));
+ nanos = (long) Math.rint((micros * 1000) % 1000000);
+ }
} else {
int usec = int_args[4] % 1000;
int msec = int_args[4] / 1000; |
@headius aah, interesting - so its a matter of rounding, thought JRuby passes a default |
I think this fix has raised a different issue |
fixes jruby#4989 ... follow-up on jruby#4866 (4be8d66)
Environment
did not dig further down the rabbit hole ...
the reproducer does not need a DB setup.
JRuby 9.1.14.0
ActiveRecord 5.0.6
Expected Behavior
MRI 2.3.3
Actual Behavior
The text was updated successfully, but these errors were encountered: