Heavily based on python-dateutil/rrule
Some useful terms to understand the algorithms and variables naming:
yearday = day of the year, from 0 to 365 (on leap years) - date('z')
weekday = day of the week (ISO-8601), from 1 (MO) to 7 (SU) - date('N')
monthday = day of the month, from 1 to 31
wkst = week start, the weekday (1 to 7) which is the first day of week.
Default is Monday (1). In some countries it's Sunday (7).
weekno = number of the week in the year (ISO-8601)
CAREFUL with this bug: https://bugs.php.net/bug.php?id=62476