Posterous theme by Cory Watilo

DataMapper and Rails' TimeWithZone

Experimenting with Datamapper, I found it lacking the time zone support of Rails and ActiveRecord.  Here’s how far I got…

class DataMapper::Types::TimeWithZone < DataMapper::Type
  primitive Time
  def self.load(value, property)
    Time.utc(*value.to_a).in_time_zone
  end
   
  def self.typecast(value, property)
    value.utc
  end
end

Unfortunately, dm-timestamps doesn’t auto-populate these types…