tplaner / When

PHP Date Recursion library

Home Page:https://github.com/tplaner/When

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting the next occurance or rule from NOW

bobemoe opened this issue · comments

The start date must be the first occurrence. So given a specific rule, say: FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13 how would I calculate the next occurrence after NOW?

I've tried: $r->RFC5545_COMPLIANT = When::IGNORE; but this just gives an empty array, as expected I think.

This looks interesting #19 but I cant get it to work, even after calling adjustStartDate() I still get the The start date must be the first occurrence exception.

Is this possible? I'm planning on using this to calculate when a specific rule would occur next (relative to today/now) without knowing any occurrences.

Ideas? Thanks.

Hi @bobemoe, I have just tried and it works perfectly as expected:

$r = new When();
$r->RFC5545_COMPLIANT = When::IGNORE;
$r->startDate(new \DateTime())
  ->count(1)
  ->rrule("FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13")
  ->generateOccurrences();

return $r->occurrences;

@boryn thanks for this. I'm no longer working on this project so have no way to confirm it solves my original issue.

But if you've tested it (and assuming it wasn't friday the 13th when you did the test) I'd be happy for you to close the issue.

thanks :)

Yeah, you asked this two years ago and I just started using the library two days ago :)