refactor time duration formatting

This commit is contained in:
end-4
2026-03-08 18:09:34 +01:00
parent 3da23ce176
commit 83baff7894
3 changed files with 22 additions and 32 deletions
@@ -2,6 +2,7 @@ pragma Singleton
pragma ComponentBehavior: Bound
import qs
import qs.modules.common
import qs.modules.common.functions
import QtQuick
import Quickshell
import Quickshell.Io
@@ -10,6 +11,7 @@ import Quickshell.Io
* A nice wrapper for date and time strings.
*/
Singleton {
id: root
property var clock: SystemClock {
id: clock
precision: {
@@ -33,21 +35,7 @@ Singleton {
fileUptime.reload();
const textUptime = fileUptime.text();
const uptimeSeconds = Number(textUptime.split(" ")[0] ?? 0);
// Convert seconds to days, hours, and minutes
const days = Math.floor(uptimeSeconds / 86400);
const hours = Math.floor((uptimeSeconds % 86400) / 3600);
const minutes = Math.floor((uptimeSeconds % 3600) / 60);
// Build the formatted uptime string
let formatted = "";
if (days > 0)
formatted += `${days}d`;
if (hours > 0)
formatted += `${formatted ? ", " : ""}${hours}h`;
if (minutes > 0 || !formatted)
formatted += `${formatted ? ", " : ""}${minutes}m`;
uptime = formatted;
root.uptime = DateUtils.formatDuration(uptimeSeconds)
interval = Config.options?.resources?.updateInterval ?? 3000;
}
}