diff options
author | Perl 5 Porters <perl5-porters@africa.nicoh.com> | 1996-07-03 23:36:46 +0000 |
---|---|---|
committer | Charles Bailey <bailey@genetics.upenn.edu> | 1996-07-03 23:36:46 +0000 |
commit | 16bb4654df736f4325b04851b91f4d13fb185fb2 (patch) | |
tree | c7769be94caf420bbe92c13e5aa7f97a94f4a902 /lib/Time | |
parent | b1a524cb07dc967b81ca1991cece82cb77a776ac (diff) | |
download | perl-16bb4654df736f4325b04851b91f4d13fb185fb2.tar.gz |
Fix bugs in initialization for some timezones
Diffstat (limited to 'lib/Time')
-rw-r--r-- | lib/Time/Local.pm | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/lib/Time/Local.pm b/lib/Time/Local.pm index 451c7fa20c..40e8da796b 100644 --- a/lib/Time/Local.pm +++ b/lib/Time/Local.pm @@ -39,28 +39,44 @@ after the 1st of January, 2038 on most machines. =cut -@epoch = localtime(0); -$tzmin = $epoch[2] * 60 + $epoch[1]; # minutes east of GMT -if ($tzmin > 0) { - $tzmin = 24 * 60 - $tzmin; # minutes west of GMT - $tzmin -= 24 * 60 if $epoch[5] == 70; # account for the date line -} +BEGIN { + @epoch = localtime(0); + + $SEC = 1; + $MIN = 60 * $SEC; + $HR = 60 * $MIN; + $DAY = 24 * $HR; + $YearFix = ((gmtime(946684800))[5] == 100) ? 100 : 0; + + my $t = time; + my @lt = localtime($t); + my @gt = gmtime($t); -$SEC = 1; -$MIN = 60 * $SEC; -$HR = 60 * $MIN; -$DAYS = 24 * $HR; -$YearFix = ((gmtime(946684800))[5] == 100) ? 100 : 0; + $tzsec = ($gt[1] - $lt[1]) * $MIN + ($gt[2] - $lt[2]) * $HR; + + my($lday,$gday) = ($lt[7],$gt[7]); + if($lt[5] > $gt[5]) { + $tzsec -= $DAY; + } + elsif($gt[5] > $lt[5]) { + $tzsec += $DAY; + } + else { + $tzsec += ($gt[7] - $lt[7]) * $DAY; + } + + $tzsec += $HR if($lt[8]); +} sub timegm { $ym = pack(C2, @_[5,4]); $cheat = $cheat{$ym} || &cheat; return -1 if $cheat<0; - $cheat + $_[0] * $SEC + $_[1] * $MIN + $_[2] * $HR + ($_[3]-1) * $DAYS; + $cheat + $_[0] * $SEC + $_[1] * $MIN + $_[2] * $HR + ($_[3]-1) * $DAY; } sub timelocal { - $time = &timegm + $tzmin*$MIN; + $time = &timegm + $tzsec; return -1 if $cheat<0; @test = localtime($time); $time -= $HR if $test[2] != $_[2]; @@ -69,6 +85,8 @@ sub timelocal { sub cheat { $year = $_[5]; + $year -= 1900 + if $year > 1900; $month = $_[4]; croak "Month out of range 0..11 in timelocal.pl" if $month > 11 || $month < 0; @@ -85,7 +103,7 @@ sub cheat { $year += $YearFix if $year < $epoch[5]; $lastguess = ""; while ($diff = $year - $g[5]) { - $guess += $diff * (363 * $DAYS); + $guess += $diff * (363 * $DAY); @g = gmtime($guess); if (($thisguess = "@g") eq $lastguess){ return -1; #date beyond this machine's integer limit @@ -93,7 +111,7 @@ sub cheat { $lastguess = $thisguess; } while ($diff = $month - $g[4]) { - $guess += $diff * (27 * $DAYS); + $guess += $diff * (27 * $DAY); @g = gmtime($guess); if (($thisguess = "@g") eq $lastguess){ return -1; #date beyond this machine's integer limit @@ -105,7 +123,7 @@ sub cheat { return -1; #date beyond this machine's integer limit } $g[3]--; - $guess -= $g[0] * $SEC + $g[1] * $MIN + $g[2] * $HR + $g[3] * $DAYS; + $guess -= $g[0] * $SEC + $g[1] * $MIN + $g[2] * $HR + $g[3] * $DAY; $cheat{$ym} = $guess; } |