Skip to content
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

Synced Timezone wrong #168

Closed
Trefex opened this issue Jul 4, 2024 · 17 comments
Closed

Synced Timezone wrong #168

Trefex opened this issue Jul 4, 2024 · 17 comments

Comments

@Trefex
Copy link

Trefex commented Jul 4, 2024

Hi,

In my source, events are at 1 PM, but in the sink, they will be synced as 11 AM.

Are timezones perhaps not handled correctly or is it something i missed in a config?

Thanks
T

@alxndr13
Copy link
Contributor

Hey! Thanks for the bug report! (and sorry for the late response!)

Could you give me some more details? Are you using different timezone's in both calendars?

@Trefex
Copy link
Author

Trefex commented Jul 13, 2024

Hey! Thanks for the bug report! (and sorry for the late response!)

Could you give me some more details? Are you using different timezone's in both calendars?

I basically sync to the same account in a different calendar for testing, so i guess the timezones are the same?

@Trefex
Copy link
Author

Trefex commented Aug 7, 2024

@alxndr13 is it possible that for the Outlook to Outlook use case, timezone is not handled properly ?

https://github.com/inovex/CalendarSync/blob/main/internal/adapter/outlook_http/client.go#L275

@alxndr13
Copy link
Contributor

alxndr13 commented Sep 4, 2024

@Trefex i just found the time to dig deeper into this.

Thanks for the bug report again! We definitely aren't handling timezones the way we should. I tested this as follows:

Created an event in my outlook source and made sure to use a different timezone. (Asia/Tomsk)

The event will then be represented in the API Response in UTC[1], the only fields which would cover the timezone correctly is the originalStartTimeZone and originalEndTimeZone[2]. The DateTimeTimeZone field just has the timezone set to UTC, which seems counterintuitive.

[1]:
screenshot 2024-09-04 at 19 11 25

[2]:
screenshot 2024-09-04 at 19 10 53

This is also why it is working all the time for my case, where i have outlook as the sink: i just retrieve the UTC Time and write it in UTC to my google sink. The clients then represent the events according to my machines timezone.

In case we use outlook as a sink, we should make sure to convert (and set) the timezone to UTC when retrieving events. Your local client should then show the time according to your preferred timezone.

Need to attend a padel match now, will have a deeper look at this in the coming days i hope.

@Trefex
Copy link
Author

Trefex commented Sep 8, 2024

@alxndr13
Copy link
Contributor

Hi @Trefex,

could you try to build the app with the fix-168 branch and test if that fixes your problem?

@Trefex
Copy link
Author

Trefex commented Sep 16, 2024

@alxndr13 it is the same result. All events are shifted by 2 hours (I am in CEST).

From the PR, it seems though as the timezone is not set / added in https://github.com/inovex/CalendarSync/blob/main/internal/adapter/outlook_http/client.go#L275 ?

I think the timeZone need to be set as well when writing back the event in Outlook, otherwise you will write the time in UTC?

➜  bin git:(fix-168) ./calendarsync --version
Version: 7e7d652

@alxndr13
Copy link
Contributor

alxndr13 commented Sep 18, 2024

