Project

General

Profile

Actions

Bug #21301

open

Invalid Dates Accepted When Using "UTC" in Time.new

Added by mame (Yusuke Endoh) 4 days ago. Updated 2 days ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:121801]

Description

2025-04-31 does not exist, but, when creating a time object with the "UTC" zone, the value is accepted without error:

Time.new(2025, 4, 31, 0, 0, 0, "UTC") #=> expected: 2025-05-01 00:00:00 UTC
                                      #=> actual:   2025-04-31 00:00:00 UTC

In contrast, using the "+00:00" time zone works as expected and rolls the date over to 2025-05-01:

Time.new(2025, 4, 31, 0, 0, 0, "+00:00") # => 2025-05-01 00:00:00 +0000

Note that 2025-04-30T24:00:00Z is correctly rolled over to 2025-05-01T00:00:00Z.
And 2025-04-31T24:00:00Z is rolled over to 2025-04-01!

Time.new(2025, 4, 30, 24, 0, 0, "UTC") #=> 2025-05-01 00:00:00 UTC # OK
Time.new(2025, 4, 31, 24, 0, 0, "UTC") #=> 2025-04-01 00:00:00 UTC # What?
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0