FAQ
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
moseley@hank.org

Search Discussions

  • Zefram at Sep 16, 2013 at 12:50 pm

    Bill Moseley wrote:
    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.
    That's a sane comparison to make, but, as you show, a different one from
    what delta_days does. Compatibility requires that we do not change the
    behaviour of delta_days. It's up to the user to decide which kind of
    comparison to do.

    -zefram

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdatetime @
categoriesperl
postedSep 16, '13 at 3:21a
activeSep 16, '13 at 12:50p
posts2
users2
websitemetacpan.org...

2 users in discussion

Zefram: 1 post Bill Moseley: 1 post

People

Translate

site design / logo © 2019 Grokbase