Bug #9032

Time.round reverts the DST status of the time

Added by Mayank Sharma 6 months ago. Updated 2 months ago.

[ruby-core:57911]
Status:Third Party's Issue
Priority:Normal
Assignee:-
Category:-
Target version:-
ruby -v:ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin11.4.2] Backport:

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

History

#1 Updated by Nobuyoshi Nakada 6 months ago

  • Status changed from Open to Feedback
  • Priority changed from Urgent 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

#2 Updated by Nobuyoshi Nakada 6 months ago

  • Description updated (diff)

#3 Updated by Mayank Sharma 6 months ago

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

#4 Updated by Nobuyoshi Nakada 6 months ago

  • 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.

#5 Updated by Andrew White 3 months ago

This has been fixed in Rails master and will be released as part of Rail 4.1:
https://github.com/rails/rails/commit/63f8fabe4939ad59d597dfea441002ef5b16d2f4

#6 Updated by Usaku NAKAMURA 2 months ago

  • Backport deleted (1.9.3: UNKNOWN, 2.0.0: UNKNOWN)

Also available in: Atom PDF