Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

What Time is It?

by hsmyers (Canon)
on Jan 05, 2004 at 00:52 UTC ( [id://318731]=perlquestion: print w/replies, xml ) Need Help??

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

This is no doubt something stupid, but on a W2K box running ActiveState 5.6.1, the following leaves me a little confused:
C:>perl -e "$t=localtime;print $t" Mon Jan 5 00:50:20 2004 C:>set tz TZ=MST C:>time The current time is: 17:50:30.95 Enter the new time:
I was able to fix it by setting TZ=UTC+7 but am vaguely under the opinion that I shouldn't have to. Where is my mistake?

--hsm

"Never try to teach a pig to sing...it wastes your time and it annoys the pig."

Replies are listed 'Best First'.
Re: What Time is It?
by ysth (Canon) on Jan 05, 2004 at 02:53 UTC
    Looks to me like ActiveState's perl relies on a posix-style TZ. That looks like this: stdoffset[dst[offset][,start[/time],end[/time]]] So at minimum you would have TZ=MST+7 (std and offset). (Note that the offsets are negative east of GMT and positive west of GMT.)

    It's interesting that many more posixy operating systems will have Olson-style TZ instead (where just TZ=MST will be looked up in a database that describes that timezone).

      So, who is responsible for the POSIX system call that doesn't understand 'MST' as being unique? And BTW, thanks for the clarification.

      --hsm

      "Never try to teach a pig to sing...it wastes your time and it annoys the pig."
        MST isn't unique; it could also mean Moscow Summer Time (according to the Olson files, this was used in 1917 only).

        I'm not sure what your question is. I'm guessing that ActiveState's perl is using C library functions provided by Microsoft that interpret TZ as specified by the POSIX standard. If you have TZ=MST, it seems to default to a 0 offset, saying you are in a timezone named MST with offset 0. (When you say TZ=UTC+7, you are saying you are in a timezone named UTC with offset 7 hours. :)

        Many unix-like systems have recognized the limitations of these POSIX-style timezone settings and switched to looking up the TZ environment variable in a database maintained by Arthur David Olson, thus allowing you to look up a timezone like MST (actually just a link to America/Phoenix; the Olson database names are usually in form (continent or ocean)/(major city) ). I wouldn't expect Microsoft to do so anytime soon.

Re: What Time is It?
by seattlejohn (Deacon) on Jan 05, 2004 at 02:29 UTC
    I believe your setting TZ=MST provides insufficient information for the localtime function to determine the correct time zone offset. My understanding is that the TZ setting must include the hours offset from UTC, and that the alphabetic designation you give it is merely for human convenience. So in your case, it would be TZ=MST7 or, perhaps, TZ=MST7MDT to account for the switch to daylight savings time.

    Update: sporty's right -- I determined this only for Windows. My Linux box did just fine without the numeric offset. (Thanks for the info on /usr/share/zoneinfo.)

            $perlmonks{seattlejohn} = 'John Clyman';

      It depends on the system. I'm gonna guess you are talking about windows only, but in case you aren't..
      Mon Jan 5 02:35:37 2004[calligraphy:~] sporty% setenv TZ CET [calligraphy:~] sporty% perl -e 'print scalar localtime' Mon Jan 5 03:35:46 2004[calligraphy:~] sporty% setenv TZ MST [calligraphy:~] sporty% perl -e 'print scalar localtime' Sun Jan 4 19:35:51 2004[calligraphy:~] sporty%
      It's because of what's in my /usr/share/zoneinfo/ dir .. so if I created a new one, I could use that, without the number.

      Play that funky music white boy..
Re: What Time is It?
by demerphq (Chancellor) on Jan 05, 2004 at 03:33 UTC

    I bet if you eliminate the TZ setting entirely the time would be correct. BTW, what version are you running? What I see there makes me think you have cygwin installed...


    ---
    demerphq

      First they ignore you, then they laugh at you, then they fight you, then you win.
      -- Gandhi


      Version of what? As I said, perl is ActiveState 5.6.1 build 635 and Windows is Windows 2000 Pro. I've played with cygwin, but have found it easier to use 'nix utilities built for Windows without the cygwin dll. see http://unxutils.sourceforge.net/

      --hsm

      "Never try to teach a pig to sing...it wastes your time and it annoys the pig."

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2024-04-20 05:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found