From 44474a39200efb8f1b832575a1f66d9eaeabb414 Mon Sep 17 00:00:00 2001 From: Thorben Grove Date: Mon, 11 Dec 2023 22:16:37 +0100 Subject: [PATCH] Enhancement: fritzbox uptime display --- src/widgets/fritzbox/component.jsx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/widgets/fritzbox/component.jsx b/src/widgets/fritzbox/component.jsx index 7c32f617..2e12c235 100644 --- a/src/widgets/fritzbox/component.jsx +++ b/src/widgets/fritzbox/component.jsx @@ -7,15 +7,25 @@ import useWidgetAPI from "utils/proxy/use-widget-api"; export const fritzboxDefaultFields = ["connectionStatus", "uptime", "maxDown", "maxUp"]; const formatUptime = (timestamp) => { - const hours = Math.floor(timestamp / 3600); + const days = Math.floor(timestamp / (3600 * 24)); + const hours = Math.floor((timestamp % (3600 * 24)) / 3600); const minutes = Math.floor((timestamp % 3600) / 60); const seconds = timestamp % 60; + const format = (num) => String(num).padStart(2, "0"); - const hourDuration = hours > 0 ? `${hours}h` : "00h"; - const minDuration = minutes > 0 ? `${minutes}m` : "00m"; - const secDuration = seconds > 0 ? `${seconds}s` : "00s"; + let uptimeStr = ""; + if (days) { + uptimeStr += `${days}d`; + } + if (hours || days) { + uptimeStr += `${format(hours)}h`; + } + uptimeStr += `${format(minutes)}m`; + if (!days) { + uptimeStr += `${format(seconds)}s `; + } - return hourDuration + minDuration + secDuration; + return uptimeStr; }; export default function Component({ service }) {