FAQ
Hello

I am attempting to create a number of DateTime::Span objects for the
past hour, past 24 hours, past week etc. The code I am using looks like
this:

      my $last24hours = DateTime::Span->from_datetime_and_duration(
          end => DateTime->now(),
          duration => DateTime::Duration->new( hours => 24 ),
      );

The code is not working as expected. Instead, I am getting a 24 hour
time span from now into the future rather than into the past.

I have had a peek at the source code for from_datetime_and_duration(),
and it looks like it always adds the duration to the supplied DateTime
regardless of weather it is supplied as a start or end.

Is this a bug? I can supply a test case or patch if necessary.

--
David Pottage
CV Library Ltd.

Search Discussions

  • Karen Etheridge at Aug 27, 2013 at 3:52 pm

    On Tue, Aug 27, 2013 at 10:02:41AM +0100, David Pottage wrote:
    I have had a peek at the source code for from_datetime_and_duration(),
    and it looks like it always adds the duration to the supplied DateTime
    regardless of weather it is supplied as a start or end.
    Is this a bug? I can supply a test case or patch if necessary.
    That sounds like a bug to me -- either the API shouldn't accept an end at
    all (should always require the caller to calculate the start), or it should
    apply the duration into the past when 'end' is provided rather than
    'start'.
  • Mark Stosberg at Aug 27, 2013 at 4:13 pm

    On 08/27/2013 11:52 AM, Karen Etheridge wrote:
    On Tue, Aug 27, 2013 at 10:02:41AM +0100, David Pottage wrote:
    I have had a peek at the source code for from_datetime_and_duration(),
    and it looks like it always adds the duration to the supplied DateTime
    regardless of weather it is supplied as a start or end.
    Is this a bug? I can supply a test case or patch if necessary.
    That sounds like a bug to me -- either the API shouldn't accept an end at
    all (should always require the caller to calculate the start), or it should
    apply the duration into the past when 'end' is provided rather than
    'start'.
    Agreed.

        Mark
  • Flavio S. Glock at Aug 27, 2013 at 6:54 pm
    I've uploaded DateTime-Set-0.32 to cpan.

    The idea was that you would specify 'end' and a negative duration, like:

         DateTime::Span->from_datetime_**and_duration(
             end => DateTime->now(),
             hours => -24
         )

    but that would not work because of a bug in 0.31 or before.

    The new version ignores the signal of the duration, and it does the right
    thing depending on which other endpoint is specified.

    diff:
    https://github.com/fglock/DateTime-Set/commit/83350c3e99455b5cbd0d2c158b0b7168b5c9908e

    Flávio S. Glock

    2013/8/27 David Pottage <d.pottage@cv-library.co.uk>
    Hello

    I am attempting to create a number of DateTime::Span objects for the past
    hour, past 24 hours, past week etc. The code I am using looks like this:
    my $last24hours = DateTime::Span->from_datetime_and_duration(
    end => DateTime->now(),
    duration => DateTime::Duration->new( hours => 24 ),
    );

    The code is not working as expected. Instead, I am getting a 24 hour time
    span from now into the future rather than into the past.
    I have had a peek at the source code for from_datetime_and_duration(),
    and it looks like it always adds the duration to the supplied DateTime
    regardless of weather it is supplied as a start or end.
    Is this a bug? I can supply a test case or patch if necessary.

    --
    David Pottage
    CV Library Ltd.
  • David Pottage at Aug 28, 2013 at 10:12 am

    On 27/08/13 19:54, Flavio S. Glock wrote:
    I've uploaded DateTime-Set-0.32 to cpan.

    The idea was that you would specify 'end' and a negative duration, like:

    DateTime::Span->from_datetime_and_duration(
    end => DateTime->now(),
    hours => -24
    )
    I saw that, but I could not make it work, and in any case I am not sure
    that it makes sense for time durations to have a sign, though I dare say
    someone will show me a counter example.
    but that would not work because of a bug in 0.31 or before.

    The new version ignores the signal of the duration, and it does the
    right thing depending on which other endpoint is specified.

    diff:
    https://github.com/fglock/DateTime-Set/commit/83350c3e99455b5cbd0d2c158b0b7168b5c9908e
    Thanks, that is impressively speedy service, especially after the last
    time I attempted to report a bug in the DateTime distro, and was told
    (paraphrased), "We have documented our illogical behavior so it is not a
    bug."

    --
    David Pottage
    CV Library Ltd.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdatetime @
categoriesperl
postedAug 27, '13 at 9:02a
activeAug 28, '13 at 10:12a
posts5
users4
websitemetacpan.org...

People

Translate

site design / logo © 2019 Grokbase