Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #4551 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

TimeZone reports wrong offset during daylight savings time

Reported by: drbrain@segment7.net Assigned to: jamis@37signals.com
Priority: normal Milestone:
Component: ActiveSupport Version: 1.1.0
Severity: normal Keywords:
Cc:

Description

Steps to reproduce:

1) Set your computer to a time and time zone where daylight-savings time are in effect. (Pacific Time, April 3, 2006 is a good time zone and time.) 2) Use TimeZone to get UTC offset

Expected results:

UTC offset is accurate for the time zone and time. Adjusted times are accurate for daylight-savings time.

Actual results:

UTC offset is only returns the non-daylight-savings time. Adjusted times are one hour off during daylight-savings time.

Here it is on the console:

>> Time.now.gmtoff
=> -25200
>> TimeZone.all.select { |t| t.name =~ /pacific/i }.map { |t| t.utc_offset }
=> [-28800]
>> TimeZone.all.select { |t| t.name =~ /pacific/i }.map { |t| t.name }
=> ["Pacific Time (US & Canada)"]
>> pt = TimeZone[_.first]
=> #<TimeZone:0x24eaa54 @utc_offset=-28800, @name="Pacific Time (US & Canada)">
>> Time.now
=> Mon Apr 03 01:09:18 PDT 2006
>> pt.adjust Time.now.gmtime
=> Mon Apr 03 00:09:24 UTC 2006

Change History

04/03/06 18:44:29 changed by david

  • owner changed from David to jamis@37signals.com.

04/03/06 18:47:19 changed by minam

  • status changed from new to closed.
  • resolution set to wontfix.

The bundled TimeZone library is pretty weaksauce--it does not handle daylight savings at all. If you need DST support, please consider evaluating the tzinfo_timezone plugin, which relies on the tzinfo library (gem install tzinfo). Note that the tzinfo_timezone plugin currently relies on the version of tzinfo in svn, which is two orders of magnitude faster than the one currently released. This mess will all get cleaned up soon, hopefully as soon as Phil releases the next version of tzinfo.

04/03/06 20:00:05 changed by drbrain

Since TimeZone will be broken for most of the US for half the year why not switch to tzinfo_timezone?

04/03/06 21:00:49 changed by minam

We'll definitely consider that. The problem is that the tzinfo library is quite large, and we'd like to require as few dependencies as possible for Rails. (Bundling it isn't an option, either, also because of its size.) Not every app requires time-zone and DST support, though, so for now, making it a plugin is probably the best solution. Down the road, we may remove the built-in TimeZone class, because it is (as you said) broken for half the year.

The whole time-zone and DST thing is one area where Ruby really has a few warts. Sorry for the confusion and poorly documented issues with the TimeZone class. We'll improve on that.

04/03/06 21:11:27 changed by minam

I should note that Phil Ross *just* released tzinfo 0.2.0, which should work fine with the tzinfo_timezone plugin.

07/31/06 19:55:59 changed by Stephen Touset

  • status changed from closed to reopened.
  • severity set to normal.
  • cc deleted.
  • type set to defect.
  • component set to ActiveSupport.
  • summary changed from TimeZone+reports+wrong+offset+during+daylight+savings+time to TimeZone reports wrong offset during daylight savings time.
  • priority set to normal.
  • keywords deleted.
  • resolution deleted.

Sorry to reopen, but there's a spam comment right above mine. Figured it wouldn't get noticed unless the bug was reopened.

Any way to delete it?

08/05/06 02:47:11 changed by bitsweat

  • status changed from reopened to closed.
  • resolution set to fixed.

11/02/06 01:52:13 changed by bitsweat

(In [5388]) next_week respects DST changes. Closes #5617, closes #2353, closes #2509, references #4551.