develooper Front page | perl.datetime | Postings from February 2003

subtract_datetime() problem

Thread Next
From:
Eric Cholet
Date:
February 9, 2003 05:44
Subject:
subtract_datetime() problem
Message ID:
8F8141F2-3C34-11D7-824E-000393DB4634@logilune.com
Using DateTime's subtract_datetime() to compute
2003/02/09 13:21:28 - 1994/12/16 00:01:00, I get a negative result.
->delta_days = -2978

I traced it to the value of utc_rd_secs:

2003/02/09 13:21:28: utc_rd_secs = 44488
1994/12/16 00:01:00: utc_rd_secs = 82860

subtract_datetime calls
         DateTime::Duration->new
             ( days    => $self->{utc_rd_days} - $dt->{utc_rd_days},
               seconds => $self->{utc_rd_secs} - $dt->{utc_rd_secs},
             );

When DateTime::Duration::new() sees the negative 44488 - 82860,
it decides the duration will be negative.


    '_d' => DateTime=HASH(0x11ce064)
       'c' => HASH(0x11ce1fc)
          'day' => 9
          'day_of_week' => 7
          'day_of_year' => 40
          'hour' => 13
          'minute' => 21
          'month' => 2
          'second' => 28
          'year' => 2003
       'local_rd_days' => 731255
       'local_rd_secs' => 48088
       'tz' => DateTime::TimeZone::OffsetOnly=HASH(0x11ce268)
          'offset' => 3600
       'utc_rd_days' => 731255
       'utc_rd_secs' => 44488

    '_d' => DateTime=HASH(0x11cf31c)
       'c' => HASH(0x11cf8c4)
          'day' => 16
          'day_of_week' => 5
          'day_of_year' => 350
          'hour' => 0
          'minute' => 1
          'month' => 12
          'second' => 0
          'year' => 1994
       'local_rd_days' => 728278
       'local_rd_secs' => 60
       'tz' => DateTime::TimeZone::OffsetOnly=HASH(0x11cf924)
          'offset' => 3600
       'utc_rd_days' => 728277
       'utc_rd_secs' => 82860

--
Eric Cholet


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About