I was looking at
http://search.cpan.org/~drolsky/DateTime-1.03/lib/DateTime.pm
where it says:

The delta_md and delta_days methods truncate the duration so that any
> fractional portion of a day is ignored. Both of these methods operate on
> the date portion of a datetime only, *and so effectively ignore the time
> zone*.


What I'm wondering is if the dates are not floating should they be set to,
say, UTC, before comparing -- apples to apples, so to speak.

This is what triggered this:

    my $dt1 = DateTime->new(
        year => 2013, month => 9, day => 15,
        hour => 20,
        time_zone => 'America/Los_Angeles'
    );
    my $dt2 = $dt1->clone;
    my $dt3 = $dt1->clone;
    my $dt4 = $dt1->clone;

    $dt2->set_time_zone( 'Australia/Perth' );

    print $dt1->strftime( '%F %T %z' ) . "\n";
    print $dt2->strftime( '%F %T %z' ) . "\n";

    my $days = $dt2->delta_days( $dt1 )->delta_days;
    print "$days days apart\n";

    $dt3->set_time_zone( 'UTC' );
    $dt4->set_time_zone( 'UTC' );

    $days = $dt4->delta_days( $dt3 )->delta_days;
    print "$days days apart in UTC\n";

2013-09-15 20:00:00 -0700
2013-09-16 11:00:00 +0800
1 days apart
0 days apart in UTC

I'm frankly not sure what "delta days" should show there.   Same point in
time but also the dates are different.

Should DateTime set them to the same timezone before comparing?   Or is
this left to the user to decided this?



-- 
Bill Moseley
[email protected]

Reply via email to