#868 confirmed
Bright 4

Support for UTC/GMT timestamps

Reported by Bright 4 | May 27th, 2009 @ 04:36 AM

For a project we are currently working on, it is important that the date/times stored in the database are in UTC/GMT (timezone offset of +00:00).

Activerecord has a configuration option to enable this:

ActiveRecord::Base.default_timezone = :utc

DataMapper unfortunately has not (as far as we can tell). For now, we have changed the TIMESTAMP_PROPERTIES constant in dm-timestamps.rb to the following:

datetime = DateTime.now.new_offset(0)
date = Date.parse( datetime.to_s )
  :updated_at => [ DateTime, lambda { |r, p| datetime                                    } ],
  :updated_on => [ Date,     lambda { |r, p| date                                        } ],
  :created_at => [ DateTime, lambda { |r, p| r.created_at || (datetime if r.new_record?) } ],
  :created_on => [ Date,     lambda { |r, p| r.created_on || (date     if r.new_record?) } ],

This fixes the issue for now. However, it would be nice to make this option configurable. Does anyone share our opinion on this matter?

If so, we could create a patch. The one thing we are not sure about is how to set such a configuration option. Any ideas?

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) May 28th, 2009 @ 07:12 PM

    • Assigned user set to “Dirkjan Bussink”

    This change would probably require that DataObjects (DO) read/store the DateTime and Time objects in the configured timezone. While I think it would be possible to do some of the conversion at the DM layer, it'll be really bad for performance compared to just reading/writing them in the correct timezone in the first place.

    Dirkjan (the DO maintainer) and I have spoken about this, but I don't know what his plans are for adding this feature to DO. I will assign this ticket to him to get his input on this.

  • Martin Gamsjaeger (snusnu)

    Martin Gamsjaeger (snusnu) June 23rd, 2009 @ 10:50 AM

    I already did some work on this quite some time ago. It's currently based on dm-core/more/master, but it should be easy to use with 0.10 too. Maybe this helps?


  • Dirkjan Bussink

    Dirkjan Bussink July 23rd, 2009 @ 11:55 AM

    • State changed from “unconfirmed” to “confirmed”

    The idea is to provide an option on a connection so you're able to specify the default timezone, something like the following:


    This still needs to be worked in though.

  • Piotr Solnica (solnic)

    Piotr Solnica (solnic) May 17th, 2011 @ 02:34 AM

    • Tag changed from dm-timestamp, gmt, timestamps, utc to dm-timestamp, gmt, utc
    • Milestone order changed from “0” to “0”

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

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

Referenced by