in reply to Re: Split date ranges/chunks based on Unix epoch time?
in thread Split date ranges/chunks based on Unix epoch time?

Take care, that should then be
my %date_count; foreach my $time ( @times ) { $date_count{ int( $time / 3600 ) * 3600 }++; }
The division operator '/' doesn't do any implicit integer truncation - yes, I know C does... :)

Replies are listed 'Best First'.
Re^3: Split date ranges/chunks based on Unix epoch time?
by jwkrahn (Abbot) on Apr 26, 2007 at 14:13 UTC
    Yes, thank you, I forgot about that.    :-)

      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