repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by admin
quickshell/nuguland/features/clock/fixtures/services/Time.qml
Rawimport QtQuick
Item {
id: root
// Time double: the production API the clock's bar control and panel read, at
// the fixture's start time; no ticking, so the bar label and panel stay still.
property date now: new Date()
// Set by the registry on opening and dismissal; the load proof reads it.
property bool secondsShown: false
readonly property string compact: formatClock(now).display
// English and lowercase on every host locale, like every shell label.
readonly property var weekdays: ["sun", "mon", "tue", "wed", "thu", "fri", "sat"]
readonly property var monthNames: ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"]
function pad(value) {
return value < 10 ? `0${value}` : `${value}`;
}
function isoDay(value) {
return `${value.getFullYear()}-${pad(value.getMonth() + 1)}-${pad(value.getDate())}`;
}
function formatClock(value) {
const display = `${pad(value.getHours())}:${pad(value.getMinutes())}`;
return {
"display": display,
"statusDisplay": `${display}:${pad(value.getSeconds())}`
};
}
function formatDate(value) {
return {
"line": `${weekdays[value.getDay()]} ${value.getDate()} ${monthNames[value.getMonth()]}`
};
}
// Monday-first six-week grid with the fields the panel reads, as production.
function monthGrid(year, month, selectedDay) {
const first = new Date(year, month - 1, 1);
const cursor = new Date(year, month - 1, 1 - (first.getDay() + 6) % 7);
const todayIso = `${year}-${pad(month)}-${pad(selectedDay)}`;
const weeks = [];
for (let week = 0; week < 6; week++) {
const days = [];
for (let day = 0; day < 7; day++) {
days.push({
"iso": isoDay(cursor),
"day": cursor.getDate(),
"inMonth": cursor.getMonth() === month - 1,
"today": isoDay(cursor) === todayIso
});
cursor.setDate(cursor.getDate() + 1);
}
weeks.push(days);
}
return {
"weeks": weeks
};
}
}