Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Time - TimeWithZone fails (sometimes)

#3410
 38 :> x = Time.zone.now
    => Thu, 22 Oct 2009 06:23:32 UTC 00:00
 39 :> y = Time.now
    => Wed Oct 21 23:23:35 -0700 2009
 40 :> x.class
    => ActiveSupport::TimeWithZone
 41 :> y.class
    => Time
 42 :> x - y
    => -2.95153093338013
 43 :> y - x
    => 2.951531
 44 :> x = Comment.last.updated_at
  Comment Load (0.000331) (1 Row)   SELECT * FROM `comments` WHERE (comments.deleted_at IS NULL OR comments.deleted_at > '2009-10-21 23:25:01') ORDER BY comments.id DESC LIMIT 1
    => Wed, 21 Oct 2009 23:07:29 UTC 00:00
 45 :> x.class
    => ActiveSupport::TimeWithZone
 46 :> x - y
    => -26166.2522480488
 47 :> y - x
    => Wed Dec 31 23:16:06 -0800 1969

in environment:

  config.time_zone = 'UTC'
  config.active_record.default_timezone = 'Pacific Time (US & Canada)'

This is in Rails 2.3.4.

WTF?

Reported by Sai Emrys · October 22nd, 2009 @ 07:28 AM

State: invalid
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Sai Emrys
    Sai Emrys

    Removing the config.active_record.default_timezone fixes this. (I added it to try to help with #1339.)

    Nevertheless, it's a weird bug.

    October 22nd, 2009 @ 07:35 AM

  2. Geoff Buesing
    Geoff Buesing
    • State changed from new to invalid

    The only valid settings for config.active_record.default_timezone are :utc and :local.

    I've seen others make this same error -- they assume default_timezone can be set to any of the ActiveSupport timezone names. Might make sense to raise an exception if someone tries to do that, to help with the confusion.

    October 27th, 2009 @ 02:16 AM