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 columns do not support time zones

#839

The new support for time zones in Rails 2.1 does not apply time columns, but only to datetime and timestamp columns. I think this should be changed so that time columns undergo the same time zone conversions as datetime and timestamp columns.

The reasoning behind this is the same as for datetime and timestamp, even though time columns do not include date information: all times need to appear in the user's time zone. An example of where this would be important could be a news application that requires the submission of all prospective news items for the next day by a certain time, which is stored in the database. This time, even though it is date agnostic, still needs to appear in the user's own time zone to be understood correctly.

The attached patch adds time columns to the array of valid column types in the ActiveRecord::AttributeMethods::ClassMethods.create_time_zone_conversion_attribute? method.

Reported by Connor McKay · August 15th, 2008 @ 07:23 AM

State: wontfix
Milestone: 2.x
Assigned to: Geoff Buesing Geoff Buesing
Importance: none

Activity

  1. Ernie Miller
    Ernie Miller

    I'm not sure I agree on this one. When only time, and not date is being persisted in the database, part of the information required to make an intelligent decision about conversion is missing. Namely, the ability to discern whether the time is during daylight savings time or not.

    You could say the assumption should be made that the current date should be used for determining offset from UTC, but at that point, I'd contend you're not really dealing with a persisted attribute of the model at all, but instead a derived value from the persisted data. That makes a pretty strong case for you to do your own conversion if that's what you want.

    I'd have to give this one a -1.

    August 15th, 2008 @ 02:05 PM

  2. Geoff Buesing
    Geoff Buesing
    • Assigned user set to Geoff Buesing
    • Tag changed from 2.1, activerecord, patch, tiny to 2.1, activerecord, patch

    To do time zone conversions, you need to work with specific points in time, and in order to convert a db time identifier like "12:30:00" to a specific point in time, you'd need to make an assumption about a date and a zone.

    I'm in agreement with Ernie here, these assumptions sound like they belong in application code, not Rails.

    Also, I'm not sure your example gives a compelling use case for time-only columns -- couldn't "next day by a certain time" be turned into a specific UTC time point, and stored in the db in a datetime column?

    August 15th, 2008 @ 03:39 PM

  3. DHH
    DHH
    • State changed from new to wontfix

    Agree with Ernie and Geoff.

    August 16th, 2008 @ 05:34 AM

  4. Connor McKay
    Connor McKay

    Its a bit late to comment now, but I have to say that after I thought about it more, I think I do have to agree that this is an application assumption.

    August 16th, 2008 @ 06:02 AM