waffles: more continuous infinite scrolling calendar

This commit is contained in:
end-4
2025-11-26 22:57:40 +01:00
parent a786f0353e
commit d27fbede2a
10 changed files with 354 additions and 129 deletions
@@ -0,0 +1,38 @@
pragma Singleton
import Quickshell
Singleton {
id: root
function getMonday(date, american = false) {
const d = new Date(date); // Copy
const day = d.getDay(); // 0 = Sunday, 1 = Monday, ..., 6 = Saturday
// Calculate difference to Monday
if (american) {
// Week starts on Sunday
d.setDate(d.getDate() - day);
} else {
// Week starts on Monday
const diff = day === 0 ? -6 : 1 - day;
d.setDate(d.getDate() + diff);
}
return d;
}
function sameDate(d1, d2) {
return (
d1.getFullYear() === d2.getFullYear() &&
d1.getMonth() === d2.getMonth() &&
d1.getDate() === d2.getDate()
);
}
function getIthDayDateOfSameWeek(date, i, american = false) {
const monday = root.getMonday(date, american);
const targetDate = new Date(monday);
targetDate.setDate(monday.getDate() + i);
return targetDate;
}
}