Make clock's alt format include the ISO week number
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.
This commit is contained in:
@@ -9,10 +9,31 @@ BarWidget {
|
|||||||
|
|
||||||
property bool alt: false
|
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() {
|
function label() {
|
||||||
if (alt) return Qt.formatDateTime(clock.date, String(setting("formatAlt", "dd MMMM 'W'ww yyyy")))
|
if (alt) return format(clock.date, setting("formatAlt", "dd MMMM 'W'ww yyyy"))
|
||||||
if (bar && bar.vertical) return Qt.formatDateTime(clock.date, String(setting("verticalFormat", "HH\n—\nmm")))
|
if (bar && bar.vertical) return format(clock.date, setting("verticalFormat", "HH\n—\nmm"))
|
||||||
return Qt.formatDateTime(clock.date, String(setting("format", "dddd HH:mm")))
|
return format(clock.date, setting("format", "dddd HH:mm"))
|
||||||
}
|
}
|
||||||
|
|
||||||
implicitWidth: button.implicitWidth
|
implicitWidth: button.implicitWidth
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ Item {
|
|||||||
layout: {
|
layout: {
|
||||||
left: [{ id: "omarchy" }, { id: "workspaces" }],
|
left: [{ id: "omarchy" }, { id: "workspaces" }],
|
||||||
center: [
|
center: [
|
||||||
{ id: "clock", format: "dddd HH:mm", formatAlt: "dd MMMM yyyy", verticalFormat: "HH\n\u2014\nmm" },
|
{ id: "clock", format: "dddd HH:mm", formatAlt: "dd MMMM 'W'ww yyyy", verticalFormat: "HH\n\u2014\nmm" },
|
||||||
{ id: "weather" }, { id: "indicators", items: [ "dnd", "nightlight", "stayAwake", "screenrecording", "dictation" ] }, { id: "systemUpdate" }
|
{ id: "weather" }, { id: "indicators", items: [ "dnd", "nightlight", "stayAwake", "screenrecording", "dictation" ] }, { id: "systemUpdate" }
|
||||||
],
|
],
|
||||||
right: [
|
right: [
|
||||||
@@ -1205,7 +1205,7 @@ Item {
|
|||||||
}
|
}
|
||||||
ClockField {
|
ClockField {
|
||||||
fieldKey: "formatAlt"
|
fieldKey: "formatAlt"
|
||||||
text: clockForm.entry.formatAlt || "dd MMMM yyyy"
|
text: clockForm.entry.formatAlt || "dd MMMM 'W'ww yyyy"
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
{
|
{
|
||||||
"id": "clock",
|
"id": "clock",
|
||||||
"format": "dddd HH:mm",
|
"format": "dddd HH:mm",
|
||||||
"formatAlt": "dd MMMM yyyy",
|
"formatAlt": "dd MMMM 'W'ww yyyy",
|
||||||
"verticalFormat": "HH\n\u2014\nmm"
|
"verticalFormat": "HH\n\u2014\nmm"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user