Actions
Bug #3737
closedDateTime#to_time doesn't preserve zone
Description
=begin
Why does DateTime#to_time doesn't preserve the time zone but convert the timestamp to local time zone?
d = DateTime.new(2010, 8, 23, 20, 14, 10, '+08:00')
puts d # => 2010-08-23T20:14:10+08:00
t = d.to_time
puts t # => 2010-08-23 14:14:10 +0200
I would expect that t is in time zone +08:00 not +02:00. If I want the time in local time zone I can call t.localtime, but I have no chance to preserve the zone information. If this behavior is intentional the the DateTime#to_time method is useless for most of my use cases. My actual workaround is following code:
t = Time.new(d.year, d.month, d.day, d.hour, d.minute, d.second, d.zone)
puts t #= => 2010-08-23 20:14:10 +0800
Best regards
Jan
=end
Actions
Like0
Like0Like0Like0