Search code examples
phprecurrencerrule

Rrule from Datetime collection


I'm making a recurrent activity calendar system and i'm facing an issue. My activity has a collection of Period items, which contain a StartedAt Datetime and an EndedAt Datetime.

A lot of libs allow me to convert my RRule from a string to Period-like items, but it seems that the reverse (Having multiple "DateTime-couples" converted to a RRule string) isn't common at all.

Any option about this ?


Solution

  • A lot of libs allow me to convert my RRule from a string to Period-like items, but it seems that the reverse (Having multiple "DateTime-couples" converted to a RRule string) isn't common at all.

    That's because it's not possible. A given RRule generates one and only one set of occurrences, but the opposite is not true - a given set of occurrences can be generated by a multitude of RRules.

    In other words, it's impossible to know the exact rule that generated a collection of dates.