I just want to share my experiences with timezone conversion using .toLocaleString( timeZone: tz,…).
This often used to get the curernt local time for logging etc.
This method has a bug at least und HomeyPro19 NodeJS version. I haven’t tested it on HP23 yet.
The error occours if a time is used, when UTC is one day back compared to your local time.
Example:
Time is: 07/03/2023, 22:00 and timezone difference is 2h
Local time sould be: 07/04/2023, 00:00
Then convert into local time string using:
let tz = this.homey.clock.getTimezone();
let now = new Date().toLocaleString('en-US',
{
hour12: false,
timeZone: tz,
hour: "2-digit",
minute: "2-digit",
day: "2-digit",
month: "2-digit",
year: "numeric"
});
Result: 07/04/2023, 24:00 (means: it’s 07/05/2023 0:00)
When converting this string back into a date, you get: 07/05/2023 0:00 (one day ahead)
Example 2:
Time is: 07/03/2023, 22:01 and timezone difference is 2h
Converted with .toLocaleString() you get: 07/04/2023, 24:01 (means: 07/05/2023 0:01)
So better use another date library to convert timezones