开发者

Is there timezone offset bug in ruby on rails?

开发者 https://www.devze.com 2022-12-18 03:23 出处:网络
I\'m in Korea. Rails version is 2.3.5 in my environment, config.time_zone = \'Seoul\' config.active_record.default_timezone = \'开发者_JAVA百科Seoul\'

I'm in Korea.

Rails version is 2.3.5

in my environment,

  config.time_zone = 'Seoul'
  config.active_record.default_timezone = '开发者_JAVA百科Seoul'

created_at and updated_at value is inserted with local time in database.

but, when I access model.created_at or model.updated_at, the value is understanding with UTC +9:00

So, I insert model to database and get the value, and check difference both values immediately, It is different bellow:

>> Time.now.to_datetime
=> Sun, 24 Jan 2010 21:28:03 +0900
# insert new Product. And check difference Time.now and Product.created_at immediately.
>> Product.last.created_at.to_datetime
=> Mon, 25 Jan 2010 06:12:51 +0900

Is it a bug of rails?


There is a known bug in Rails:

Rails Timezone Gotcha: ActiveRecord::Base.find does not convert Time objects to UTC

http://marklunds.com/articles/one/402

0

精彩评论

暂无评论...
验证码 换一张
取 消