qistoph / MMM-MyCommute

This a module for the MagicMirror. It shows your commute time using Google's Traffic API
39 stars 14 forks source link

Calendar events are not being added if you specify transit #12

Closed testdruif closed 4 years ago

testdruif commented 4 years ago

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.

testdruif commented 4 years ago

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

testdruif commented 4 years ago

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 }))

radokristof commented 4 years ago

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

testdruif commented 4 years ago

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

radokristof commented 4 years ago

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...

qistoph commented 4 years ago

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

qistoph commented 4 years ago

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.

qistoph commented 4 years ago

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