SDK3 and timezone from calendar events

As of SDK3, Athom has changed Homey to always work in UTC timezone… :man_facepalming:

I am trying to move my app IcalCalendar from SDK2 to SDK3, but this change in timezone behavior has made it quite problematic.

In SDK2 the calendars were read and start / end were correctly converted to date objects with correct timezone offset.

In SDK3 the calendars are read but start / end are converted to date objects with UTC, and are missing timezone offsets.

I can use moment with the timezone found in Homey (this.homey.clock.getTimezone()) to get the offsets back, however i don’t seem to have found the correct way to add the offsets to the date to get correct start / end.

Has anyone has any luck achieving this correctly?

The code is here if someone would like to take a look: calendar-homey/get-active-events.js at sdk3 · runely/calendar-homey · GitHub

Yes, just because Athom cannot handle timezones all developers have to suffer :grimacing:

I’m not sure I understand.

You can use moment-timezone to convert a UTC timestamp to a local one:

const moment = require('moment-timezone');

const d1 = new Date();
console.log('Date', d1.toString(), 'Offset', d1.getTimezoneOffset());

const d2 =, 'Europe/Amsterdam');
console.log('Date', d2.toString(), 'Offset', d2.utcOffset());

If that’s not what you need, what exactly is it you do need? The code you’re linking to contains too much context to understand the underlying issue you’re having :sweat_smile:

By the way, you can run the above code locally with Node.js, which saves some time with the whole make-a-minor-change-and-upload-your-entire-app cycle for Homey. To set the timezone to UTC, just like with SDKv3, you can use the TZ environment variable (at least on Linux and macOS):

$ env TZ=UTC node test.js

I was already using moment-timezone to convert the date to local, but hadn’t found the correct way to add the offset. With your suggestion to set my local TZ to UTC it helped quite a lot and sped up the process, so thank you!

1 Like