teambition / rrule-go

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

StrToRRule Does Not Apply Timezone to UNTIL and treats it as UTC #37

Closed Ferix9288 closed 4 years ago

Ferix9288 commented 4 years ago

Basically when it parses a RRULE expression like below where it’s supposed to generate one recurrence on 3/3/2020, it treats the UNTIL as UTC time instead of the specified timezone in the RRULE.

Expression in question:

DTSTART;TZID=America/Los_Angeles:20200225T060000
RRULE:FREQ=WEEKLY;INTERVAL=1;WKST=MO;BYDAY=TU;UNTIL=20200303T063000

Instead of reading UNTIL as LA time 3/3/2020 6:30AM, it reads that as LA time 3/2/2020 10:30PM.

Code-wise, what happens is as follows:

  1. You call StrToRRuleSet.
  2. It correctly trims and parses TZID and overloads locale.
  3. However, it then calls below which completely ignores any locale and forces UTC.
// StrToROption converts string to ROption
func StrToROption(rfcString string) (*ROption, error) {
    return StrToROptionInLocation(rfcString, time.UTC)
}
Ferix9288 commented 4 years ago

Hmm I see. Looks like behavior was intentional based on the specification:

 The UNTIL rule part defines a date-time value which bounds the
   recurrence rule in an inclusive manner. If the value specified by
   UNTIL is synchronized with the specified recurrence, this date or
   date-time becomes the last instance of the recurrence. If specified
   as a date-time value, then it MUST be specified in an UTC time
   format. If not present, and the COUNT rule part is also not present,
   the RRULE is considered to repeat forever.

That's confusing >.<''