'In Dart get next occurring date from an rrule

Is there a Dart library or, lacking one, a correct way to handle finding the next date that would be returned from a correctly formatted rrule?

For example give the following rule: "FREQ=WEEKLY;BYDAY=WE;INTERVAL=1;DTSTART=20180328T160000Z"

I would want a date time value of the next occurring Wed.



Solution 1:[1]

Don't know if there is a library for this, but I quickly came up with this. Not complete, but it's a start.

void main() {
    var today = DateTime.parse('20180328T160000Z');

    var days = today.weekday < DateTime.wednesday ? DateTime.wednesday - today.weekday : 7 - today.weekday + DateTime.wednesday;

    var next = today.add(new Duration(days:days));
    print(next);
}

Others might come up with something better. Parsing the rule would be the hard part.

Solution 2:[2]

I've been using rrule for a while and quite happy with it

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Ali80