Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Finding a remote time

by Moron (Curate)
on Jul 17, 2006 at 13:59 UTC ( [id://561743]=note: print w/replies, xml ) Need Help??


in reply to Finding a remote time

Thanks for all your replies. In the end I went for fletch's suggestion to localise $ENV{ TZ }, because I needed to compute the difference between local time and the remote time and could not permit the code to switch to remote time throughout. Another factor in choosing the most convenient solution was that it was easier to use core modules only rather than require module installation all the way down the production line (dev -> test -> QA -> uat -> prod.) for so small a piece of code.

Update: OK to be honest I did not explicitly use 'local' because the tzset had to be repeated anyway. What I actually did was more like:

sub RemoteTime { my $realtz = $ENV{ TZ }; my ( @return, $return ); my $wantarray = wantarray; $ENV{ TZ } = shift; tzset; if ( $wantarray ) { @return = localtime(); } else $return = localtime(); } $ENV{ TZ } = $realtz; tzset; return $wantarray ? @return : $return; }

-M

Free your mind

Replies are listed 'Best First'.
Re^2: Finding a remote time
by nothingmuch (Priest) on Jul 17, 2006 at 20:04 UTC
    If you need to compute stuff you really ought to use DateTime - it takes care of all the nasty details of time math for you.
    -nuffin
    zz zZ Z Z #!perl
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-25 13:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found