Set the default formatAlt to "dd MMMM 'W'ww yyyy" (was "dd MMMM yyyy") in shell-defaults.json, the bundled settings-panel defaults, and the form placeholder text — clock's own widget fallback already used this spec but the shipped config overrode it. Qt.formatDateTime doesn't recognize `ww` and renders it literally (`20 May Www 2026`), so add an `isoWeek` helper to clock.qml that pre-substitutes `ww` with a Qt-quoted literal of the ISO 8601 week number before handing the format off to Qt. Users get `20 May W21 2026` without anyone needing to know about the substitution.
61 lines
1.7 KiB
QML
61 lines
1.7 KiB
QML
import QtQuick
|
|
import Quickshell
|
|
import qs.Commons
|
|
import qs.Ui
|
|
|
|
BarWidget {
|
|
id: root
|
|
moduleName: "clock"
|
|
|
|
property bool alt: false
|
|
|
|
// Qt.formatDateTime doesn't recognize `ww` (ISO week number). Pre-substitute
|
|
// it as a Qt-quoted literal before formatting so users can write the natural
|
|
// `'W'ww yyyy` and get `W21 2026` rather than `Www 2026`.
|
|
function isoWeek(date) {
|
|
var d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()))
|
|
var day = d.getUTCDay() || 7
|
|
d.setUTCDate(d.getUTCDate() + 4 - day)
|
|
var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1))
|
|
return Math.ceil(((d - yearStart) / 86400000 + 1) / 7)
|
|
}
|
|
|
|
function format(date, fmt) {
|
|
var f = String(fmt || "")
|
|
if (f.indexOf("ww") !== -1) {
|
|
var w = isoWeek(date)
|
|
var ww = w < 10 ? "0" + w : String(w)
|
|
f = f.replace(/ww/g, "'" + ww + "'")
|
|
}
|
|
return Qt.formatDateTime(date, f)
|
|
}
|
|
|
|
function label() {
|
|
if (alt) return format(clock.date, setting("formatAlt", "dd MMMM 'W'ww yyyy"))
|
|
if (bar && bar.vertical) return format(clock.date, setting("verticalFormat", "HH\n—\nmm"))
|
|
return format(clock.date, setting("format", "dddd HH:mm"))
|
|
}
|
|
|
|
implicitWidth: button.implicitWidth
|
|
implicitHeight: button.implicitHeight
|
|
|
|
SystemClock {
|
|
id: clock
|
|
precision: SystemClock.Minutes
|
|
}
|
|
|
|
WidgetButton {
|
|
id: button
|
|
anchors.fill: parent
|
|
bar: root.bar
|
|
text: root.label()
|
|
horizontalMargin: 8.75
|
|
verticalPadding: 8.75
|
|
onPressed: function(button) {
|
|
if (!root.bar) return
|
|
if (button === Qt.RightButton) root.bar.run("omarchy-launch-floating-terminal-with-presentation omarchy-tz-select")
|
|
else root.alt = !root.alt
|
|
}
|
|
}
|
|
}
|