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: 15899bb21396
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: dad5ac56086f
Choose a head ref
  • 5 commits
  • 3 files changed
  • 2 contributors

Commits on Jun 5, 2017

  1. Copy the full SHA
    1ca3575 View commit details
  2. add test for #1779

    MSNexploder committed Jun 5, 2017
    Copy the full SHA
    f93e34f View commit details
  3. Copy the full SHA
    d2f5ab0 View commit details
  4. add better test for #1779

    MSNexploder committed Jun 5, 2017
    Copy the full SHA
    2fb9659 View commit details
  5. Merge pull request #4646 from MSNexploder/time_add

    try harder to avoid long overflow in Time#+ (fixes #1779)
    headius authored Jun 5, 2017
    Copy the full SHA
    dad5ac5 View commit details
Showing with 20 additions and 13 deletions.
  1. +6 −8 core/src/main/java/org/jruby/RubyTime.java
  2. +1 −3 test/jruby.index
  3. +13 −2 test/jruby/test_time.rb
14 changes: 6 additions & 8 deletions core/src/main/java/org/jruby/RubyTime.java
Original file line number Diff line number Diff line change
@@ -637,23 +637,21 @@ public IRubyObject op_plus(ThreadContext context, IRubyObject other) {
}
other = other.callMethod(context, "to_r");

long adjustNanos = (long)(RubyNumeric.num2dbl(other) * 1000000000);
return opPlusNanos(adjustNanos);
double adjustMillis = RubyNumeric.num2dbl(other) * 1000;
return opPlusMillis(adjustMillis);
}

@Deprecated
public IRubyObject op_plus19(ThreadContext context, IRubyObject other) {
return op_plus(context, other);
}

private IRubyObject opPlusNanos(long adjustNanos) {
private IRubyObject opPlusMillis(double adjustMillis) {
long currentMillis = getTimeInMillis();

long adjustMillis = adjustNanos/1000000;
long adjustNanosLeft = adjustNanos - (adjustMillis*1000000);

long newMillisPart = currentMillis + adjustMillis;
long newNanosPart = nsec + adjustNanosLeft;
long newMillisPart = currentMillis + (long)adjustMillis;
long adjustNanos = (long)((adjustMillis - Math.floor(adjustMillis)) * 1000000);
long newNanosPart = nsec + adjustNanos;

if (newNanosPart >= 1000000) {
newNanosPart -= 1000000;
4 changes: 1 addition & 3 deletions test/jruby.index
Original file line number Diff line number Diff line change
@@ -74,9 +74,7 @@ jruby/test_thread
# FIXME probably should figure this one out
#test_thread_backtrace
jruby/test_threaded_nonlocal_return
jruby/test_time_add
jruby/test_time_nil_ops
jruby/test_time_tz
jruby/test_time
jruby/test_unmarshal
jruby/test_vietnamese_charset
jruby/test_win32
15 changes: 13 additions & 2 deletions test/jruby/test_time.rb
Original file line number Diff line number Diff line change
@@ -41,11 +41,22 @@ def test_tz_with_minutes
def test_nsec_rounding # GH-843
t1 = Time.utc(2013,6,30,14,56,14,263031.604)
t2 = Time.utc(2013,6,30,14,56,14,263031.605)
assert_equal t1.usec, t2,usec
assert_not_equal t1.nsec, t2,nsec
assert_equal t1.usec, t2.usec
assert_not_equal t1.nsec, t2.nsec
assert_false t1 == t2
end

def test_large_add # GH-1779
t = Time.local(2000, 1, 1) + (400 * 366 * 24 * 60 * 60)
assert_equal 2400, t.year
end

def test_far_future
now = Time.now
t1 = now + 80000000000
t2 = now + 90000000000
assert_false t1 == t2
end
end

class TestTimeNilOps < Test::Unit::TestCase