This project is archived and is in readonly mode.

#1575 ✓stale
ronin-24025 (at lighthouseapp)

ActiveRecord DateTime, Time Mappings

Reported by ronin-24025 (at lighthouseapp) | December 15th, 2008 @ 12:14 PM | in 3.x

It appears to not be possible to call to_xml on an ActiveRecord object with various Time, Datetime columns and have it return the following:


Even if :from and :until were declared as time columns. Because of how ActiveRecord mixes and matches DateTime and Time class mappings (over-optimization), ActiveRecord would output the following instead:


In other words, there appears to be no way to differentiate between a time object: "14:00:00", a date object: "2008-12-15" and a datetime object: "2008-12-15 14:00:00".

At the database level, however, these differentiations are in fact honored, times are stored as times, dates as dates, and datetimes as datetimes.

So the pragmatic position is that the data treatment and the presentation treatment are different, and that the data is being misrepresented.

The world might prove to be a better place if :time were mapped to Time, :datetime to DateTime, and :date to Date. Plus dates before 1970 wouldn't give "out of range" exceptions.

The performance implications of this are of course to be considered. But so should the complexity implications. Even if the performance considerations do justify the more-complicated mapping, this should at least be done properly.

Comments and changes to this ticket

  • Frederick Cheung

    Frederick Cheung December 20th, 2008 @ 01:24 PM

    Ruby does not have a pure time of day class so :time maps to the Time class. Date columns already map to Date. As far as DateTime goes, it's a lot slower to work with than Time (since Time is just an integer offset from an epoch). These days Rails does fall back from Time to DateTime if a row contains a date not representable by Time.

    It does seem a bit broken to me that pure times of day are represented as datetimes with an arbitrary year/month/day prefix. It shouldn't be hard to change the serialization code, although I would be concerned about the backwards compatibility implications of that (it does look like someone explicitly chose to handle time columns in the same way as datetime columns though)

  • Pratik

    Pratik March 13th, 2009 @ 11:12 AM

    • Assigned user set to “Frederick Cheung”
  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:42 PM

    • State changed from “new” to “open”
    • Importance changed from “” to “”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:42 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>