notes

Dienstag, Juli 24, 2007

Rails Bug? Timezone in persistant models

Programming Rails I have realized that there can be a small bug.
When developing a web application there is an option in the "config/environment.rb" file that specifies the default timezone of Active Record, "config.active_record.default_timezone". I set this option to ":utc", so now I thought that I can expect that, when I set an attribute of an object being a model that accepts "Time" as type, then Rails should convert dates of any timezone to the default timezone of Active Record. But it doesnt happen. Only when I read attributes from the database they are handled as dates of default timezone:

# config/environment.rb
...
config.active_record.default_timezone = :utc
...

# db/migrate/002_create_user_model.rb
...
create_table :users do |t|
t.column :name, :string
t.column :created, :datetime
...

# test/unit/user_test.rb
...
def test_saving_time_format
now = Time.now # localtime = 9:32
bob = users(:bob)
bob.created = now
# bob.created == 9:32 (local) == 7:32 (UTC) == now.utc
# -> success
assert now.utc-2 <= bob.created && bob.created <= now.utc+2
bob.save; bob.reload
# bob.created == 9:32 (UTC) != 7:32 (UTC) -> fails
assert now.utc-2 <= bob.created && bob.created <= now.utc+2
# convert the time manually to UTC
bob.created = now.utc; bob.save; bob.reload
# bob.created == 9:32 (UTC) == now.utc -> successful
assert now.utc-2 <= bob.created && bob.created <= now.utc+2
...

it fails because rails stored (or better dumped) bob.created localtime to db:
db_record = 9:32 without any convertion and when reloading from db, it handles it as utc time
9:32 (UTC) = 11:32 (localtime).
Instead of dumping the localtime to the db, it would be better when rails converted the time object to UTC and dumped the UTC time to the db!

Maybe I should write a bug report if it is not a feature, but when its a feature its a stupid one!

Regards
Rudi

Labels: , , , , ,

Donnerstag, Juli 05, 2007

Firefox Alpha, Beta + RC History, Resources

-- Firefox 1.0 Milestones --
2004-09-14 :: 0.10/1.0 Preview Release
2004-10-28 :: 1.0 RC1, RC2 (no resources found)
2004-11-09 :: 1.0 final -

-- Deer Park Milestones --
2005-05-31 :: 1.1 Alpha 1
2005-07-13 :: 1.1 Alpha 2 (DevNews)
2005-09-08 :: 1.4/1.5 Beta 1 (DevNews)
2005-10-06 :: 1.4.1/1.5 Beta 2
2005-11-01 :: 1.5 RC1 (DevNews)
2005-11-11 :: 1.5 RC2 (DevNews)
2005-11-17 :: 1.5 RC3 (DevNews)
2005-11-29 :: 1.5 final

--Bon Echo Milestones --
2006-03-22 :: 2.0 Alpha 1 (DevNews)
2006-05-12 :: 2.0 Alpha 2 (DevNews)
2006-05-26 :: 2.0 Alpha 3 (DevNews)
2006-07-12 :: 2.0 Beta 1 (DevNews)
2006-08-31 :: 2.0 Beta 2 (DevNews)
2006-09-26 :: 2.0 RC1
2006-10-06 :: 2.0 RC2
2006-10-17 :: 2.0 RC3
2006-10-24 :: 2.0 final (DevNews)

-- Gran Paradiso Milestones --
2006-12-08 :: 3.0 Alpha 1 (DevNews)
2007-02-07 :: 3.0 Alpha 2 (DevNews)
2007-03-23 :: 3.0 Alpha 3 (DevNews)
2007-04-27 :: 3.0 Alpha 4 (DevNews)
2007-06-06 :: 3.0 Alpha 5 (DevNews)
2007-07-02 :: 3.0 Alpha 6 (DevNews)



These pictures are licensed under the GNU Free Documentation License. For the second picture I used material from the German Wikipedia article "Vorlage:Firefox-Zeittafel", being part of Mozilla Firefox subarticle Versionsgeschichte Mozilla Firefox.
sourcecode

Labels: , , , ,