Calculation methods should act the same as attributes on the model and be timezone aware.
Currently values returned from calculations on models return dates/times in UTC. For example:
Topic.maximum(:written_on) => 2014-01-13 17:56:44 UTC
Selecting that column will return the value converted to the current timezone if time_zone_aware_attributes is true and it's not been excluded with skip_time_zone_conversion_for_attributes:
Topic.pluck(:written_on).first => Mon, 13 Jan 2014 17:56:44 GMT +00:00
topic = Topic.first
topic.written_on => Mon, 13 Jan 2014 17:56:44 GMT +00:00
This pull request makes it so calculated values also honor the time_zone_aware_attributes flag and the skip_time_zone_conversion_for_attributes array:
Topic.maximum(:written_on) => Mon, 13 Jan 2014 17:56:44 GMT +00:00
Let me know if it needs any cleaning up or changes. Thanks!
Calculation methods on datetime fields should return values in the cu…
Hey, thanks for the pull request. Sorry it got missed for so long. This was randomly brought onto my radar from a problem a coworker was having. This has been fixed in 4.2 and 5.0 (and in fact this bug would be impossible to introduce with the new type system internals).