NoamB/sorcery — Issue #96: DateTime values stored with Mongoid converted to UTC twice when Time.zone set
Author: allspiritseve
Created: 2011-10-19 04:45:14+00:00
State: open

I'm trying to get dates to appear consistently across my app. From what I've read, the way to do this is to set Time.zone to the timezone I want. However, when I do this, I get dates back from Mongoid that are UTC + 4 hours instead of UTC.

Basically sorcery converts the date to UTC, calls to_s, and then hands it off to the model. Mongoid retrieves the string, assumes it's in the local timezone, and converts it to UTC again.

# /lib/sorcery/controller/submodules/activity_logging.rb line 72
current_user.send(:"#{current_user.sorcery_config.last_activity_at_attribute_name}=", Time.now.utc.to_s(:db))

I'm not sure what the solution is-- should sorcery be using Time.now.in_time_zone.to_s instead of utc? That seems preferable to always having to convert dates to UTC before saving with Mongoid. I'm certainly open to other suggestions though.