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 }) {