Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Daylight Savings Time twist

by BigLug (Chaplain)
on Feb 06, 2003 at 22:57 UTC ( [id://233310]=note: print w/replies, xml ) Need Help??


in reply to Daylight Savings Time twist

Take a look at DateTime its only a developer release at the moment, but its moving ahead fast. I imagine the people at the DateTime project would like to hear how it goes for you (email datetime@perl.org).

DateTime aims to be the difinitive perl module for working with dates and times. The DateTime::Timezone module(s) are based on the OlsenDB - the central source of information on timezones and daylight savings so they should be right. There is talk on the list about how to keep these files up to date - which will be sorted out by the time you'd need to update them :)

Try using DateTime something like this:

my $realtimehere = DateTime->now; my $realtimethere = DateTime->new(time_zone => 'America/Los_Angeles'); my $difference = $realtimehere - $realtimethere;
The PODumentation will explain how to use the $difference duration. Also note that you might have to feed a time into the new() method, but I'm sure someone else will chime in and tell you.

The code is completely untested because I can't install DateTime on my mac here at the moment. Of course, read the documentation and then test it :)

Replies are listed 'Best First'.
Re: Re: Daylight Savings Time twist
by BigLug (Chaplain) on Feb 07, 2003 at 12:36 UTC
    OK, we've had a talk about it and this is the best solution at the moment using the current state of the module:
    use DateTime; %OurLogs = get_the_time_from_the_log_file_as_a_hash(); $here = DateTime->new( time_zone => 'America/Indiana', map { $_ => $OurLogs{$_} } qw( year month day hour minute second ) ); $there = DateTime->new( time_zone => 'America/Los_Angeles', map { $_ => $here->$_() } qw( year month day hour minute second ) );
    Then you can play around with however you want to format the $here and $there objects. Check the PODumentation for details.
      Once again, I have posted the wrong solution. The above solution will give you a time difference if you subtract here from there. However to get the equivlent there time for a particular here time, do this:
      use DateTime; %OurLogs = get_the_time_from_the_log_file_as_a_hash(); $here = DateTime->new( time_zone => 'America/Indiana', map { $_ => $OurLogs{$_} } qw( year month day hour minute second ) ); $there = $here->clone; $there->set_time_zone('America/Los_Angeles');
      This will give you the equivlent time in LA for the time in Indiana. Please note that you should set the timezones to appropriate values :)

      Many appologies for all the confusion. I woke up at about 3am in a cold sweat realising that I'd posted the wrong solution :)

        Ok, all, I REALLY appreciate the comments back. Learned quite a bit in the exercise. In this case, they guy who's taking over for me is a real PL/SQL (Oracle) nut; I read this thread, and liked it best.

        I urged him to make use of it, and he tried it out, kinda liked it, but opted to use an Oracle function to handle the time shift and write a simple Perl piece that used ranges to give a proper time range. The range is based on whether or not we are between the first Sunday in April and the last Sunday in October or not. It, admittedly, was simple, but isn't the most efficient solution (of which I think BigLug's probably is).

Log In?
Username:
Password:

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

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

    No recent polls found