teambition / rrule-go

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

Changing DTStart not changing iterator #20

Closed srikrsna closed 5 years ago

srikrsna commented 5 years ago

Hi, Thank you for this. It's been really helpful for us.

One issue I've noticed was that changing the DTStart for an rrule set does not change the actual values generated by the iterator. For example,

package main

import (
    "log"
    "github.com/teambition/rrule-go"
)

func main() {
    log.SetFlags(0)
    ogr := []string{"DTSTART;TZID=America/Los_Angeles:20181115T000000", "RRULE:FREQ=DAILY;INTERVAL=1;WKST=SU;UNTIL=20181118T235959"}
    set, err := rrule.StrSliceToRRuleSet(ogr)
    if err != nil {
    log.Fatalln(err)
    }

    log.Println("Original Recurrence: ", ogr)
    for _, t := range set.All() {
    log.Println(t)
    }

    set.DTStart(set.GetDTStart().AddDate(0, 0, 1))

    log.Println("New Recurrence: ", set.Recurrence())

    for _, t := range set.All() {
    log.Println(t)
    }

    ns, err := rrule.StrSliceToRRuleSet(set.Recurrence())
    if err != nil {
    log.Fatalln(err)
    }

    log.Println("Reparsed Recurrence: ", ns.Recurrence())

    for _, t := range ns.All() {
    log.Println(t)
    }
}

This prints out the following,

Original Recurrence:  [DTSTART;TZID=America/Los_Angeles:20181115T000000 RRULE:FREQ=DAILY;INTERVAL=1;WKST=SU;UNTIL=20181118T235959]
2018-11-15 00:00:00 -0800 PST
2018-11-16 00:00:00 -0800 PST
2018-11-17 00:00:00 -0800 PST
2018-11-18 00:00:00 -0800 PST
New Recurrence:  [DTSTART:TZID=America/Los_Angeles:20181116T000000 RRULE:FREQ=DAILY;INTERVAL=1;WKST=SU;UNTIL=20181118T235959Z]
2018-11-15 00:00:00 -0800 PST
2018-11-16 00:00:00 -0800 PST
2018-11-17 00:00:00 -0800 PST
2018-11-18 00:00:00 -0800 PST
Reparsed Recurrence:  [DTSTART:TZID=America/Los_Angeles:20181116T000000 RRULE:FREQ=DAILY;INTERVAL=1;WKST=SU;UNTIL=20181118T235959Z]
2018-11-16 00:00:00 -0800 PST
2018-11-17 00:00:00 -0800 PST
2018-11-18 00:00:00 -0800 PST

As you can see changing the DTStart changed the recurrence but did not have any impact on the iterator. If this is the expected behaviour, it should be documented. If not I am more than happen to try and fix this.

rickywiens commented 5 years ago

I can't comment to what the expected functionality is, but I think you can get what you want by using the After method instead.

Something like:

ns.After(time.Now(), false)

and iterating over it that way.

srikrsna commented 5 years ago

All I am saying is that setting DTStart has changed the output of the Recurrence function but didn't really update the actual rrule set.

I am saying third should be the expected output and the second output is wrong.

And After does not return the same output for more complex rules.

rickywiens commented 5 years ago

Sorry I reviewed the code again and saw my mistake. I agree that what you are proposing should be the output.

damoye commented 5 years ago

The code actually doesn't use the DTStart to do anything.

srikrsna commented 5 years ago

Shall I send a PR correcting it?