Parse RRULE to readable text?

2019-07-21 02:18发布

问题:

I am looking for a library (php) or some pseudocode to parse Ical RRULEs to readable text(like for example google calendar)

RRULE:FREQ=MONTHLY;INTERVAL=1;BYDAY=1FR,3FR,5FR

-> Monthly on Friday of weeks 1, 3, 5 of the month

回答1:

I was wondering the same thing and I struggled to find one, but I found one which is still in development, and you can find it here: https://github.com/simshaun/recurr/tree/v0.2-dev

I was able to get it working with this code:

$timezone        = 'America/New_York';
$startDate       = new \DateTime('2013-06-12 20:00:00', new \DateTimeZone($timezone));
$rule            = new \Recurr\Rule('FREQ=MONTHLY;COUNT=5', $startDate, $timezone);
$textTransformer = new  \Recurr\Transformer\TextTransformer();
echo $textTransformer->transform($rule);

I believe it's not perfect yet and I guess it's still changing while in dev, but looks very promising.