Bug #9032
closed
Time.round reverts the DST status of the time
Added by mayanks (Mayank Sharma) about 11 years ago.
Updated almost 11 years ago.
Status:
Third Party's Issue
ruby -v:
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin11.4.2]
[ruby-core:57911]
Description
=begin
If the time is in non-DST and round method is applied, then the resulting time goes back to DST time. This happens only during the 1 hour when time goes back. Following example should explain the situation better.
2.0.0-p0 :057 > d
=> Sun, 27 Oct 2013 02:30:00 CET +01:00
2.0.0-p0 :058 > d.isdst
=> false
2.0.0-p0 :059 > d.round(3)
=> Sun, 27 Oct 2013 02:30:00 CEST +02:00
2.0.0-p0 :060 > d.round(3).isdst
=> true
I have set the priority Urgent as the DST is going to elapse in 10 days from now.
=end
- Status changed from Open to Feedback
- Priority changed from 6 to Normal
=begin
I can't reproduce it.
What's your timezone?
$ TZ=Europe/Paris ~/ruby/2.0.0-p0/bin/ruby -v -rtime -e 't1 = Time.new(2013, 10, 27, 2, 30, 0); t2 = t1.round(3); [t1, t2].each {|t|p [t, t.dst?, t.zone]}'
ruby 2.0.0p0 (2013-02-24 revision 39474) [universal.x86_64-darwin11.0]
[2013-10-27 02:30:00 +0100, false, "CET"]
[2013-10-27 02:30:00 +0100, false, "CET"]
And it seems an irb session, but why it prints time objects in old format?
=end
- Description updated (diff)
I am sorry, I should have mentioned that I am using rails console. It could be rails ActiveSupport::TimeZone issue as well, but the round method is in ruby Time, so not entirely sure about that. In the following snippet, I am (a) setting the Time.zone, (b) creating a time by parsing the string in that zone. This time is in CEST, (c) I then add 1 hour to get CET. (d) on this CET time, when I call round, I get back CEST.
2.0.0-p0 :019 > Time.zone = "Europe/Paris"
=> "Europe/Paris"
2.0.0-p0 :020 > t1 = Time.zone.parse("2013-10-27 02:30:00")
=> Sun, 27 Oct 2013 02:30:00 CEST +02:00
2.0.0-p0 :021 > t2 = t1 + 1.hour
=> Sun, 27 Oct 2013 02:30:00 CET +01:00
2.0.0-p0 :022 > t2.round
=> Sun, 27 Oct 2013 02:30:00 CEST +02:00
2.0.0-p0 :023 >
Does this make sense? My Rails version is 3.2.11
- Status changed from Feedback to Third Party's Issue
It's not Time class object, but ActiveSupport::TimeWithZone.
It seems handling local time and time zone separately, so it is impossible to resolve the timezone from local time only, because 02:30:00 will come twice at 2013-10-27, CEST and CET.
This is a miss-design of ActiveSupport::TimeWithZone.
- Backport deleted (
1.9.3: UNKNOWN, 2.0.0: UNKNOWN)
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0