From 8a2eeb6c31b64427fe08e695bdbfcce14f53fbdf Mon Sep 17 00:00:00 2001 From: zach Date: Sun, 3 May 2026 17:30:10 +0200 Subject: [PATCH] add support for custom date formats via config --- Config/Config.qml | 1 + Config/General.qml | 1 + Helpers/Time.qml | 9 ++++++-- Modules/Clock.qml | 2 +- Modules/Settings/Categories/General.qml | 9 ++++++++ Modules/Settings/SettingsIndex.mjs | 7 ++++++ Modules/Time.qml | 30 ------------------------- 7 files changed, 26 insertions(+), 33 deletions(-) delete mode 100644 Modules/Time.qml diff --git a/Config/Config.qml b/Config/Config.qml index 295b8e5..1697c6f 100644 --- a/Config/Config.qml +++ b/Config/Config.qml @@ -180,6 +180,7 @@ Singleton { logo: general.logo, wallpaperPath: general.wallpaperPath, desktopIcons: general.desktopIcons, + dateFormat: general.dateFormat, color: { mode: general.color.mode, smart: general.color.smart, diff --git a/Config/General.qml b/Config/General.qml index a823f6d..a0a2a2c 100644 --- a/Config/General.qml +++ b/Config/General.qml @@ -6,6 +6,7 @@ JsonObject { } property Color color: Color { } + property string dateFormat: "ddd d MMM - hh:mm:ss" property bool desktopIcons: false property Idle idle: Idle { } diff --git a/Helpers/Time.qml b/Helpers/Time.qml index f9ef387..f7d75f1 100644 --- a/Helpers/Time.qml +++ b/Helpers/Time.qml @@ -1,18 +1,23 @@ pragma Singleton import Quickshell +import QtQuick +import qs.Config Singleton { - readonly property string amPmStr: timeComponents[2] ?? "" + id: root + readonly property date date: clock.date + readonly property string dateStr: format(Config.general.dateFormat) property alias enabled: clock.enabled readonly property string hourStr: timeComponents[0] ?? "" readonly property int hours: clock.hours readonly property string minuteStr: timeComponents[1] ?? "" readonly property int minutes: clock.minutes + readonly property string secondStr: timeComponents[2] ?? "" readonly property int seconds: clock.seconds readonly property list timeComponents: timeStr.split(":") - readonly property string timeStr: format("hh:mm") + readonly property string timeStr: format("hh:mm:ss") function format(fmt: string): string { return Qt.formatDateTime(clock.date, fmt); diff --git a/Modules/Clock.qml b/Modules/Clock.qml index c81f504..26da1f8 100644 --- a/Modules/Clock.qml +++ b/Modules/Clock.qml @@ -3,7 +3,7 @@ import QtQuick import QtQuick.Layouts import qs.Config import qs.Modules -import qs.Helpers as Helpers +import qs.Helpers import qs.Components CustomRect { diff --git a/Modules/Settings/Categories/General.qml b/Modules/Settings/Categories/General.qml index c2703ed..4fe7d58 100644 --- a/Modules/Settings/Categories/General.qml +++ b/Modules/Settings/Categories/General.qml @@ -47,6 +47,15 @@ SettingsPage { object: Config.general setting: "desktopIcons" } + + Separator { + } + + SettingInput { + name: "Date format" + object: Config.general + setting: "dateFormat" + } } SettingsSection { diff --git a/Modules/Settings/SettingsIndex.mjs b/Modules/Settings/SettingsIndex.mjs index f3afffb..0f5f75f 100644 --- a/Modules/Settings/SettingsIndex.mjs +++ b/Modules/Settings/SettingsIndex.mjs @@ -30,6 +30,13 @@ export const settingsIndex = [ section: "General", keywords: ["icons", "desktop", "show"], }, + { + name: "Date format", + category: "general", + categoryName: "General", + section: "General", + keywords: ["date", "time", "format"], + }, // Color section { name: "Scheme mode", diff --git a/Modules/Time.qml b/Modules/Time.qml deleted file mode 100644 index 542f13f..0000000 --- a/Modules/Time.qml +++ /dev/null @@ -1,30 +0,0 @@ -pragma Singleton - -import Quickshell -import QtQuick - -Singleton { - id: root - - readonly property date date: clock.date - readonly property string dateStr: format("ddd d MMM - hh:mm:ss") - property alias enabled: clock.enabled - readonly property string hourStr: timeComponents[0] ?? "" - readonly property int hours: clock.hours - readonly property string minuteStr: timeComponents[1] ?? "" - readonly property int minutes: clock.minutes - readonly property string secondStr: timeComponents[2] ?? "" - readonly property int seconds: clock.seconds - readonly property list timeComponents: timeStr.split(":") - readonly property string timeStr: format("hh:mm:ss") - - function format(fmt: string): string { - return Qt.formatDateTime(clock.date, fmt); - } - - SystemClock { - id: clock - - precision: SystemClock.Seconds - } -}