Time.local and offsets

X

Xavier Noria

Does anyone know why Time.local gives these offsets here? (+0100 is correct)

fxn@rails:~/rails/activerecord$ rvm use 1.8.7

info: Using ruby 1.8.7 p302
fxn@rails:~/rails/activerecord$ ruby -e 'p Time.local(2010); p
Time.local(1940); p Time.local(1807)'
Fri Jan 01 00:00:00 +0100 2010
Mon Jan 01 00:00:00 +0000 1940
Thu Jan 01 00:00:00 -0014 1807

fxn@rails:~/rails/activerecord$ rvm use 1.9.2

info: Using ruby 1.9.2 p0
fxn@rails:~/rails/activerecord$ ruby -e 'p Time.local(2010); p
Time.local(1940); p Time.local(1807)'
2010-01-01 00:00:00 +0100
1940-01-01 00:00:00 +0000
1807-01-01 00:00:00 -0015

Local time zone is Europe/Madrid, the TZ environment variable is empty.
 
B

Brian Candler

Xavier said:
Does anyone know why Time.local gives these offsets here? (+0100 is
correct)

IIRC, daylight saving time was first introduced as a wartime
energy-saving measure. So prior to its introduction, Britain was on GMT
(+0000) even in the summer.

Wikipedia will almost certainly have the details.
 
B

Brian Candler

Sorry, I should engage brain before typing. Jan 1st is not in the
summer, and you are in Western Europe.

FWIW, I get similar results here for UK, under ruby 1.8.7.

irb(main):008:0> Time.local(1941)
=> Wed Jan 01 00:00:00 +0100 1941
irb(main):009:0> Time.local(1940)
=> Mon Jan 01 00:00:00 +0000 1940
 
X

Xavier Noria

Sorry, I should engage brain before typing. Jan 1st is not in the
summer, and you are in Western Europe.

FWIW, I get similar results here for UK, under ruby 1.8.7.

irb(main):008:0> Time.local(1941)
=3D> Wed Jan 01 00:00:00 +0100 1941
irb(main):009:0> Time.local(1940)
=3D> Mon Jan 01 00:00:00 +0000 1940

It's a bit weird (though I guess there's an explanation).

This is a trace from Brian Lopez

brianmario@Brians-iMac mysql2.git (master): ruby -e 'p
Time.local(2010); p Time.local(1940); p Time.local(1807)'
Fri Jan 01 00:00:00 -0800 2010
Mon Jan 01 00:00:00 -0800 1940
Thu Jan 01 00:00:00 -0800 1807

This one is from Jos=C3=A9 Valim

jose:~/Work[ree-1.8.7-2010.02][master]$ ruby -e 'p Time.local(2010); p
Time.local(1940); p Time.local(1807)'
Fri Jan 01 00:00:00 -0200 2010
Mon Jan 01 00:00:00 -0300 1940
Thu Jan 01 00:00:00 -0306 1807

Have you noticed also that for 1807 I get -0014 and -0015?
 
T

Tanaka Akira

2010/8/26 Xavier Noria said:
Does anyone know why Time.local gives these offsets here? (+0100 is correct)

% TZ=Europe/Madrid ruby -ve 'p Time.local(2010); p Time.local(1940); p
Time.local(1807)'
ruby 1.8.7 (2010-06-23 patchlevel 299) [x86_64-linux]
Fri Jan 01 00:00:00 +0100 2010
Mon Jan 01 00:00:00 +0000 1940
Thu Jan 01 00:00:00 -0014 1807
% TZ=Europe/Madrid ./ruby -ve 'p Time.local(2010); p Time.local(1940);
p Time.local(1807)'
ruby 1.9.3dev (2010-08-26 trunk 29102) [x86_64-linux]
2010-01-01 00:00:00 +0100
1940-01-01 00:00:00 +0000
1807-01-01 00:00:00 -0014
% TZ=Europe/Madrid ./ruby -ve 'p Time.local(2010); p Time.local(1940);
p Time.local(1807)'
ruby 1.9.2p0 (2010-08-18 revision 29034) [x86_64-linux]
2010-01-01 00:00:00 +0100
1940-01-01 00:00:00 +0000
1807-01-01 00:00:00 -0015
% zdump -v Europe/Madrid|head
Europe/Madrid -9223372036854775808 = NULL
Europe/Madrid -9223372036854689408 = NULL
Europe/Madrid Tue Jan 1 00:14:43 1901 UTC = Mon Dec 31 23:59:59 1900
LMT isdst=0 gmtoff=-884
Europe/Madrid Tue Jan 1 00:14:44 1901 UTC = Tue Jan 1 00:14:44 1901
WET isdst=0 gmtoff=0
Europe/Madrid Sat May 5 22:59:59 1917 UTC = Sat May 5 22:59:59 1917
WET isdst=0 gmtoff=0
Europe/Madrid Sat May 5 23:00:00 1917 UTC = Sun May 6 00:00:00 1917
WEST isdst=1 gmtoff=3600
Europe/Madrid Sat Oct 6 22:59:59 1917 UTC = Sat Oct 6 23:59:59 1917
WEST isdst=1 gmtoff=3600
Europe/Madrid Sat Oct 6 23:00:00 1917 UTC = Sat Oct 6 23:00:00 1917
WET isdst=0 gmtoff=0
Europe/Madrid Mon Apr 15 22:59:59 1918 UTC = Mon Apr 15 22:59:59 1918
WET isdst=0 gmtoff=0
Europe/Madrid Mon Apr 15 23:00:00 1918 UTC = Tue Apr 16 00:00:00 1918
WEST isdst=1 gmtoff=3600
% zdump -v Europe/Madrid|grep 2010
Europe/Madrid Sun Mar 28 00:59:59 2010 UTC = Sun Mar 28 01:59:59 2010
CET isdst=0 gmtoff=3600
Europe/Madrid Sun Mar 28 01:00:00 2010 UTC = Sun Mar 28 03:00:00 2010
CEST isdst=1 gmtoff=7200
Europe/Madrid Sun Oct 31 00:59:59 2010 UTC = Sun Oct 31 02:59:59 2010
CEST isdst=1 gmtoff=7200
Europe/Madrid Sun Oct 31 01:00:00 2010 UTC = Sun Oct 31 02:00:00 2010
CET isdst=0 gmtoff=3600

