This project is archived and is in readonly mode.
Time columns are not zone aware
-
Justin Mazzi
- Tag changed from 2.3.2, in_time_zone, time, zone to 2.3.2, active_record, in_time_zone, time, zone
-
Justin Mazzi
- Tag changed from 2.3.2, active_record, in_time_zone, time, zone to 2.3.2, active_record, bug, in_time_zone, time, zone
-
Ryan Bigg
I think this is more of a bug in your Rails application, not Rails.
Do you have
config.active_record.time_zoneset in config/environment.rb? If that is set and Time.zone is set to the user's timezone, then any time retrieved from the database should be relative to that user. Take this example:>> Topic.first.created_at => Sun, 19 Apr 2009 11:17:35 UTC +00:00 >> Time.zone = "Brisbane" => "Brisbane" >> Topic.first.created_at => Sun, 19 Apr 2009 21:17:35 EST +10:00 -
Justin Mazzi
Yes, this works fine with a datetime, but not with a time (unless you call it with in_time_zone)
create_table :schedules do |t| t.time :start_time end >> Schedule.first.start_time => Sat Jan 01 08:19:00 UTC 2000 >> Time.zone = "Brisbane" => "Brisbane" >> Schedule.first.start_time => Sat Jan 01 08:19:00 UTC 2000 -
Geoff Buesing
- State changed from new to wontfix
I assume you're talking about a sql :time (i.e., time-only) column, which AR returns as an instance of Time, with year, month and day set to Jan 1, 2000.
Rails doesn't do automatic time zone conversions on time-only columns, because there's not enough information to do so, given that the UTC offset changes depending upon the date. If we did do automatic time zone conversions, they would be for that time on Jan 1, 2000, which is probably not what you want.
So it's appropriate that you'll have to do a bit more fiddling to do the proper time zone conversions, since the rules will be app-specific.