teambition / rrule-go

Go library for working with recurrence rules for calendar dates.
MIT License
310 stars 57 forks source link

After generating a rule from a string, rule.DTStart does not work as expected [has workaround] #39

Closed rrufus closed 4 years ago

rrufus commented 4 years ago

If I have code like:

startTime := /* some time which is not now, including some day which is not today */
rruleString := "FREQ=WEEKLY"
myRule, _ := rrule.StrToRRule(rruleString)
myRule.DTStart(startTime)

Then the initial calculations of day of the week for the rrule to match are wrong, as the calculations done here and in the following lines (which assume using time.Now() is valid) https://github.com/teambition/rrule-go/blob/master/rrule.go#L145 are never re-done.

Workaround The workaround is to use rrule.StrToROption / rrule.StrToROptionInLocation and then on the resultant options struct, set Dtstart to your start time.