madeintandem / hstore_accessor

Adds typed hstore-backed field support to ActiveRecord models.
MIT License
242 stars 47 forks source link

deserialze time with zone to provide consistent accessor interface #51

Closed eprothro closed 9 years ago

eprothro commented 9 years ago

My understanding is that an Active Record date_time accessors are time zone aware, returning the object configured with the current time zone (e.g. not the system time). If I'm wrong there, just let me know.

Migrating to this gem with existing data (e.g replacing field foo_at that was an Active Record date_time type field with an hstore_accessor attribute with data_type: :time resulted in unexpected behavior, where the returned object is now initialized with the zone of the system clock.

Before migration to hstore

some_model.foo_at.iso8601
=> 2015-05-11T21:28:00Z

After migration to hstore

some_model.foo_at.iso8601
=> 2015-05-11T16:28:00-05:00

The change in this PR fixes this, such that the ActiveSupport timezone is respected.

If you think this is the right direction, I'd love your thoughts about the robustness of this change, and how to best integrate that with the test suite.

eprothro commented 9 years ago

I amended the commit in preference of the Active Support's more robust in_time_zone

eprothro commented 9 years ago

any thoughts on this?

crismali commented 9 years ago

@eprothro I've played around a bit with this and I was seeing some inconsistent behavior with this change. I'm going to poke around again and see what I can figure out.