Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Determining Daylight Savings Time

by Juerd (Abbot)
on May 29, 2002 at 21:30 UTC ( [id://170225]=note: print w/replies, xml ) Need Help??


in reply to Determining Daylight Savings Time

5. Reset $ENV{TZ} to its original value so it doesn't muck up any other date calculations elsewhere in the code

You could of course localize %ENV:

{ local $\ = "\n"; print scalar localtime; { local %ENV; $ENV{TZ} = 'GMT'; print scalar localtime; } print scalar localtime; }
yields:
Wed May 29 23:29:08 2002 Wed May 29 21:29:08 2002 Wed May 29 23:29:08 2002

Update/PS: -- for frontpaging your own node. Don't do that.

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.

Replies are listed 'Best First'.
(MeowChow) Re2: Determining Daylight Savings Time
by MeowChow (Vicar) on May 30, 2002 at 19:49 UTC
    You don't have to localize all of %ENV:
    local $ENV{TZ} = 'GMT';
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print

      You don't have to localize all of %ENV: local $ENV{TZ} = 'GMT';

      Please test before posting. Localizing a single %ENV value will not work as expected.

      { local $\ = "\n"; print scalar localtime; { local $ENV{TZ} = 'GMT'; print scalar localtime; } print scalar localtime, ", which is wrong."; }
      yields:
      Thu May 30 23:19:56 2002 Thu May 30 21:19:56 2002 Thu May 30 21:19:56 2002, which is wrong.
      Update: environment: Debian GNU/Linux sid x86, Perl 5.6.1

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.
      

        It works on both my OpenBSD and Linux perl 5.6.1 and 5.00503. What platform are you testing on?
          
        { local $\ = "\n"; print scalar localtime; { local $ENV{TZ} = 'GMT'; print scalar localtime; } print scalar localtime, ", which is right."; } Thu May 30 16:36:26 2002 Thu May 30 21:36:26 2002 Thu May 30 16:36:26 2002, which is right.
           MeowChow                                   
                       s aamecha.s a..a\u$&owag.print

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-03-28 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found