Update time zone offset information #4514

Merged
merged 1 commit into from Jan 24, 2012

Conversation

Projects
None yet
2 participants
Contributor

brainopia commented Jan 18, 2012

To demonstrate an issue run following:

$ export TZ='Europe/Moscow'
$ rake test TEST=activesupport/test/core_ext/time_ext_test.rb

You'll get following:

  1) Failure:
test_local_time(TimeExtCalculationsTest) [/Users/brainopia/code/sources/rails/activesupport/test/core_ext/time_ext_test.rb:650]:
--- expected
+++ actual
@@ -1 +1 @@
-2039-02-21 17:44:30 +0400
+Mon, 21 Feb 2039 17:44:30 +0300


  2) Failure:
test_time_with_datetime_fallback(TimeExtCalculationsTest) [/Users/brainopia/code/sources/rails/activesupport/test/core_ext/time_ext_test.rb:621]:
--- expected
+++ actual
@@ -1 +1 @@
-2039-02-21 17:44:30 +0400
+Mon, 21 Feb 2039 17:44:30 +0300

The reason is that rails uses time zone offets for 2007 year. And since then there were changes, for example Russia abolished daylight savings.

> ENV['TZ'] = 'Europe/Moscow'
"Europe/Moscow" 
> Time.new(2007).utc_offset
10800 
> Time.new(2012).utc_offset
14400
Owner

tenderlove commented Jan 18, 2012

Just out of curiosity, what is this method used for? Can it be replaced with something from Ruby core?

The comment says:

DateTimes aren't aware of DST rules,

and I find that really hard to believe.

Contributor

brainopia commented Jan 20, 2012

@tenderlove thanks for question and sorry for delay in response.

I did my research and found out following. Only Time class is aware of DST rules, the one way in which DateTime is aware of DTS rules is when calling DateTime.now. And that's only because it calls Time.now.utc_offset underneath.

All other possible ways of constructing a new DateTime object will use an offset given explicitly as fraction of a day or zero if none was given. Therefore it does not differentiate between locations with DST rules and we need to have an easy access to local offset as fraction of a day.

That's why there is method DateTime.local_offset.
It's used in DateTime.civil_from_format which in turn is used when Time.local_time is called for time period outside of 1902/1970..2038.

Is there anything else I can do to help you with this pull-request?

tenderlove added a commit that referenced this pull request Jan 24, 2012

@tenderlove tenderlove merged commit 8478b0c into rails:master Jan 24, 2012

tenderlove added a commit that referenced this pull request Jan 24, 2012

tenderlove added a commit that referenced this pull request Jan 24, 2012

tenderlove added a commit that referenced this pull request Jan 24, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment