ruby-changes:54750
From: usa <ko1@a...>
Date: Thu, 31 Jan 2019 19:59:56 +0900 (JST)
Subject: [ruby-changes:54750] usa:r66967 (ruby_2_4): merge revision(s) 65974: [Backport #15340]
usa 2019-01-31 19:59:53 +0900 (Thu, 31 Jan 2019) New Revision: 66967 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66967 Log: merge revision(s) 65974: [Backport #15340] Normalize month-mday before finding epoch Especially over the year 2038, 30 Feb and so on may cause odd behavior on validating found epoch with given year-month-day [Bug #15340] Modified directories: branches/ruby_2_4/ Modified files: branches/ruby_2_4/test/ruby/test_time.rb branches/ruby_2_4/time.c branches/ruby_2_4/version.h Index: ruby_2_4/time.c =================================================================== --- ruby_2_4/time.c (revision 66966) +++ ruby_2_4/time.c (revision 66967) @@ -2574,6 +2574,29 @@ time_arg(int argc, VALUE *argv, struct v https://github.com/ruby/ruby/blob/trunk/ruby_2_4/time.c#L2574 vtm->mday = obj2ubits(v[2], 5); } + /* normalize month-mday */ + switch (vtm->mon) { + case 2: + { + /* this drops higher bits but it's not a problem to calc leap year */ + unsigned int mday2 = leap_year_v_p(vtm->year) ? 29 : 28; + if (vtm->mday > mday2) { + vtm->mday -= mday2; + vtm->mon++; + } + } + break; + case 4: + case 6: + case 9: + case 11: + if (vtm->mday == 31) { + vtm->mon++; + vtm->mday = 1; + } + break; + } + vtm->hour = NIL_P(v[3])?0:obj2ubits(v[3], 5); vtm->min = NIL_P(v[4])?0:obj2ubits(v[4], 6); Index: ruby_2_4/version.h =================================================================== --- ruby_2_4/version.h (revision 66966) +++ ruby_2_4/version.h (revision 66967) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1 #define RUBY_VERSION "2.4.6" #define RUBY_RELEASE_DATE "2019-01-31" -#define RUBY_PATCHLEVEL 342 +#define RUBY_PATCHLEVEL 343 #define RUBY_RELEASE_YEAR 2019 #define RUBY_RELEASE_MONTH 1 Index: ruby_2_4/test/ruby/test_time.rb =================================================================== --- ruby_2_4/test/ruby/test_time.rb (revision 66966) +++ ruby_2_4/test/ruby/test_time.rb (revision 66967) @@ -1043,6 +1043,29 @@ class TestTime < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/ruby/test_time.rb#L1043 assert_equal(min, t.min) assert_equal(sec, t.sec) } + assert_equal(Time.local(2038,3,1), Time.local(2038,2,29)) + assert_equal(Time.local(2038,3,2), Time.local(2038,2,30)) + assert_equal(Time.local(2038,3,3), Time.local(2038,2,31)) + assert_equal(Time.local(2040,2,29), Time.local(2040,2,29)) + assert_equal(Time.local(2040,3,1), Time.local(2040,2,30)) + assert_equal(Time.local(2040,3,2), Time.local(2040,2,31)) + n = 2 ** 64 + n += 400 - n % 400 # n is over 2^64 and multiple of 400 + assert_equal(Time.local(n,2,29),Time.local(n,2,29)) + assert_equal(Time.local(n,3,1), Time.local(n,2,30)) + assert_equal(Time.local(n,3,2), Time.local(n,2,31)) + n += 100 + assert_equal(Time.local(n,3,1), Time.local(n,2,29)) + assert_equal(Time.local(n,3,2), Time.local(n,2,30)) + assert_equal(Time.local(n,3,3), Time.local(n,2,31)) + n += 4 + assert_equal(Time.local(n,2,29),Time.local(n,2,29)) + assert_equal(Time.local(n,3,1), Time.local(n,2,30)) + assert_equal(Time.local(n,3,2), Time.local(n,2,31)) + n += 1 + assert_equal(Time.local(n,3,1), Time.local(n,2,29)) + assert_equal(Time.local(n,3,2), Time.local(n,2,30)) + assert_equal(Time.local(n,3,3), Time.local(n,2,31)) end def test_future Index: ruby_2_4 =================================================================== --- ruby_2_4 (revision 66966) +++ ruby_2_4 (revision 66967) Property changes on: ruby_2_4 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r65974 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/