qistoph/MMM-MyCommute

Calendar events are not being added if you specify transit

Closed this issue · 8 comments

Calendar events are not being added because the arrival time passed to the google API is the timestamp in miliseconds. (example: arrival_time=1584806232000)

When doing the request with the epoch timestamp which does not include miliseconds the request succeeds (example: arrival_time=1584806232)

Google dev guide states:

arrival_time — Specifies the desired time of arrival for transit directions, in seconds since midnight, January 1, 1970 UTC. You can specify either departure_time or arrival_time, but not both. Note that arrival_time must be specified as an integer.

I've fixed this by deviding calendar event times by 1000
arrival_time: calendarEvent.startDate/1000

Unclear if it breaks anything else by doing so, will post if so.

Extra info, it will only fail if you have specified "transit" as one of the options to check.
Car, walking, bike work if call submits arrival time in miliseconds

Also added "color: calendarEvent.color" in code because later on it will crash because color wasn't added for these events.

this.config.calendarOptions.map( calOpt => Object.assign({}, calOpt, {
label: calendarEvent.title,
destination: calendarEvent.location,
arrival_time: calendarEvent.startDate/1000,
color: calendarEvent.color
}))

Are other options like driving works with the epoch time? If yes I think this is a good workaround.

They don't appear to have issues with either the miliseconds or epoch times...
Might be worth looking into

I have tried it, it works as it should with your changes also. Basically I don't use alternatives and transit on calendar events (just driving) that's why it didn't happened...

Thanks for the suggestions. I'm going to add these to the code base and test it for a while.

I've tested, confirmed and fixed the arrival_time: calendarEvent.startDate/1000.

The color didn't seem to be an issue here. However, since your addition won't do any harm and is actually a nice improvement (matching colors). I'm adding that too.

Pushed to branch test. Feel free to try it and provide any feedback here or in a new issue if applicable.