(undef, undef, undef, $day, $month, $year, undef) = localtime(time() - 24*60*60); #### # Determine how many hours in a year cause problems when # subtracting/adding 24 hours to yield the previous/next # date. use strict; use Time::Local; my $start = timelocal(0, 0, 0, 1, 0, 2001); foreach my $hour ( 0 .. 24 * 365 ) { check($start + $hour * 60 * 60); } sub check { my $time = shift; # Method 1 - subtract 24 hours from the given time # to determine yesterday's date my $timeMinus24 = $time - 24 * 60 * 60; my $dm1 = join ' ', (localtime($timeMinus24))[3,4]; # Method 2 -- substract 2 hours from the start of the day # to determine yesterday's date my ($m,$d,$y) = (localtime($time))[3,4,5]; my $daystart = timelocal(0, 0, 0, $m, $d, $y); my $dm2 = join ' ', (localtime($daystart - 2 * 60 * 60))[3,4]; print "-24 wrong at ", scalar localtime($time), "\n" if $dm1 ne $dm2; # Method 1 -- add 24 hours to the given time # to determine tomorrow's date my $timePlus24 = $time + 24 * 60 * 60; $dm1 = join ' ', (localtime($timePlus24))[3,4]; # Method 2 -- add 26 hours to the start of the day # to determine tomorrow's date $dm2 = join ' ', (localtime($daystart + 26 * 60 * 60))[3,4]; print "+24 wrong at ", scalar localtime($time), "\n" if $dm1 ne $dm2; } #### +24 wrong at Sat Mar 31 23:00:00 2001 -24 wrong at Mon Apr 2 00:00:00 2001 +24 wrong at Sun Oct 28 00:00:00 2001 -24 wrong at Sun Oct 28 23:00:00 2001