Project

General

Profile

Misc #19121

Updated by andrykonchin (Andrew Konchin) about 2 years ago

I've noticed a strange difference between Ruby versions 2.7, 3.0 and 3.1. 

 The mentioned above formats are supported in Ruby 2.7 and Ruby 3.1 but aren't supported in Ruby 3.0. 

 So I am wondering whether supporting these formats is expected behaviour or a bug. In any case I would expect consistent behaviour in all the supported Ruby versions. 3.0: 

 Ruby 2.7.4 
 ```ruby 
 Time.new(2000, 1, 1, 0, 0, 0, "+05") # => 2000-01-01 00:00:00 +0500 
 Time.new(2000, 1, 1, 0, 0, 0, "+0530") # => 2000-01-01 00:00:00 +0530 
 Time.new(2000, 1, 1, 0, 0, 0, "+053037") # => 2000-01-01 00:00:00 +0530 
 ``` 

 Ruby 3.0.4 
 ```ruby 
 Time.new(2000, 1, 1, 0, 0, 0, "+05") 
 #(irb):1:in `initialize': "+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset (ArgumentError) 

 Time.new(2000, 1, 1, 0, 0, 0, "+0530") 
 #(irb):2:in `initialize': "+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset (ArgumentError) 

 Time.new(2000, 1, 1, 0, 0, 0, "+053037") 
 #(irb):3:in `initialize': "+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset (ArgumentError) 
 ``` 

 Ruby 3.1.2 

 ```ruby 
 Time.new(2000, 1, 1, 0, 0, 0, "+05") # => 2000-01-01 00:00:00 +0500 

 Time.new(2000, 1, 1, 0, 0, 0, "+0530") # => 2000-01-01 00:00:00 +0530 

 Time.new(2000, 1, 1, 0, 0, 0, "+053037") # => 2000-01-01 00:00:00 +053037 
 ```

Back