Hi all,
I have been struggling with time/date in perl for several hours now and for some reason i get a quirky error. I have an array called "date" 44 elements in length and "time" 44 elements in length. I created this code to convert UTC to localtime (Alaska). But whenever I run this code, my $date[0] (which is 09/12/2007) gets replaced with (09/14/2007). I did all kinds of debugging on this and can't seem to find what the matter is. One thing i noticed is that the value of $date[0] changes from 09/12/2007 to 09/13/2007 to 09/14/2007 !! I want it to stay at 09/12/2007... argh!!!
Does anyone know of an easier way to convert the time? The code to backtrack to the previous day, I got from another perl message board(start date and end date function) and I tweaked it ($md-8) until I saw that it went back a day.
dave
foreach $x (0...$#date)
{
if ($isdst)
{
print "we are in daylight saving time, so subtract 9";
}
else
{
#print " we are not in daylight saving time, so subtract 8 </br>";
if ($time[$x]<8)
{
$time[$x]=($time[$x]+24-8);
$time[$x]= join(':',$time[$x], "00");
# have to use the previous days, so convert the
# current date to EPOCH then subtract a day
# then change back to regular date 00/00/0000
$date[$x]= get_prevday($date[$x]);
sub get_prevday { $date[$x] = shift || return(0);
my ($m,$md,$y) = $date[$x] =~ m|(\d+)/(\d+)/(\d+)|;
my $epochtime = timelocal_nocheck(0, 0, 0, $md-8, $m-1, $y);
return strftime("%m/%d/20%y",0,0,0,(localtime($epochtime+604800))[3,4,5]);}
}
else
{
if ($time[$x]<18)
{
$time[$x]="0".($time[$x]-8).":00";
}
else
{
$time[$x]=($time[$x]-8).":00";
}
}
}