SBECK-github / Date-Manip

Other
10 stars 11 forks source link

Use of uninitialized value $n in integer subtraction #36

Closed vitstradal closed 3 years ago

vitstradal commented 3 years ago

When I have same start and end date, ->next works fine and as expected, but generates unexpcepted and unwanted warning:

$ perl -MDate::Manip::Recur -E 'my $r = Date::Manip::Recur->new; $r->parse("0:0:0:*17:30:0"); $r->basedate("2015-06-01,");$r->start("2015-06-01,"); $r->end("2015-06-01,"); my ($date, $err) = $r->next ; say join (" ", $date->value )' 
Use of uninitialized value $n in integer subtraction (-) at /home/foo/perl5/lib/perl5/Date/Manip/Recur.pm line 920.
2015 6 1 17 30 0
SBECK-github commented 3 years ago

You have discovered a bug in the 'next' method, though not exactly the one you thought. Your example should not have reported anything (i.e. no warning, but also no date).

You have specified both a start and end date as 2015-06-01 (and remember that when specifying a date, if you don't give a time, it defaults to midnight). If I switch to using the 'dates' method (which does not suffer from the bug):

   $r->start("2015-06-01,");
   $r->end("2015-06-01,");

   my @date = $r->dates();
   foreach my $date (@date) {
      say join (" ", $date->value);
   }

and run it, it produces nothing. But if I change the end date to "2015-06-03", it produces:

   2015 6 1 17 30 0
   2015 6 2 17 30 0

The date range says that a recurring event will be:

start <= date <= end

So you have specified:

2015-06-01-00:00:00 <= date <= 2015-06-01-00:00:00

So your recurrence (every day at 17:30:00) clearly has zero matches. And the $r->dates() method shows that to be true. I'm going to fix the bug in the next method so it works correctly without a warning, but so it also won't return a date.

SBECK-github commented 3 years ago

This is fixed now and will be corrected in the next release.