Calculation methods on models (maximum and minimum) for datetime fields should return values in the current timezone. #13711

wants to merge 1 commit into


None yet

2 participants

gspiers commented Jan 14, 2014

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!

sgrif commented Aug 21, 2015

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).

@sgrif sgrif closed this Aug 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment