Homey Community Forum

Local time in HomeyScript

Extract it from “date human”.

Ehhh?

I think your best bet is to use a library like moment, luxon or dayjs.

Thanks! Will do. Not impressed by that design decision from Athom…

Neither am I :roll_eyes:

1 Like
let SysInfo = await Homey.system.getInfo();
//theDay  = SysInfo.dateHuman.slice(0,(SysInfo.dateHuman.indexOf(' ')));
  theHour = SysInfo.dateHuman.slice((SysInfo.dateHuman.length)-8,(SysInfo.dateHuman.length)-6);
//theMin  = SysInfo.dateHuman.slice((SysInfo.dateHuman.length)-5,(SysInfo.dateHuman.length)-3);
//theHour = "08";  // test value
theHour = theHour - 0; // to prevent  08 ,  09  a.s.o.
1 Like

Apart from having to (be allowed to*) use the Web API permission for an app, this method (or any method that tries to parse some sort of string) is fraught with potential issues :frowning:

*: a Slack user’s app was rejected by Athom because they were using the Web API in their app. Maybe that was just a mistake on Athom’s part, or maybe they are clamping down on apps using the Web API, I don’t know.

This is a too high-level language for me. Was it a reaction to my post?

Yes, it was :smiley:

Tried this, but to no avail. What am I missing?

let dateLocal= moment.utc(measurementTimestampUTC).local().toDate()

UTC is the local timezone as far as Homey is concerned.

Perhaps it’s easier to use luxon:

const { DateTime } = require('luxon');

const utc = new DateTime(new Date().toISOString());
console.log(utc.toString());
const local = utc.setZone(this.homey.clock.getTimezone());
console.log(local.toString());
1 Like

Getting :

:x: Script Error
:warning: ReferenceError: require is not defined

Fredrik was looking for a way to fix it in an app. Homeyscript is doomed.

1 Like