Skip to content

Instantly share code, notes, and snippets.

@retro
Created December 14, 2009 21:19
Show Gist options
  • Save retro/256438 to your computer and use it in GitHub Desktop.
Save retro/256438 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'mongo_mapper'
require 'active_support'
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
:default => "%m/%d/%Y"
)
class Time
def self.to_mongo(value)
if value.nil? || value == ''
nil
else
time = MongoMapper.time_class.parse(value.strftime('%a %b %d %H:%M:%S %Z %Y'))
time && time.utc
end
end
end
MongoMapper.database = 'testing'
class Foo
include MongoMapper::Document
key :_id, ObjectId
key :time, Time
end
Foo.collection.remove
Foo.create(:time => Time.now)
puts Foo.first.time.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment