Timer: Make sure calculated schedule is in a valid range
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user