Skip to content

fix: check recurring event with correct timezone #31

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

Merged
merged 2 commits into from
Oct 24, 2024
Merged

fix: check recurring event with correct timezone #31

merged 2 commits into from
Oct 24, 2024

Conversation

alexsmshchnko
Copy link
Contributor

using local timezone leads to error in data comparison

using local timezone leads to error in data comparison
@alexsmshchnko
Copy link
Contributor Author

@apognu kindly approve

@apognu
Copy link
Owner

apognu commented Oct 20, 2024

Sorry I missed this. Could you:

  • Give an example (in comment) of a wrong interpretation due to the bug?
  • Add a unit test that enforces your change so there is no regression on the future?

@morotsgurka
Copy link

I'll just add that i think I'm affected by this bug?

For example for this event:

BEGIN:VEVENT
RRULE:FREQ=WEEKLY;UNTIL=20241216T090000Z;INTERVAL=1;BYDAY=MO;WKST=MO
EXDATE;TZID=W. Europe Standard Time:20240909T100000,20240923T100000,2024100
 7T100000,20241021T100000,20241104T100000
UID:some-random-number
SUMMARY:Some event summary
DTSTART;TZID=W. Europe Standard Time:20240826T100000
DTEND;TZID=W. Europe Standard Time:20240826T110000
CLASS:PUBLIC
PRIORITY:5
DTSTAMP:20241021T110643Z
TRANSP:OPAQUE
STATUS:CONFIRMED
SEQUENCE:0
LOCATION:Microsoft Teams-meeting\; Example room
X-MICROSOFT-CDO-APPT-SEQUENCE:0
X-MICROSOFT-CDO-BUSYSTATUS:BUSY
X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY
X-MICROSOFT-CDO-ALLDAYEVENT:FALSE
X-MICROSOFT-CDO-IMPORTANCE:1
X-MICROSOFT-CDO-INSTTYPE:1
X-MICROSOFT-DONOTFORWARDMEETING:FALSE
X-MICROSOFT-DISALLOW-COUNTER:FALSE
X-MICROSOFT-REQUESTEDATTENDANCEMODE:DEFAULT
X-MICROSOFT-ISRESPONSEREQUESTED:FALSE
END:VEVENT

The event is flagged as IsRecurring True, but ExcludeDates is empty

I had to add the timezone mapping to the parser since "W. Europe Standard Time" was not parsed by go and they returned as "UTC".

var tzMapping = map[string]string{
	"W. Europe Standard Time": "Europe/Stockholm",
}
gocal.SetTZMapper(func(s string) (*time.Location, error) {
	if tzid, ok := tzMapping[s]; ok {
		return time.LoadLocation(tzid)
	}
	return nil, fmt.Errorf("")
})

@alexsmshchnko
Copy link
Contributor Author

alexsmshchnko commented Oct 21, 2024

BEGIN:VEVENT
DTSTART;TZID=Europe/Moscow:20240927T190000
DTEND;TZID=Europe/Moscow:20240927T200000
SUMMARY:Glutes and abs
UID:1a4pqkardx6cdkov4mj0
SEQUENCE:2
DTSTAMP:20241021T153542Z
CREATED:20240923T130134Z
DESCRIPTION:{\n\"name\": \"Glutes+abs\"\,\n\"announce_days\": 0\,\n\"announce_time\": \"09:20\"\,\n\"announce_close_days\": 0\,\n\"announce_close_time\": \"14:00\"\,\n\"trainer\": \"Galina\"\,\n}
RRULE:FREQ=WEEKLY;BYDAY=FR;UNTIL=20241228T170000Z;INTERVAL=1
TRANSP:OPAQUE
CATEGORIES:studioYY
LAST-MODIFIED:20240923T130312Z
CLASS:PRIVATE
END:VEVENT
BEGIN:VEVENT
DTSTART;TZID=Europe/Moscow:20241025T190000
DTEND;TZID=Europe/Moscow:20241025T200000
SUMMARY:Glutes and abs
UID:1a4pqkardx6cdkov4mj0
SEQUENCE:1
DTSTAMP:20241021T153542Z
CREATED:20241018T073451Z
DESCRIPTION:{\n\"name\": \"Glutes+abs\"\,\n\"announce_days\": 0\,\n\"announce_time\": \"09:20\"\,\n\"announce_close_days\": 0\,\n\"announce_close_time\": \"14:00\"\,\n\"trainer\": \"Julia\"\,\n}
RECURRENCE-ID;TZID=Europe/Moscow:20241025T190000
TRANSP:OPAQUE
CATEGORIES:studioYY
LAST-MODIFIED:20241018T073451Z
CLASS:PRIVATE
END:VEVENT

Param TZID is specified with timezone, but ignored in parser.ParseTime due to empty input param. So recurrence is used with UTC timezone.
It leads to inequality of dates when comparing gocal.IsRecurringInstanceOverriden

@apognu , should I add a test to the gocal_test.go file?

@apognu
Copy link
Owner

apognu commented Oct 21, 2024

Thank you for explaining, it's clearer now.

Please add a test (a simple one will do, one event with a timezone-aware recurrence rule) and check that the repeated events happen at the right time.

Once that's done, I see no problem merging this in.

@alexsmshchnko
Copy link
Contributor Author

@apognu , I added the test file. Please let me know if you have any questions.

@apognu apognu merged commit c1eae90 into apognu:master Oct 24, 2024
@apognu
Copy link
Owner

apognu commented Oct 24, 2024

LGTM.

@morotsgurka
Copy link

LGTM.

Could you create a new release for this? Like v0.9.1 ?

@apognu
Copy link
Owner

apognu commented Oct 27, 2024

Done. 👍

@morotsgurka
Copy link

Just wanted to say that this seems to have fixed my issue, thanks!
I'm using this in a current project to publish calendar events to MQTT topics (which will be parsed by ESP32 devices and displayed outside meeting rooms)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants