teambition / rrule-go

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

Wrong time for events far into the future #55

Closed CubicrootXYZ closed 2 years ago

CubicrootXYZ commented 2 years ago

I am parsing this event:

BEGIN:VCALENDAR
PRODID:-//xyz Corp//NONSGML PDA Calendar Version 1.0//EN
VERSION:2.0
BEGIN:VEVENT
DTSTAMP:19960704T120000Z
UID:uid1@example.com
ORGANIZER:mailto:jsmith@example.com
DTSTART:21500918T143000Z
RRULE:FREQ=WEEKLY;BYDAY=MO
DTEND:21500918T153000Z
STATUS:CONFIRMED
CATEGORIES:CONFERENCE
SUMMARY:A test event summary
DESCRIPTION:A test event description
END:VEVENT
END:VCALENDAR

And then calling rruleObj.After(refTime, false) where refTime is the start of the event, so 2150-09-18 14:30. The result I am getting is 2150-09-21 15:19:41. But I'd expect it to be 2150-09-21 14:30:00.

The actual implementation is a testcase for a bot of me: https://github.com/CubicrootXYZ/RemindMe/blob/%2370-add-recurring-events/internal/icalimporter/icalimporter_test.go#L37.

Maybe there is sth. going wrong with leap years? Or my event is malformed? I'd appreciate any help on this topic.

zensh commented 2 years ago

I have run your case, there is nothing wrong:

package main

import (
    "fmt"
    "time"

    "github.com/teambition/rrule-go"
)

func main() {
    rruleset, _ := rrule.StrToRRuleSet("DTSTART:21500918T143000Z\nRRULE:FREQ=WEEKLY;BYDAY=MO")
    t := time.Date(2150, 9, 18, 14, 30, 0, 0, time.UTC)
    fmt.Println(rruleset.After(t, false))
    // 2150-09-21 14:30:00 +0000 UTC
}
CubicrootXYZ commented 2 years ago

Ah it works as soon as I pass the DTSTART attribute to the rrule too. Makes sense since otherwise the it can not know the actual start, but it is as far as I can see not mentioned in the documentation. Might be worth adding it there.

Thanks a lot for looking into this and helping me out.