Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 831726f2d221
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7733a41ed8b4
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Nov 27, 2017

  1. Copy the full SHA
    4be8d66 View commit details
  2. Copy the full SHA
    7733a41 View commit details
Showing with 18 additions and 3 deletions.
  1. +11 −3 core/src/main/java/org/jruby/RubyTime.java
  2. +7 −0 spec/ruby/core/time/shared/gm.rb
14 changes: 11 additions & 3 deletions core/src/main/java/org/jruby/RubyTime.java
Original file line number Diff line number Diff line change
@@ -1554,9 +1554,17 @@ private static RubyTime createTime(ThreadContext context, RubyClass klass, IRuby
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;
7 changes: 7 additions & 0 deletions spec/ruby/core/time/shared/gm.rb
Original file line number Diff line number Diff line change
@@ -19,4 +19,11 @@
it "interprets post-Gregorian reform dates using Gregorian calendar" do
Time.send(@method, 1582, 10, 15, 12).to_i.should == -12219249600 # 2299161j
end

it "handles fractional usec close to rounding limit" do
time = Time.send(@method, 2000, 1, 1, 12, 30, 0, 9999r/10000)

time.usec.should == 0
time.nsec.should == 999
end
end