Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

localtime gives unexpected result

by Ghepardo (Novice)
on Feb 07, 2023 at 20:34 UTC ( #11150221=perlquestion: print w/replies, xml ) Need Help??

Ghepardo has asked for the wisdom of the Perl Monks concerning the following question:

I am on a machine with "GB" (i.e. British) localisation, and I see the following:

$ perl -e '$t=0; print scalar localtime $t, "\n"; print scalar gmtime +$t' Thu Jan 1 01:00:00 1970 Thu Jan 1 00:00:00 1970

So localtime and gmtime return different values for time "0".

Now I'd expect localtime and gmtime to return the same thing in Britain outside of a daylight savings time period (which 1 January is).

I wondered whether this was because I didn't have a TZ variable set in my environment, but setting this to 'Europe/London' made no difference.

We don't get this discrepancy if we use the current time:

$ perl -e '$t=time; print scalar localtime $t, "\n"; print scalar gmti +me $t' Tue Feb 7 20:24:24 2023 Tue Feb 7 20:24:24 2023

This feels like a stupid question, I think I must be missing something obvious...

Replies are listed 'Best First'.
Re: localtime gives unexpected result
by choroba (Cardinal) on Feb 07, 2023 at 20:55 UTC
    Welcome to the wonderful human concept of measurable time.

    Daylight Saving Time Changes 1970 in London:

    > DST is observed all year during 1970 in London

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      Thanks @choroba, I would never have guessed that, especially since I was alive at the time (although fairly young). Use Perl, learn History (and a lot more besides).
Re: localtime gives unexpected result
by Anonymous Monk on Feb 08, 2023 at 04:02 UTC

    It because of this in the timezone database:

    # Zone NAME STDOFF RULES FORMAT [UNTIL] Zone Europe/London -0:01:15 - LMT 1847 Dec 1 0:00 GB-Eire %s 1968 Oct 27 1:00 - BST 1971 Oct 31 2:00u 0:00 GB-Eire %s 1996 0:00 EU GMT/BST

    So GB (Europe/London) was 01:00 offset from 1968 Oct 27 through to 1971 Oct 31 2AM.

    Apparently this was 'a three-year experiment was conducted with British Standard Time, keeping the clocks fixed throughout the year on GMT+1.'

      Thanks @Anonymous Monk.
Re: localtime gives unexpected result
by Discipulus (Canon) on Feb 07, 2023 at 21:20 UTC
    hello Ghepardo and welcome to the monastery and to the wonderful world of perl!

    beside Welcome to the wonderful human concept of measurable time also consider we are in XIII century and Perl rules the known world

    sorry I could not resist :)

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      Thanks @Discipulus.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11150221]
Approved by marto
Front-paged by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2023-04-02 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?