It seems Madrid used different timezone rules in these days:
LMT (local mean time) and WET/WEST.
Thu Jan 01 00:00:00 -0014 1807

14 is (884/60.0).floor.
1807-01-01 00:00:00 -0015

15 is (884/60.0).round.
 
B

Brian Candler

More info here:
http://www.nmm.ac.uk/explore/astron...ring-forward-100-years-of-british-summer-time

In particular see "Permanent summer, 1968–71", which is visible in Ruby:
=> Sat Jan 01 00:00:00 +0000 1972

So I'm pretty sure that the underlying tzinfo library is giving out true
information about what timezone was being used at the time.
This is a trace from Brian Lopez

brianmario@Brians-iMac mysql2.git (master): ruby -e 'p
Time.local(2010); p Time.local(1940); p Time.local(1807)'
Fri Jan 01 00:00:00 -0800 2010
Mon Jan 01 00:00:00 -0800 1940
Thu Jan 01 00:00:00 -0800 1807

Sure, well I guess that's West Coast USA. The USA will have had its own
rules for this sort of thing.
This one is from José Valim

jose:~/Work[ree-1.8.7-2010.02][master]$ ruby -e 'p Time.local(2010); p
Time.local(1940); p Time.local(1807)'
Fri Jan 01 00:00:00 -0200 2010
Mon Jan 01 00:00:00 -0300 1940
Thu Jan 01 00:00:00 -0306 1807

Argentina perhaps? Again, a different set of politics and rules.
Have you noticed also that for 1807 I get -0014 and -0015?

I get something similar:
=> 0

Sorry, I can't explain that one. I've heard of half-hour time zones and
even quarter-hour ones, but not a minute and a quarter :)

B.
 
B

Brian Candler

Brian said:
=> 0

Sorry, I can't explain that one. I've heard of half-hour time zones and
even quarter-hour ones, but not a minute and a quarter :)

I think I have it:
http://en.wikipedia.org/wiki/Time_zone

It wasn't until 1847 that Greenwich Mean Time was widely used across the
UK. Before then, everyone used "solar time", which means that clocks at
different points of the country (east to west) hit noon at different
times. The difference would be 60 minutes for every 15 degrees of
longitude.

So if you were standing at St Paul's Cathedral, say, noon would be
slightly later compared to noon in Greenwich, which is a bit to the
East.

In your case: Madrid has a longitude of 3 degrees 42 mins West. So the
offset of Madrid solar time from GMT is:

irb(main):001:0> -(3.0 + 42.0/60.0) / 15.0 * 60.0
=> -14.8

and that's exactly what you saw. tzdata rules :)
 
X

Xavier Noria

I think I have it:
http://en.wikipedia.org/wiki/Time_zone

It wasn't until 1847 that Greenwich Mean Time was widely used across the
UK. Before then, everyone used "solar time", which means that clocks at
different points of the country (east to west) hit noon at different
times. The difference would be 60 minutes for every 15 degrees of
longitude.

So if you were standing at St Paul's Cathedral, say, noon would be
slightly later compared to noon in Greenwich, which is a bit to the
East.

In your case: Madrid has a longitude of 3 degrees 42 mins West. So the
offset of Madrid solar time from GMT is:

irb(main):001:0> -(3.0 + 42.0/60.0) / 15.0 * 60.0
=> -14.8

and that's exactly what you saw. tzdata rules :)

Awesome!!!

Thank you very much :)
 
R

Rick DeNatale

Sorry, I should engage brain before typing. Jan 1st is not in the
summer, and you are in Western Europe.

Also, although daylight saving time WAS initiated as a war time
measure, the war was WW I, it was the Germans and their allies who
started it but Britain and other countries soon followed suit.

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Github: http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top