Skip to content

Commit 95d569b

Browse files
authored
Fix a Daylight Saving Time bug that caused the displayed time for an upcoming alarm the day after a clock change to be off by an hour. (#87)
1 parent a3a247d commit 95d569b

8 files changed

Lines changed: 86 additions & 75 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.4.1
2+
3+
* Fix a Daylight Saving Time bug that caused the displayed time for an upcoming alarm the day after a clock change to be off by an hour. (This self-corrected after midnight, and did not affect when the alarm actually went off.)
4+
15
## 3.4.0
26

37
* Use local storage instead of cookies to save user settings.

package-lock.json

Lines changed: 39 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aw-clock",
3-
"version": "3.4.0",
3+
"version": "3.4.1",
44
"license": "MIT",
55
"author": "Kerry Shetline <kerry@shetline.com>",
66
"scripts": {
@@ -18,9 +18,9 @@
1818
},
1919
"private": true,
2020
"dependencies": {
21-
"@tubular/astronomy": "^3.3.2",
22-
"@tubular/math": "^3.1.0",
23-
"@tubular/time": "^3.8.7",
21+
"@tubular/astronomy": "^3.5.0",
22+
"@tubular/math": "^3.3.1",
23+
"@tubular/time": "^3.8.8",
2424
"@tubular/util": "^4.13.1",
2525
"compare-versions": "^4.1.3",
2626
"jquery": "^3.6.0",

sass/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sass/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aw-clock-sass",
3-
"version": "3.4.0",
3+
"version": "3.4.1",
44
"description": "SASS builder for aw-clock",
55
"keywords": [
66
"sass"

server/package-lock.json

Lines changed: 26 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aw-clock-server",
3-
"version": "3.4.0",
3+
"version": "3.4.1",
44
"license": "MIT",
55
"author": "Kerry Shetline <kerry@shetline.com>",
66
"private": true,
@@ -16,8 +16,8 @@
1616
"build-win": "webpack"
1717
},
1818
"dependencies": {
19-
"@tubular/math": "^3.1.0",
20-
"@tubular/time": "^3.8.7",
19+
"@tubular/math": "^3.3.1",
20+
"@tubular/time": "^3.8.8",
2121
"@tubular/util": "^4.13.1",
2222
"by-request": "^1.3.3",
2323
"compare-versions": "^4.1.3",

src/alarm-monitor.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { domAlert } from './awc-util';
88
import { TimeFormat } from './shared-types';
99

1010
const FALLBACK_AUDIO = 'Beep-beep-beep-beep.mp3';
11-
const MINUTES_PER_DAY = 1440;
1211
const NOTHING_PENDING = Number.MAX_SAFE_INTEGER;
1312

1413
export class AlarmMonitor {
@@ -56,6 +55,9 @@ export class AlarmMonitor {
5655
checkAlarms(alarmCheckTime: number, alarms: AlarmInfo[]): AlarmInfo[] {
5756
let updatePrefs = false;
5857
const now = new DateTime(alarmCheckTime, this.appService.timezone);
58+
const minutesInDay = now.getMinutesInDay();
59+
const wt = now.wallTime;
60+
const midnight = new DateTime([wt.y, wt.m, wt.d, 0, 0, 0], this.appService.timezone);
5961
const nowMinutes = floor(now.utcSeconds / 60);
6062
const newActiveAlarms = [];
6163
let sound = '';
@@ -77,8 +79,7 @@ export class AlarmMonitor {
7779
if (snoozed)
7880
alarmTime = snoozed.restartAt;
7981
else if (isDaily)
80-
alarmTime = floor(new DateTime([now.wallTime.y, now.wallTime.m, now.wallTime.d], this.appService.timezone).utcSeconds / 60) +
81-
alarmTime;
82+
alarmTime = floor(midnight.utcSeconds / 60) + alarmTime;
8283
else
8384
alarmTime -= floor(now.utcOffsetSeconds / 60);
8485

@@ -94,16 +95,16 @@ export class AlarmMonitor {
9495
const tomorrow = now.clone().add('day', 1).format('dd', 'en').toUpperCase();
9596

9697
if (alarm.days?.includes(tomorrow) && alarmTime < nowMinutes)
97-
next24Hours = min(alarmTime + MINUTES_PER_DAY, next24Hours);
98+
next24Hours = min(alarmTime + minutesInDay, next24Hours);
9899

99100
const today = now.format('dd', 'en').toUpperCase();
100101

101102
if (!alarm.days?.includes(today))
102103
continue;
103-
else if (alarmTime > nowMinutes && alarmTime < nowMinutes + MINUTES_PER_DAY)
104+
else if (alarmTime > nowMinutes && alarmTime < nowMinutes + minutesInDay)
104105
next24Hours = min(alarmTime, next24Hours);
105106
}
106-
else if (alarmTime > nowMinutes && alarmTime < nowMinutes + MINUTES_PER_DAY)
107+
else if (alarmTime > nowMinutes && alarmTime < nowMinutes + minutesInDay)
107108
next24Hours = min(alarmTime, next24Hours);
108109
}
109110

0 commit comments

Comments
 (0)