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

ICS/ICAL sync timezone issue #3

Closed
derekantrican opened this issue Jun 4, 2018 · 16 comments
Closed

ICS/ICAL sync timezone issue #3

derekantrican opened this issue Jun 4, 2018 · 16 comments
Assignees
Labels
bug Something isn't working

Comments

@derekantrican
Copy link
Owner

From Google-Apps-Script-Library created by derekantrican : derekantrican/Google-Apps-Script-Library#6

The following function is having trouble parsing timezones and needs to be improved:

function GetUTCTime(parameter){
  parameter = parameter.substr(1); //Remove leading ; or : character
  if (parameter.includes("TZID")){
    var tzid = parameter.split("TZID=")[1].split(":")[0];
    var time = parameter.split(":")[1];
    return Moment.moment.tz(time,tzid).tz("Etc/UTC").format("YYYYMMDDTHHmmss") + "Z";    
  }
  else
    return parameter;
}

The solution is to use regex to parse out the parts of the string. Here is documentation on how this parameter is formatted: https://www.kanzaki.com/docs/ical/dtstart.html

@derekantrican derekantrican added the bug Something isn't working label Jun 4, 2018
@derekantrican
Copy link
Owner Author

Some regex's: https://regex101.com/r/Nstcrr/3

@arjanvdberg
Copy link

As far as I can see in the documentation you reference, the TZID must be a reference to a VTIMEZONE component. Thus the TZID can be anything, and can't be parsed directly. You probably need to correctly interpret the VTIMEZONE (including daylight saving stuff) to apply the correct offset for a calendar entry.
https://www.kanzaki.com/docs/ical/tzid.html

@derekantrican
Copy link
Owner Author

derekantrican commented Jul 19, 2018

Here is an example of the VTIMEZONE object we need to parse:

BEGIN:VTIMEZONE
TZID:Mountain Standard Time
BEGIN:STANDARD
DTSTART:16010101T020000
TZOFFSETFROM:-0600
TZOFFSETTO:-0700
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T020000
TZOFFSETFROM:-0700
TZOFFSETTO:-0600
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3
END:DAYLIGHT
END:VTIMEZONE

Here's another:

BEGIN:VTIMEZONE
TZID;X-RICAL-TZSOURCE=TZINFO:America/Chicago
BEGIN:DAYLIGHT
DTSTART:20180311T020000
RDATE:20180311T020000
TZOFFSETFROM:-0600
TZOFFSETTO:-0500
TZNAME:CDT
END:DAYLIGHT
END:VTIMEZONE

@jdeluyck
Copy link

I tried out this script, and while it works 'fairly' good for a lot of entries, I have noticed that items which are supposed to be 'full day events' being scheduled form 9AM to 9AM - over two days, which is weird.

My timezone is CEST (Belgium), source feed is coming from Outlook 365.

@derekantrican
Copy link
Owner Author

@jdeluyck Could you please email me all or part of your ICS file? derekantrican@gmail.com

@jdeluyck
Copy link

Sent, together with some comments

@ravem
Copy link

ravem commented Jan 11, 2019

I have a similar problem.

Every appointment/meeting I add to my office 365 calendar is correctly added to Google calendar but the time zone is ignored.
For example I have the attached ICS (where the TZID is W. Europe Standard Time) and the appointment is added to my Google calendar one hour later (I have renamed it as .txt).
prova.ics.txt

In the Stackdriver log of the script execution I have:
severity: "ERROR"
textPayload: "Moment Timezone has no data for W. Europe Standard Time. See http://momentjs.com/timezone/docs/#/data-loading/.
"

I'm no developer, so forgive me if the comment is needless :-D

@derekantrican derekantrican self-assigned this Jan 25, 2019
@IssueHuntBot
Copy link

@marketingthriveworks has funded $300.00 to this issue. See it on IssueHunt

@ravem
Copy link

ravem commented Jan 28, 2019

I have a similar problem.

FYI I solved the problem with a simple and dirty hack.
I did the math between the original start and end time and the one synced
with GC, and I changed on line 320 of Code.gs
return Moment.moment.tz(time,tzid).tz("Etc/UTC").format("YYYYMMDDTHHmmss") + "Z";
that Etc/UTC with a timezone that gives what I expect, in my case Atlantic/Cape_Verde.

@derekantrican
Copy link
Owner Author

Anyone that has been having problems with this (@ravem @marketingthriveworks @jdeluyck ) please make a copy of this script and check to see if the problem is resolved: https://script.google.com/d/1jD1oiON1ID4Cx46b3U_6nxn4Q-SNJ-J_gekVoQ_hLD2VOhGCnL6HzRn6/edit?usp=sharing

@marketingthriveworks
Copy link

TypeError: Cannot read property "id" from undefined. (line 151, file "Code")

@derekantrican
Copy link
Owner Author

derekantrican commented Jan 29, 2019

@marketingthriveworks thanks for catching that. I just fixed it. It's accessible at the same link as before (you can either make a copy again or just copy all of the Code.gs file and replace your current Code.gs file)

@marketingthriveworks
Copy link

marketingthriveworks commented Jan 29, 2019

Issue remains still. I have to change appsscripts.json to my timezone for the calendar appointments to reflect the correct timezone.

"timeZone": "America/New_York",

@derekantrican
Copy link
Owner Author

@marketingthriveworks Please send me a link to the script that you are using derekantrican@gmail.com

@ravem
Copy link

ravem commented Jan 29, 2019

@derekantrican my problem seems to be fixed.
Great work!

@IssueHuntBot
Copy link

@derekantrican has rewarded $270.00 to @derekantrican. See it on IssueHunt

  • 💰 Total deposit: $300.00
  • 🎉 Repository reward(0%): $0.00
  • 🔧 Service fee(10%): $30.00

This was referenced Feb 4, 2019
derekantrican pushed a commit that referenced this issue Oct 16, 2019
Added MD5 Checksum to determine if an event was updated. (Fix #3)
Code cleanup and reorganization.
No longer set iCalUID for new events, id will be saved as extended property
derekantrican pushed a commit that referenced this issue Nov 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants