oracle / truffleruby

A high performance implementation of the Ruby programming language, built on GraalVM.
https://www.graalvm.org/ruby/
Other
3.02k stars 185 forks source link

DateTime#to_time and Time#to_time don't preserve timezones #1515

Closed deepj closed 2 years ago

deepj commented 5 years ago

In old Ruby times this was an issue with the standard Date library. But it was fixed in Ruby 2.4

MRI (2.5.3)

datetime = DateTime.strptime('2018-12-07 11:00:29 -06:00', '%Y-%m-%d %H:%M:%S %Z')
=> #<DateTime: 2018-12-07T11:00:29-06:00 ((2458460j,61229s,0n),-21600s,2299161j)>
datetime.to_time
=> 2018-12-07 11:00:29 -0600

time = Time.new(2018, 12, 7, 11, 00, 29, '-06:00')
=> 2018-12-07 11:00:29 -0600
time.to_time
=> 2018-12-07 11:00:29 -0600

TruffleRuby (1.0.0-rc10)

datetime = DateTime.strptime('2018-12-07 11:00:29 -06:00', '%Y-%m-%d %H:%M:%S %Z')
=> #<DateTime: 2018-12-07T11:00:29-06:00 (212410962029/86400,-1/4,2299161)>
datetime.to_time
=> 2018-12-07 18:00:29 +0100

time = Time.new(2018, 12, 7, 11, 00, 29, '-06:00')
=> 2018-12-07 11:00:29 -0600
time.to_time
=> 2018-12-07 18:00:29 +0100

The results of TruffleRuby are wrong here.

chrisseaton commented 5 years ago

I think there's tagged specs for the former but not the latter.

andrykonchin commented 2 years ago

I suppose we can close this issue.

I cannot reproduce the issue on the master branch:

require 'date'
# => true
datetime = DateTime.strptime('2018-12-07 11:00:29 -06:00', '%Y-%m-%d %H:%M:%S %Z')
# => #<DateTime: 2018-12-07T11:00:29-06:00 ((2458460j,61229s,0n),-21600s,2299161j)>
datetime.to_time
# => 2018-12-07 11:00:29 -0600

time = Time.new(2018, 12, 7, 11, 00, 29, '-06:00')
# => 2018-12-07 11:00:29 -0600
time.to_time
# => 2018-12-07 11:00:29 -0600