forked from Shinonome/dots-hyprland
night light: fix evaluation in midnight
This commit is contained in:
@@ -30,15 +30,6 @@ Singleton {
|
|||||||
property int clockMinute: DateTime.clock.minutes
|
property int clockMinute: DateTime.clock.minutes
|
||||||
|
|
||||||
|
|
||||||
function isNoLater(hour1, minute1, hour2, minute2) {
|
|
||||||
if (hour1 < hour2)
|
|
||||||
return true;
|
|
||||||
if (hour1 === hour2 && minute1 < minute2)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
onClockMinuteChanged: reEvaluate()
|
onClockMinuteChanged: reEvaluate()
|
||||||
onAutomaticChanged: {
|
onAutomaticChanged: {
|
||||||
root.manualActive = undefined;
|
root.manualActive = undefined;
|
||||||
@@ -46,10 +37,16 @@ Singleton {
|
|||||||
reEvaluate();
|
reEvaluate();
|
||||||
}
|
}
|
||||||
function reEvaluate() {
|
function reEvaluate() {
|
||||||
const toHourIsNextDay = !isNoLater(fromHour, fromMinute, toHour, toMinute);
|
const t = clockHour * 60 + clockMinute;
|
||||||
const toHourWrapped = toHourIsNextDay ? toHour + 24 : toHour;
|
const from = fromHour * 60 + fromMinute;
|
||||||
const toMinuteWrapped = toMinute;
|
const to = toHour * 60 + toMinute;
|
||||||
root.shouldBeOn = isNoLater(fromHour, fromMinute, clockHour, clockMinute) && isNoLater(clockHour, clockMinute, toHourWrapped, toMinuteWrapped);
|
|
||||||
|
if (from < to) {
|
||||||
|
root.shouldBeOn = t >= from && t <= to;
|
||||||
|
} else {
|
||||||
|
// Wrapped around midnight
|
||||||
|
root.shouldBeOn = t >= from || t <= to;
|
||||||
|
}
|
||||||
if (firstEvaluation) {
|
if (firstEvaluation) {
|
||||||
firstEvaluation = false;
|
firstEvaluation = false;
|
||||||
root.ensureState();
|
root.ensureState();
|
||||||
|
|||||||
Reference in New Issue
Block a user