tplaner / When

PHP Date Recursion library
https://github.com/tplaner/When
MIT License
511 stars 96 forks source link

Daily and getOccurrencesBetween #93

Open davidh71 opened 2 years ago

davidh71 commented 2 years ago

I've just started using the library and it's great! The below doesn't work and I'm wondering if my approach is wrong or a defect. I would expect to get 2 results back - and get nothing. Many Thanks!

$r = new When\When();
$r->RFC5545_COMPLIANT = When\When::IGNORE;
$r->startDate(new DateTime("20220902"))
->freq("daily")
->interval( 1 );

$occurrences = $r->getOccurrencesBetween(new DateTime("20220902"),new DateTime("20220904"));
var_dump($r->occurrences);
davidh71 commented 2 years ago

found my problem in the above - silly mistake. My apologies

I would like some clarity on the getOccurrencesBetween behavior. If i run this - i don't get any dates ON, or AFTER the end date

$r->startDate(new DateTime("20220902"))
  ->freq("daily")
  ->interval( 1 );
$occurrences = $r->getOccurrencesBetween(new DateTime("20220903"),new DateTime("20220907"));
var_export($occurrences);

but when i use weekly, it includes days ON the end date

$r->startDate(new DateTime("20220902"))
  ->freq("weekly")
  ->byday("mo,tu,we,th,fr,sa,su")
  ->interval( 1 );

$occurrences = $r->getOccurrencesBetween(new DateTime("20220903"),new DateTime("20220907"));
var_export($occurrences);

Is there a reason 'between' is inconsistent with the end date?

marcoczen commented 1 month ago

Hi. I noticed the same thing too. Using the latest version of when ( v3.1.5) So for 'daily' . i just added 1 more day for the $dateEnd.

Weekly does not have this issue.

tplaner commented 1 month ago

Definitely looks like a bug. I'm open to looking at PRs if someone figures out the issue.

marcoczen commented 1 month ago

Wow ... a reply from the man himself. You have created a great library .... Just 2 php files.... What a genius.

PR -> For php, I am in the noob - intermediate range .... Too dumb for this kind of work.

Once again ... a great library...