Timer: Make sure calculated schedule is in a valid range

This commit is contained in:
Romain Vigier
2022-11-05 10:33:37 +01:00
parent 6cd5507143
commit d91a280b14
2 changed files with 7 additions and 2 deletions
@@ -72,15 +72,18 @@ SPDX-License-Identifier: GPL-3.0-or-later
<default>false</default>
</key>
<key name="sunrise" type="d">
<range min="0" max="24"/>
<default>6</default>
</key>
<key name="sunset" type="d">
<range min="0" max="24"/>
<default>20</default>
</key>
<key name="location" type="(dd)">
<default>(91,181)</default>
</key>
<key name="offset" type="d">
<range min="0" max="24"/>
<default>0.4</default>
</key>
</schema>
+4 -2
View File
@@ -350,9 +350,11 @@ var Timer = class extends GObject.Object {
const timeSunrise = solarNoon - haSunrise * 4 / 1440;
const timeSunset = solarNoon + haSunrise * 4 / 1440;
const modulo = (n, m) => ((n % m) + m) % m;
const offset = this.#settings.get_double('offset');
const sunrise = timeSunrise * 24 + offset;
const sunset = timeSunset * 24 - offset;
const sunrise = modulo(timeSunrise * 24 + offset, 24);
const sunset = modulo(timeSunset * 24 - offset, 24);
this.#settings.set_double('sunrise', sunrise);
this.#settings.set_double('sunset', sunset);