[EMAIL PROTECTED] wrote:
>How do I compute the number of hours in a day in a specific time zone?
Try this:
use DateTime;
for(my $today = DateTime->new(year=>2007, time_zone=>$ARGV[0]); $today->year ==
2007; ) {
(my $tomorrow = $today->clone)->add(days=>1);
print $today, " ", ($tomorrow->epoch - $today->epoch)/3600, "\n";
$today = $tomorrow;
}
It ought to be possible to do the interval calculation using
DateTime::Duration instead of ->epoch, but the behaviour of DT::D is
unreasonably confusing and I couldn't get it to work. (Strangely, I got
a version that worked fine for America/New_York, where all the days are
integer numbers of hours, but lost the fractional hour of 2007-12-09 in
America/Caracas, which was 24.5 hours long.)
Beware that the above code assumes that
midnight exists every day. We recently had a thread
<http://www.nntp.perl.org/group/perl.datetime/2008/10/msg7086.html> about
midnight not existing in some timezones, specifically America/Sao_Paulo.
-zefram