How to store UTC time values in Mongo with Mongoid?
Posted
by Jerry Cheung
on Stack Overflow
See other posts from Stack Overflow
or by Jerry Cheung
Published on 2010-05-18T00:45:18Z
Indexed on
2010/05/18
0:50 UTC
Read the original article
Hit count: 582
The behavior I'm observing with the Mongoid adapter is that it'll save 'time' fields with the current system timezone into the database. Note that it's the system time and not Rail's environment's Time.zone. If I change the system timezone, then subsequent saves will pick up the current system timezone.
# system currently at UTC -7
@record.time_attribute = Time.now.utc
@record.save
# in mongo, the value is "time_attribute" : "Mon May 17 2010 12:00:00 GMT-0700 (QYZST)"
@record.reload.time_attribute.utc? # false
© Stack Overflow or respective owner