From: "philross (Phil Ross)" Date: 2021-10-27T19:05:33+00:00 Subject: [ruby-core:105832] [Ruby master Bug#18274] Time.new initializes the date incorrectly after a leap day with a positive UTC offset Issue #18274 has been reported by philross (Phil Ross). ---------------------------------------- Bug #18274: Time.new initializes the date incorrectly after a leap day with a positive UTC offset https://bugs.ruby-lang.org/issues/18274 * Author: philross (Phil Ross) * Status: Open * Priority: Normal * ruby -v: ruby 3.1.0dev (2021-10-27T17:00:25Z master 30942c19c0) [x86_64-linux] * Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN ---------------------------------------- With 3.1.0dev revision 30942c19c0, `Time.new` can initialize the date incorrectly on the day following a leap day. The year 2000 is a leap year. 2000-03-01 00:00:00 +01:00 is considered to be 2000-02-29 00:00:00 +0100: ``` ruby Time.new(2000, 3, 1, 0, 0, 0, 3600) #=> 2000-02-29 00:00:00 +0100 ``` Ruby 3.0.2 returns the expected result: ``` ruby Time.new(2000, 3, 1, 0, 0, 0, 3600) #=> 2000-03-01 00:00:00 +0100 ``` UTC times and negative UTC offsets return the expected results with 3.1.0dev: ``` ruby Time.utc(2000, 3, 1, 0, 0, 0) #=> 2000-03-01 00:00:00 UTC Time.new(2000, 3, 1, 0, 0, 0, -3600) #=> 2000-03-01 00:00:00 -0100 ``` Any time of day at or later than the offset also returns the expected results with 3.1.0dev: ``` ruby Time.new(2020, 3, 1, 0, 59, 59, 3600) #=> 2020-02-29 00:59:59 +0100 (incorrect) Time.new(2020, 3, 1, 1, 0, 0, 3600) #=> 2020-03-01 01:00:00 +0100 (expected) Time.new(2020, 3, 1, 1, 59, 59, 7200) #=> 2020-02-29 01:59:59 +0200 (incorrect) Time.new(2020, 3, 1, 2, 0, 0, 7200) #=> 2020-03-01 02:00:00 +0200 (expected) ``` -- https://bugs.ruby-lang.org/ Unsubscribe: