From a00ff45ccfe00b5c798c917fbc3ff6ef60ee0a2e Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 22 Feb 2023 15:06:52 +0100 Subject: [PATCH] UX nits --- frontend/src/lib/utils.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/utils.ts b/frontend/src/lib/utils.ts index d48ae66d50..690d1c7efb 100644 --- a/frontend/src/lib/utils.ts +++ b/frontend/src/lib/utils.ts @@ -39,7 +39,7 @@ export function daysAgo(someDate: Date): number { } export function secondsAgo(date: Date) { - return Math.floor((new Date().getTime() - date.getTime()) / 1000) + return Math.max(0, Math.floor((new Date().getTime() - date.getTime()) / 1000)) } export function displayDaysAgo(dateString: string): string { @@ -255,8 +255,13 @@ export function allTrue(dict: { [id: string]: boolean }): boolean { return Object.values(dict).every(Boolean) } +function subtractSeconds(date: Date, seconds: number): Date { + date.setSeconds(date.getSeconds() - seconds); + return date; +} + export function forLater(scheduledString: string): boolean { - return new Date() < new Date(scheduledString) + return new Date() < subtractSeconds(new Date(scheduledString), 5) } export function elapsedSinceSecs(date: string): number {