Unfortunately, it's still broken. It doesn't account for timezones whose difference from UTC is not a multiple of 60 minutes. For example, you code doesn't work in Newfoundland.
use Time::Local qw( timelocal );
$ENV{TZ} = 'America/St_Johns';
for my $time (
timelocal(0, 25, 16, 26, 4-1, 2007), # 16th hour of 2007-04-26
timelocal(0, 35, 16, 26, 4-1, 2007), # 16th hour of 2007-04-26
) {
my $hour = int( $time / 3600 ) * 3600;
print(scalar(localtime($time)), "\n");
# Should print the same value for both, but doesn't.
print("$hour\n");
}
Thu Apr 26 16:25:00 2007
1177610400
Thu Apr 26 16:35:00 2007
1177614000
|