Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Time.local and offsets

Reply
Thread Tools

Time.local and offsets

 
 
Xavier Noria
Guest
Posts: n/a
 
      08-25-2010
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.

 
Reply With Quote
 
 
 
 
Brian Candler
Guest
Posts: n/a
 
      08-26-2010
Xavier Noria wrote:
> 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.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Brian Candler
Guest
Posts: n/a
 
      08-26-2010
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
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Xavier Noria
Guest
Posts: n/a
 
      08-26-2010
On Thu, Aug 26, 2010 at 3:55 PM, Brian Candler <(E-Mail Removed)> wrote:

> 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?

 
Reply With Quote
 
Tanaka Akira
Guest
Posts: n/a
 
      08-26-2010
2010/8/26 Xavier Noria <(E-Mail Removed)>:
> 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.
--
Tanaka Akira

 
Reply With Quote
 
Brian Candler
Guest
Posts: n/a
 
      08-26-2010
More info here:
http://www.nmm.ac.uk/explore/astrono...sh-summer-time

In particular see "Permanent summer, 1968–71", which is visible in Ruby:

>> require 'time'

=> true
>> Time.parse("1 jan 1968")

=> Mon Jan 01 00:00:00 +0000 1968
>> Time.parse("1 jan 1969")

=> Wed Jan 01 00:00:00 +0100 1969
>> Time.parse("1 jan 1970")

=> Thu Jan 01 00:00:00 +0100 1970
>> Time.parse("1 jan 1971")

=> Fri Jan 01 00:00:00 +0100 1971
>> Time.parse("1 jan 1972")

=> 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:

>> Time.parse("1 jan 1847")

=> Fri Jan 01 00:00:00 -0001 1847
>> Time.parse("1 jan 1848")

=> Sat Jan 01 00:00:00 +0000 1848
>> Time.local("1847").utc_offset

=> -75
>> Time.local("1848").utc_offset

=> 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.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Brian Candler
Guest
Posts: n/a
 
      08-27-2010
Brian Candler wrote:
>>> Time.parse("1 jan 1847")

> => Fri Jan 01 00:00:00 -0001 1847
>>> Time.parse("1 jan 1848")

> => Sat Jan 01 00:00:00 +0000 1848
>>> Time.local("1847").utc_offset

> => -75
>>> Time.local("1848").utc_offset

> => 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
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Xavier Noria
Guest
Posts: n/a
 
      08-27-2010
On Fri, Aug 27, 2010 at 12:11 PM, Brian Candler <(E-Mail Removed)> wrote:

> Brian Candler wrote:
>>>> Time.parse("1 jan 1847")

>> => Fri Jan 01 00:00:00 -0001 1847
>>>> Time.parse("1 jan 1848")

>> => Sat Jan 01 00:00:00 +0000 1848
>>>> Time.local("1847").utc_offset

>> => -75
>>>> Time.local("1848").utc_offset

>> => 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


Awesome!!!

Thank you very much

 
Reply With Quote
 
Rick DeNatale
Guest
Posts: n/a
 
      08-31-2010
On Thu, Aug 26, 2010 at 9:55 AM, Brian Candler <(E-Mail Removed)> wrote:
> 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/pers...-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Byte Offsets of Tokens, Ngrams and Sentences? Muhammad Adeel Python 2 08-06-2010 10:06 AM
Dynamic DIV and P creation offsets the P Andrew Poulos Javascript 3 12-01-2005 02:37 PM
How To Write A Program To Convert Structure Member Offsets? Randy Yates C Programming 7 05-14-2005 11:04 PM
Looking for a more elegant way to do memory offsets mikegw C Programming 5 05-24-2004 11:39 AM
OpenSP API, Unicode character byte offsets Phillip Farber XML 0 08-20-2003 09:13 PM



Advertisments