ah, understood. This is uncoventional, as this differentiates it from the google adapter.. When writing calendar events into the google sink using UTC as the events timezone, it is still always represented in your computers timezone. (which makes sense, it's the same time, just differently displayed)

Example flow when outlook is my source and google my sink:

  • Event is retrieved from outlook, time is 3pm CEST
  • gets converted into our internal format and to UTC (1pm)
  • written to google in UTC (1pm)
  • but gets represented in my browser as 3pm

Which is what i would expect..

But outlook seems to handle this differently and presents the event in it's original timezone and not your local timezone, which doesnt make sense imo. (why would you look at events where each event has a different timezone??)

(not sure if this is actually the case but this would explain the behaviour you're describing)

EDIT: nope, can't reproduce your isse @Trefex ..

Created an event in my google source at 2:30pm GMT+3, showed up as 1:30pm in google calendar (local timezone is +2). After the sync it was shown at 1:30pm in my outlook sink as well..

see:

image
image
image

Maybe i need some more data from the events you try to sync @Trefex ...

@Trefex
Copy link
Author

Trefex commented Sep 18, 2024

@alxndr13 what if you use Outlook as source and Outlook as sync ? I can provide a calendar JSON if that would help.

Is there a way to get full debug info of what is actually written to the sink ?

@alxndr13
Copy link
Contributor

@Trefex used google as source, outlook as sink in the example above.

Calendar JSOn would help, yes. Please make sure to remove all personal information

@Trefex
Copy link
Author

Trefex commented Sep 20, 2024

@alxndr13

Source (Outlook)

    "@odata.context": "xxx",
    "@odata.etag": "xxxx",
    "id": "xxxx",
    "subject": "xxxx",
    "bodyPreview": "Rolling minutes: xxx",
    "body": {
        "contentType": "html",
        "content": "xxxx"
    },
    "start": {
        "dateTime": "2024-09-20T11:00:00.0000000",
        "timeZone": "UTC"
    },
    "end": {
        "dateTime": "2024-09-20T12:00:00.0000000",
        "timeZone": "UTC"
    },
    "location": {
        "displayName": "xxxx",
        "locationType": "default",
        "uniqueId": "xxxxx",
        "uniqueIdType": "private"
    },
    "attendees": [
        {
            "type": "required",
            "status": {
                "response": "none",
                "time": "0001-01-01T00:00:00Z"
            },
            "emailAddress": {
                "name": "xxxx",
                "address": "xxxx"
            }
        },
        {
            "type": "required",
            "status": {
                "response": "none",
                "time": "0001-01-01T00:00:00Z"
            },
            "emailAddress": {
                "name": "xxxx",
                "address": "xxxx"
            }
        }
    ],
    "organizer": {
        "emailAddress": {
            "name": "xxxx",
            "address": "xxxxx"
        }
    },
    "[email protected]": "xxxx",
    "[email protected]": "xxxx"
}

Sink (Outlook)

    "value": [
        {
            "@odata.etag": "xxxx",
            "id": "xxxx",
            "createdDateTime": "2024-09-20T06:52:01.9038305Z",
            "lastModifiedDateTime": "2024-09-20T06:54:03.2007083Z",
            "changeKey": "xxxx",
            "categories": [],
            "transactionId": null,
            "originalStartTimeZone": "Europe/Luxembourg",
            "originalEndTimeZone": "Europe/Luxembourg",
            "iCalUId": "xxxx",
            "uid": "xxxxx",
            "reminderMinutesBeforeStart": 10,
            "isReminderOn": true,
            "hasAttachments": false,
            "subject": "[ELU] xxxx",
            "bodyPreview": "xxxx",
            "importance": "normal",
            "sensitivity": "normal",
            "isAllDay": false,
            "isCancelled": false,
            "isOrganizer": true,
            "responseRequested": true,
            "seriesMasterId": null,
            "showAs": "busy",
            "type": "singleInstance",
            "webLink": "xxxx",
            "onlineMeetingUrl": null,
            "isOnlineMeeting": false,
            "onlineMeetingProvider": "unknown",
            "allowNewTimeProposals": true,
            "occurrenceId": null,
            "isDraft": false,
            "hideAttendees": false,
            "responseStatus": {
                "response": "organizer",
                "time": "0001-01-01T00:00:00Z"
            },
            "body": {
                "contentType": "html",
                "content": "xxxx"
            },
            "start": {
                "dateTime": "2024-09-04T08:00:00.0000000",
                "timeZone": "UTC"
            },
            "end": {
                "dateTime": "2024-09-04T09:00:00.0000000",
                "timeZone": "UTC"
            },
            "location": {
                "displayName": "xxxx",
                "locationType": "default",
                "uniqueId": "xxxx",
                "uniqueIdType": "private"
            },
            "locations": [
                {
                    "displayName": "xxxx",
                    "locationType": "default",
                    "uniqueId": "xxxxx",
                    "uniqueIdType": "private"
                }
            ],
            "recurrence": null,
            "attendees": [],
            "organizer": {
                "emailAddress": {
                    "name": "xxxx",
                    "address": "xxxxx"
                }
            },
            "onlineMeeting": null
        },

@alxndr13
Copy link
Contributor

alxndr13 commented Oct 1, 2024

Hi @Trefex,

fyi: Yesterday was my last day at Inovex. Since I won't be using CalendarSync daily anymore, addressing this issue will take some time as I'm focusing on my new role.

@MichaelEischer
Copy link
Collaborator

I've read through the issue and am still confused what's going on.

tzname, err := tzlocal.RuntimeTZ()
looks suspicious though. It determines the local TZ and sets that for the timestamps of a to be written event. That could explain what you're seeing. The UTC timestamp 2024-09-20T11:00:00 gets marked as CEST. After normalizing that timestamp again to UTC, we're now at 2024-09-20T9:00:00. (not sure why the event snippets show a time diff of three hours though).

Can you try whether setting the environment variable TZ=UTC makes the problem disappear?

@Trefex
Copy link
Author

Trefex commented Oct 10, 2024

@MichaelEischer this indeed fixes the issue. I have now tested on the #187 branch.

Would this require a fix in the code or should the docs be updated to reflect the TZ env variable be set to UTC

Thank you !

@MichaelEischer
Copy link
Collaborator

Would this require a fix in the code

This definitely should be fixed in the code, the current inconsistent timezone handling is definitely broken. Not sure when I'll get around to fix it.

@Trefex
Copy link
Author

Trefex commented Oct 10, 2024

No worries, in the meantime, the workaround is fine.

I am more curious about #166 :)

@MichaelEischer
Copy link
Collaborator

fixed via #187.

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

No branches or pull requests

3 participants