-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rule Set: All() returns events in local time even if DTStart is provided as an UTC time object #25
Comments
Hi, I spent some time today figuring this out. I have a fix working locally but it's not super great. I think this has to do with I have a unit test locally to reproduce the issue: func TestSetTimezonesDtStartSticky(t *testing.T) {
set := &Set{}
rule, err := StrToRRule("FREQ=DAILY;COUNT=10;WKST=MO;BYHOUR=10;BYMINUTE=0;BYSECOND=0")
if err != nil {
panic(err)
}
set.RRule(rule)
dt := time.Date(2019, 3, 6, 0, 0, 0, 0, time.UTC)
set.DTStart(dt)
// set.All() returns events in my local timezone instead of UTC
for _, event := range set.All() {
if event.Location().String() != time.UTC.String() {
t.Errorf("Timezone set incorrectly on recurrence after DtStart set: [%s]", event.String())
}
}
} But the way I fixed it was to recreate all the rrules and exrules when the DtStart is set: // DTStart sets dtstart property for all rules in set
func (set *Set) DTStart(dtstart time.Time) {
var newrruleset []*RRule
var newexruleset []*RRule
set.dtstart = dtstart
for _, r := range set.rrule {
r.dtstart = dtstart
r.OrigOptions.Dtstart = dtstart
nr, err := NewRRule(r.OrigOptions)
if err != nil {
return
}
newrruleset = append(newrruleset, nr)
}
for _, xr := range set.exrule {
xr.dtstart = dtstart
xr.OrigOptions.Dtstart = dtstart
nxr, err := NewRRule(xr.OrigOptions)
if err != nil {
return
}
newexruleset = append(newexruleset, nxr)
}
set.rrule = newrruleset
set.exrule = newexruleset
} I don't particularly like that fix, so if you have some ideas I'd love to hear them :). |
@rickywiens thank you for your quick response! I will see what I can cook up and create a pull request if I think it's good enough. 😄 |
@rickywiens @damoye I've created a pull request with a fix. Thank you. |
Hello everybody.
I want to report a suspected bug. I'm able to provide a pull request with a fix if this is indeed a bug.
Bug description
The DTStart's timezone is not respected when requesting a list of upcoming events.
Code for reproducing the bad behavior
Expected results
Actual results
The text was updated successfully, but these errors were encountered: