Convert Seconds to date format

Hello everyone, I have a request for you :

I have a value, exemple value = 60000, which is the uptime in second of a device. This value is a child parameter.
I want to view this value into a regular date format (HH:MM:SS).
I want to know if you have fonctions or methods to do it.

And can you tell me if all the display config is in YAML please.

Thank you in advance for your replies.

You don’t mention what version of GenieACS you are using. In v1.0 and v1.1 (not sure about v1.2 as we haven’t migrated yet) there is support. In v1.0 and v1.1 look in the gui/config/parameter_renders.yml file. You will see a mapping between parameters and parameter renderers. You can even write your own by in ruby storing them in gui/config/parameter_renderers.

Example from my environment:

InternetGatewayDevice.DeviceInfo.UpTime: duration
Device.DeviceInfo.UpTime: duration
VirtualParameters.UpTime: duration
VirtualParameters.pppoeUsername: username_link
_deviceId._SerialNumber: serial_number_link
_tags: tags
_lastBoot: date_local

The two renderers username_link and serial_number_link are custom ones I’ve written.

Thanks for your reply.

I use the last version : the 1.2 beta, so do you know if this version keeps the files you mentioned ?

There’s the function DATE_STRING() but that renders a datetime, not a duration. Maybe create a custom component to render a numeric parameter in that format? See ui/components/parameter.ts for an example component.

I do this via a virtual parameter. For example I convert UpTime to a format DDd hh:mm:ss with a Virtual Parameter called UpTimeDHMS.

There may be more efficient ways to write the code, my aim is for simplicity and clarity.

// Unified across Device and InternetGatewayDevice
let v1 = declare("Device.DeviceInfo.UpTime", {value: Date.now()});
let v2 = declare("InternetGatewayDevice.DeviceInfo.UpTime", {value: Date.now()});
let totalSecs = 0
if (typeof v1.value !== "undefined") {
  totalSecs = v1.value[0];
} else {
  totalSecs = v2.value[0];
}
let days = Math.floor(totalSecs / 86400);
let rem  = totalSecs % 86400;
let hrs  = Math.floor(rem / 3600);
if (hrs < 10) {
	hrs = "0" + hrs;
}

rem  = rem % 3600;
let mins = Math.floor(rem / 60);
if (mins < 10) {
	mins = "0" + mins;
}
let secs = rem % 60;
if (secs < 10) {
	secs = "0" + secs;
}

let uptime = days + "d " + hrs + ":" + mins + ":" + secs;
return {writable: false, value: uptime};

This is how it renders:

1 Like

Hello,

Thank you for your reply and your solution. This is exactly what I am looking for ^^