ruby-changes:62417
From: Jeremy <ko1@a...>
Date: Wed, 29 Jul 2020 04:54:00 +0900 (JST)
Subject: [ruby-changes:62417] 520a734ad9 (master): Fix Time#ceil when result should be the same as the receiver
https://git.ruby-lang.org/ruby.git/commit/?id=520a734ad9 From 520a734ad9c7348f4e4858ee24640f42c88fd389 Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Fri, 24 Jul 2020 15:21:08 -0700 Subject: Fix Time#ceil when result should be the same as the receiver Fixes [Bug #17025] diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index 247bc34..0fc7dd7 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -1069,6 +1069,11 @@ class TestTime < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_time.rb#L1069 t2 = (t+0.123456789).ceil(4) assert_equal([59,59,23, 31,12,1999, 5,365,false,"UTC"], t2.to_a) assert_equal(Rational(1235,10000), t2.subsec) + + time = Time.utc(2016, 4, 23, 0, 0, 0.123456789r) + assert_equal(time, time.ceil(9)) + assert_equal(time, time.ceil(10)) + assert_equal(time, time.ceil(11)) end def test_getlocal_dont_share_eigenclass diff --git a/time.c b/time.c index 51b7a26..3073e15 100644 --- a/time.c +++ b/time.c @@ -4446,7 +4446,10 @@ time_ceil(int argc, VALUE *argv, VALUE time) https://github.com/ruby/ruby/blob/trunk/time.c#L4446 v = w2v(rb_time_unmagnify(tobj->timew)); v = modv(v, den); - return time_add(tobj, time, subv(den, v), 1); + if (!rb_equal(v, INT2FIX(0))) { + v = subv(den, v); + } + return time_add(tobj, time, v, 1); } /* -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/