i've got a simple play-around script that attempts to
calculate and display a time til target value (*) -- it first
calculates the target by creating a timezone aware starting
point, and adding a 28 day duration (created with hours => 672
so Daylight Saving Time won't skew the result, or more
accurately *will* skew it honestly)

another duration object is created by subtracting a timezone
aware "now" from my timezone aware target, at which point i
attempt to use a DateTime::Format::Duration to display the
result, which for reasons i cannot imagine is coming out as

now til target is 24 days, 00 hours, 461 minutes

did i create the duration formatter improperly?

sc

(*) i include the whole thing, as i am new to this package and
may be making a silly mistake elsewhere -- also i apologize as
i know there are going to be unintended line breaks in it by
the time it gets to the list

#!/usr/bin/perl
#  and what about DateTime::Format::Duration
use DateTime::Format::Duration;
use DateTime::Format::Strptime;
$fs = "%Y-%b-%d %H:%M";
$strp = new DateTime::Format::Strptime(
    pattern   => "$fs",
    locale    => 'en_US',
    time_zone => 'America/Chicago');
$dt = $strp->parse_datetime("2011-oct-09 04:03");
$nw = DateTime->now(time_zone => 'America/Chicago');
printf "now is %s\n", $nw->strftime("$fs");
$hl = $nw - $dt;
printf "it's been %d days, %d hours, %d minutes since %s\n", $hl-
>days, $hl->hours, $hl->minutes, $dt->strftime("$fs");
$dfd = DateTime::Format::Duration->new(
    pattern => '%e days, %H hours, %M minutes');
$fw = DateTime::Duration->new(hours => 672);
$targ = $dt + $fw;
printf "target date is %s\n", $targ->strftime("$fs");
$t = $targ - $nw;
printf "now til target is %s\n", $dfd->format_duration($t);

Reply via email to