From e84e816b56a1ad942c8e30c76f3df952459e631d Mon Sep 17 00:00:00 2001 From: Jack Greenlee Date: Tue, 20 Feb 2024 13:02:04 -0500 Subject: [PATCH] fix crash on updatePrefReminderTime `newTime` here is not an ISO string; it is a JavaScript Date object. Attempting to parse it as an ISO string results in "Invalid DateTime" being stored to the user prefs and a crash on the Profile screen --- www/js/control/ProfileSettings.tsx | 4 ++-- www/js/splash/notifScheduler.ts | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/www/js/control/ProfileSettings.tsx b/www/js/control/ProfileSettings.tsx index 0c6101c48..4a33a6a68 100644 --- a/www/js/control/ProfileSettings.tsx +++ b/www/js/control/ProfileSettings.tsx @@ -297,10 +297,10 @@ const ProfileSettings = () => { if (!uiConfig?.reminderSchemes) return logWarn('In updatePrefReminderTime, no reminderSchemes yet, skipping'); if (storeNewVal) { - const m = DateTime.fromISO(newTime); + const dt = DateTime.fromJSDate(newTime); // store in HH:mm setReminderPrefs( - { reminder_time_of_day: m.toFormat('HH:mm') }, + { reminder_time_of_day: dt.toFormat('HH:mm') }, uiConfig.reminderSchemes, isScheduling, setIsScheduling, diff --git a/www/js/splash/notifScheduler.ts b/www/js/splash/notifScheduler.ts index b059aa3cd..00f24571d 100644 --- a/www/js/splash/notifScheduler.ts +++ b/www/js/splash/notifScheduler.ts @@ -24,7 +24,11 @@ const calcNotifTimes = (scheme, dayZeroDate, timeOfDay): DateTime[] => { .plus({ days: d }) .toFormat('yyyy-MM-dd'); const notifTime = DateTime.fromFormat(date + ' ' + timeOfDay, 'yyyy-MM-dd HH:mm'); - notifTimes.push(notifTime); + if (notifTime.isValid) { + notifTimes.push(notifTime); + } else { + displayErrorMsg('Cannot schedule notifs with invalid time of day: ' + timeOfDay); + } } } return notifTimes;