I am writing a python script that adds new events to user's calendars, assuming that the user's timezone is unknown. But since the StartDateTime and EndDateTime I set are always in UTC, and not the user's own timezone, they show up as different times on the user's calendar. For example, when I insert this:
{'Subject': 'Meeting', 'StartDateTime':'2017-07-01T14:15:00',
'EndDateTime': '2017-07-01T16:15:00'}
The event shows up in the user's calendar as starting at 7:15AM and ending at 9:15AM (the user's timezone in this case is America/Los_Angeles).
I've read that Salesforce API uses UTC, so it doesn't appear like I can insert times in other timezones. To get around this, I've considered doing this:
- Get the user's timezone and offset
- Add the offset to the time I want to set to
- Add the event with the new time
However, I am currently stuck on step 1. I was able to get the user's timezone by querying for the TimeZoneSidKey, but that doesn't show the offset. I've searched around and seen people make a list of all TimeZoneSidKey and their offsets in a CSV file and get the offsets by searching through that file. But that requires a lot of overhead and I was wondering if there are faster ways to achieve this?
I'd appreciate any ideas on either how to get the offset quickly, or if possible, a straight-forward way to insert an event that'll show up as the intended time in the user's calendar, regardless of the timezone that user is at.
timezone(TimezoneSidKey).utcoffset(mytime)
to get the offset and convert my time to UTC before inserting it.