ruby on rails - Should ActiveSupport::TimeWithZone (and Time.zone)'s methods respect DST changes? -
look @ code:
[4, 5, 6, 7].each |x| start_at = time.zone.parse("2014.10.2#{x} 08:00") puts "#{start_at.inspect} / #{start_at.seconds_since_midnight/60}" end
output:
fri, 24 oct 2014 08:00:00 cest +02:00 / 480.0 sat, 25 oct 2014 08:00:00 cest +02:00 / 480.0 sun, 26 oct 2014 08:00:00 cet +01:00 / 480.0 mon, 27 oct 2014 08:00:00 cet +01:00 / 480.0
we in germany, , on oct 26 dst reset 08:00 not 8*60 minutes since midnight 9*60.
imho, should respected seconds_since_midnight
method. missing or ruby bug?
using ruby 1.9.3, rails 3.0.20 on mac os x 10.9.5 (macports).
(yes, rails 3.0.20 old. legacy project. if it's fixed in rails 4, better.)
according the rails docs, it's implemented such:
# file activesupport/lib/active_support/core_ext/date_time/calculations.rb, line 14 def seconds_since_midnight sec + (min * 60) + (hour * 3600) end
thus, function not time zone aware. looks @ local time value. not consider offset of midnight might not same offset of value provided. nor consider midnight might not exist in local time zone (such brazil's spring-forward transition).
is bug? perhaps. 1 might method poorly named. either way, it's issue rails, not ruby.
ruby-on-rails ruby time timezone
No comments:
Post a Comment