ruby / date

A subclass of Object includes Comparable module for handling dates.
Other
73 stars 38 forks source link

DateTime._strptime("...", "%z") behaves differently from Ruby 3.2 #94

Closed dmikurube closed 9 months ago

dmikurube commented 1 year ago

They may be ultimate cases, so may not be to fix. But reporting just in case.

require 'date'
puts DateTime._strptime("UTC+99:13", "%z")
puts DateTime._strptime("UTC+99:13:14", "%z")
puts DateTime._strptime("UTC+912:42", "%z")
puts DateTime._strptime("UTC+912:42:49", "%z")
puts DateTime._strptime("UTC-99:13", "%z")
puts DateTime._strptime("UTC-99:13:14", "%z")
puts DateTime._strptime("UTC-912:42", "%z")
puts DateTime._strptime("UTC-912:42:49", "%z")

Until Ruby 3.1 (tested with 2.7.7, 3.0.5, 3.1.3)

{:zone=>"UTC+99:13", :offset=>357180}
{:zone=>"UTC+99:13:14", :offset=>357194}
{:zone=>"UTC+912:42", :offset=>3285720}
{:zone=>"UTC+912:42:49", :offset=>3285769}
{:zone=>"UTC-99:13", :offset=>-357180}
{:zone=>"UTC-99:13:14", :offset=>-357194}
{:zone=>"UTC-912:42", :offset=>-3285720}
{:zone=>"UTC-912:42:49", :offset=>-3285769}

From Ruby 3.2 (tested with Ruby 3.2.1)

{:zone=>"UTC+99:13", :offset=>nil}
{:zone=>"UTC+99:13:14", :offset=>nil}
{:zone=>"UTC+912:42", :offset=>nil}
{:zone=>"UTC+912:42:49", :offset=>nil}
{:zone=>"UTC-99:13", :offset=>nil}
{:zone=>"UTC-99:13:14", :offset=>nil}
{:zone=>"UTC-912:42", :offset=>nil}
{:zone=>"UTC-912:42:49", :offset=>nil}
nobu commented 9 months ago

+99 is out of range of hour.