Project

General

Profile

Actions

Bug #18274

closed

Time.new initializes the date incorrectly after a leap day with a positive UTC offset

Added by philross (Phil Ross) over 2 years ago. Updated over 2 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 3.1.0dev (2021-10-27T17:00:25Z master 30942c19c0) [x86_64-linux]
[ruby-core:105832]

Description

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:

Time.new(2000, 3, 1, 0, 0, 0, 3600)
#=> 2000-02-29 00:00:00 +0100

Ruby 3.0.2 returns the expected result:

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:

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:

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)
Actions

Also available in: Atom PDF

Like0
Like0Like0