This project is archived and is in readonly mode.
Cannot make zone.parse create given time (DST)
Reported by Cezary Baginski | April 10th, 2009 @ 12:42 AM | in 2.x
When leaving DST time, time is shifted back an hour, so we get two ambiguous times. I cannot seem to find a way to control which one is returned by ActiveSupport::TimeZone.parse:
(e.g. in activesupport/test/time_zone_test.rb)
def test_parse_on_dst_boundary
zone = ActiveSupport::TimeZone['Moscow']
zone.stubs(:now).returns zone.local(2009,4,5)
assert_equal Time.utc(2008,10,25,21), zone.parse('2008-10-26 1:00')
assert_equal Time.utc(2008,10,25,22), zone.parse('2008-10-26 2:00')
#This fails - I don't know how to make zone.parse give the equiv. UTC time
assert_equal Time.utc(2008,10,25,23), zone.parse('2008-10-26 2:00 MSK +0300').utc
assert_equal Time.utc(2008,10,26,0), zone.parse('2008-10-26 3:00')
end
NOTE: the additonal 'MSK +0300' of course isn't parsed properly - this is just for the sake of the example.
I have no idea how to make zone.parse '2:00' into the time I want - 23:00 UTC instead of 22:00 UTC.
I wouldn't be surprised if this is resolved as "wont fix". I would love to debug this and create a patch, but I have no idea if and how this can be nicely solved. How can I allow entering a time (e.g. '2:00') in a timezone without it being ambiguous?
The best I can think of is extending zone.parse to handle:
"2:00 D" (DST version, 22:00 UTC) -> 2:00 MSD
and
"2:00 K" (non-DST version, 23:00 UTC) -> 2:00 MSK
Any comments or suggestions?
Comments and changes to this ticket
-
Geoff Buesing April 11th, 2009 @ 03:19 PM
- State changed from new to wontfix
If you include the UTC offset and leave out the MSK/MDK from the string, it works:
>> zone = ActiveSupport::TimeZone['Moscow'] => #<ActiveSupport::TimeZone:0x183ec98 @tzinfo=nil, @name="Moscow", @utc_offset=10800> >> zone.parse('2008-10-26 2:00 +0300') => Sun, 26 Oct 2008 02:00:00 MSK +03:00 >> zone.parse('2008-10-26 2:00 +0400') => Sun, 26 Oct 2008 02:00:00 MSD +04:00
Here's why:
>> Date._parse('2008-10-26 2:00 +0300') => {:mday=>26, :mon=>10, :zone=>"+0300", :offset=>10800, :year=>2008, :hour=>2, :min=>0} >> Date._parse('2008-10-26 2:00 MSK +0300') => {:mday=>26, :mon=>10, :zone=>"MSK", :year=>2008, :hour=>2, :min=>0}
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>