[San-Diego-pm] Converting Time from UTC
Chris Grau
chris at chrisgrau.com
Fri Feb 8 10:53:54 PST 2008
How annoying. My original reply ended up being rejected by qmail.
Better luck this time. And the error message is oh so useful.
host 16.mx.develooper.com[216.52.237.216] said: 452 Message denied
temporarily (in reply to end of DATA command)
On Fri, Feb 01, 2008 at 08:39:04PM -0500, Mark Schoonover wrote:
> Yeah, that's what I was thinking on the way home tonight... I was
> thinking I could just check the date/time to see if it's equal to, or
> past March 9th, 0200 and go that route, but I think it maybe safer to
> use DateTime module to do what I need.
Ouch. I would never recommend handling Daylight Saving Time manually.
Too much room for error. I whipped up something that may do what you
want (or may not... I only skimmed this thread). Notice the second two
dates fall on the DST switch.
-----cut----------cut----------cut----------cut----------cut-----
#!/usr/bin/perl -w
use strict;
use Date::Parse;
my @dates = qw(01/01/2007 03/11/2007 11/04/2007);
my @times = qw(00:00 08:25 08:09);
for my $i ( 0 .. $#dates ) {
my $date = join ' ', $dates[$i], $times[$i];
my $time = str2time( $date, 'GMT' );
print "Got date: ", ( scalar gmtime $time ), " GMT\n";
for my $tz ( qw(US/Pacific US/Mountain US/Central US/Eastern) ) {
local $ENV{'TZ'} = $tz;
print " $tz => ", ( scalar localtime $time ), "\n";
}
}
-----cut----------cut----------cut----------cut----------cut-----
Got date: Mon Jan 1 00:00:00 2007 GMT
US/Pacific => Sun Dec 31 16:00:00 2006
US/Mountain => Sun Dec 31 17:00:00 2006
US/Central => Sun Dec 31 18:00:00 2006
US/Eastern => Sun Dec 31 19:00:00 2006
Got date: Sun Mar 11 08:25:00 2007 GMT
US/Pacific => Sun Mar 11 00:25:00 2007
US/Mountain => Sun Mar 11 01:25:00 2007
US/Central => Sun Mar 11 03:25:00 2007
US/Eastern => Sun Mar 11 04:25:00 2007
Got date: Sun Nov 4 08:09:00 2007 GMT
US/Pacific => Sun Nov 4 01:09:00 2007
US/Mountain => Sun Nov 4 01:09:00 2007
US/Central => Sun Nov 4 02:09:00 2007
US/Eastern => Sun Nov 4 03:09:00 2007
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/san-diego-pm/attachments/20080208/e3888598/attachment.bin
More information about the San-Diego-pm
mailing list