Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10982 (closed defect: fixed)

Opened 3 months ago

Last modified 3 months ago

[PATCH] time_zone aware activerecord attributes using TimeWithZone

Reported by: technoweenie Assigned to: technoweenie
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: edge
Severity: normal Keywords:
Cc: gbuesing

Description

Geoff Buesing and I have been rapping about ActiveRecord time_zone-aware attributes.

Attachments

time_zone_ar_methods_draft-1.diff (5.6 kB) - added by technoweenie on 02/02/08 03:15:13.
Geoff's first patch
time_zone_attributes_2.diff (11.3 kB) - added by technoweenie on 02/04/08 07:15:22.
time_zone_attributes_3.diff (16.1 kB) - added by gbuesing on 02/06/08 03:00:34.

Change History

02/02/08 03:15:13 changed by technoweenie

  • attachment time_zone_ar_methods_draft-1.diff added.

Geoff's first patch

02/02/08 03:17:18 changed by technoweenie

  • owner changed from core to technoweenie.
  • status changed from new to assigned.

The main change I made was that setting times will convert the time to the current timezone, not just change it. I personally think this makes more sense. Also, multiparameter attributes will change the timezone to the current timezone if one is set, rather than creating them based on ActiveRecord::Base.default_timezone (local/utc).

(follow-up: ↓ 3 ) 02/02/08 03:26:46 changed by technoweenie

  • cc set to gbuesing.

02/04/08 07:15:22 changed by technoweenie

  • attachment time_zone_attributes_2.diff added.

02/06/08 03:00:34 changed by gbuesing

  • attachment time_zone_attributes_3.diff added.

(in reply to: ↑ 2 ) 02/06/08 04:27:31 changed by gbuesing

Replying to technoweenie:

Rick, great stuff! I think you're right about the setter method using #in_current_time_zone, and having multiparameter attributes change the zone beforehand -- I think that's more intuitive than what I originally had.

The patch I uploaded adds skip_time_zone_conversion_for_attributes awareness for multiparameter attributes, a Time.zone.now() constructor method, and some enhancements to tests.

All in all, I think this is looking pretty good.

02/06/08 06:43:05 changed by rick

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [8806]) Add Time Zone support to ActiveRecord, and config.time_zone property for specifying a default Time Zone. Closes #10982 [Geoff Buesing, rick]