[前][次][番号順一覧][スレッド一覧]

ruby-changes:60589

From: usa <ko1@a...>
Date: Tue, 31 Mar 2020 06:46:41 +0900 (JST)
Subject: [ruby-changes:60589] b4446de7ad (ruby_2_5): merge revision(s) d6a2bce64a7fa1099e507e1d36b5f1533f42f60f,c687be4bc01c9ce52ea990945d9304d6fe59fe9b: [Backport #16159]

https://git.ruby-lang.org/ruby.git/commit/?id=b4446de7ad

From b4446de7ad658708571bde6673ee179de7b98761 Mon Sep 17 00:00:00 2001
From: usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date: Mon, 30 Mar 2020 21:46:27 +0000
Subject: merge revision(s)
 d6a2bce64a7fa1099e507e1d36b5f1533f42f60f,c687be4bc01c9ce52ea990945d9304d6fe59fe9b:
 [Backport #16159]

	time.c (find_time_t): fix round-to-zero bug

	`find_time_t` did not work correctly for year older than the Epoch
	because it used C's integer division (which rounds negative to zero).

	For example, `TIme.new(1933)` returned a wrong time whose year is 1922
	in Asia/Kuala_Lumpur because there is no 00:00:00 1st Jan. 1933 in the
	time zone.

	```
	$ TZ=Asia/Kuala_Lumpur ruby -e 'p Time.new(1933)'
	1932-12-31 00:00:00 +0700
	```

	This change fixes the issue by using `DIV` macro instead of `/`.
	Now `Time.new(1933)` returns a time in 1933.

	```
	$ TZ=Asia/Kuala_Lumpur ruby -e 'p Time.new(1933)'
	1933-01-01 00:20:00 +0720
	```

	[Bug #16159]

	Added a test for [Bug #16159]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@67864 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

diff --git a/test/ruby/test_time_tz.rb b/test/ruby/test_time_tz.rb
index 8be7294..bfe9b4e 100644
--- a/test/ruby/test_time_tz.rb
+++ b/test/ruby/test_time_tz.rb
@@ -155,6 +155,12 @@ class TestTimeTZ < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_time_tz.rb#L155
     }
   end
 
+  def test_asia_kuala_lumpur
+    with_tz(tz="Asia/Kuala_Lumpur") {
+      assert_time_constructor(tz, "1933-01-01 00:20:00 +0720", :local, [1933])
+    }
+  end
+
   def test_canada_newfoundland
     with_tz(tz="America/St_Johns") {
       assert_time_constructor(tz, "2007-11-03 23:00:59 -0230", :new, [2007,11,3,23,0,59,:dst])
diff --git a/time.c b/time.c
index 1967c5d..0470775 100644
--- a/time.c
+++ b/time.c
@@ -2958,12 +2958,12 @@ find_time_t(struct tm *tptr, int utc_p, time_t *tp) https://github.com/ruby/ruby/blob/trunk/time.c#L2958
 
     *tp = guess_lo +
           ((tptr->tm_year - tm_lo.tm_year) * 365 +
-           ((tptr->tm_year-69)/4) -
-           ((tptr->tm_year-1)/100) +
-           ((tptr->tm_year+299)/400) -
-           ((tm_lo.tm_year-69)/4) +
-           ((tm_lo.tm_year-1)/100) -
-           ((tm_lo.tm_year+299)/400) +
+           DIV((tptr->tm_year-69), 4) -
+           DIV((tptr->tm_year-1), 100) +
+           DIV((tptr->tm_year+299), 400) -
+           DIV((tm_lo.tm_year-69), 4) +
+           DIV((tm_lo.tm_year-1), 100) -
+           DIV((tm_lo.tm_year+299), 400) +
            tptr_tm_yday -
            tm_lo.tm_yday) * 86400 +
           (tptr->tm_hour - tm_lo.tm_hour) * 3600 +
diff --git a/version.h b/version.h
index 9fca24e..76a8079 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L1
 #define RUBY_VERSION "2.5.8"
 #define RUBY_RELEASE_DATE "2020-03-31"
-#define RUBY_PATCHLEVEL 213
+#define RUBY_PATCHLEVEL 214
 
 #define RUBY_RELEASE_YEAR 2020
 #define RUBY_RELEASE_MONTH 3
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]