views:

71

answers:

1

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
+1  A: 

Try setting the use_utc mongoid config parameter to true.

It tells Mongoid that you want to return times in UTC: http://github.com/durran/mongoid/blob/master/lib/mongoid/config.rb#L22

Jim Garvin