From fdc3b0c0b6e1534a5744667fbb0c66e089a7465c Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Tue, 18 Jun 2024 16:52:18 -0500 Subject: [PATCH] Use non-string comparison --- src/lib/strings/time.ts | 11 +++++++++++ src/state/shell/reminders.ts | 9 ++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/lib/strings/time.ts b/src/lib/strings/time.ts index 6d71005dc8..fde66e8eb0 100644 --- a/src/lib/strings/time.ts +++ b/src/lib/strings/time.ts @@ -27,3 +27,14 @@ export function toSimpleDateString(date: Date | string): string { const _date = typeof date === 'string' ? new Date(date) : date return _date.toISOString().split('T')[0] } + +/** + * Compares two dates by year, month, and day only + */ +export function simpleAreDatesEqual(a: Date, b: Date): boolean { + return ( + a.getFullYear() === b.getFullYear() && + a.getMonth() === b.getMonth() && + a.getDate() === b.getDate() + ) +} diff --git a/src/state/shell/reminders.ts b/src/state/shell/reminders.ts index 06edff25a3..93ce06c526 100644 --- a/src/state/shell/reminders.ts +++ b/src/state/shell/reminders.ts @@ -1,4 +1,4 @@ -import {toSimpleDateString} from '#/lib/strings/time' +import {simpleAreDatesEqual} from '#/lib/strings/time' import {logger} from '#/logger' import * as persisted from '#/state/persisted' import {SessionAccount} from '../session' @@ -12,9 +12,8 @@ export function shouldRequestEmailConfirmation(account: SessionAccount) { // wait for onboarding to complete if (isOnboardingActive()) return false - const stored = persisted.get('reminders').lastEmailConfirm - const snoozedAt = stored ? toSimpleDateString(new Date(stored)) : undefined - const today = toSimpleDateString(new Date()) + const snoozedAt = persisted.get('reminders').lastEmailConfirm + const today = new Date() logger.debug('Checking email confirmation reminder', { today, @@ -28,7 +27,7 @@ export function shouldRequestEmailConfirmation(account: SessionAccount) { } // already snoozed today - if (snoozedAt === today) { + if (simpleAreDatesEqual(new Date(snoozedAt), new Date())) { return false }