From 2744f9b682c0c71f675c830fb66c085e08dbcd21 Mon Sep 17 00:00:00 2001 From: James Chang Date: Fri, 16 Apr 2021 12:00:28 -0400 Subject: [PATCH] If Date Happened is specified for a PB, the local time will be automatically appended to the field on frontend --- frontend/models/personalBest.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/models/personalBest.ts b/frontend/models/personalBest.ts index 5318b52..caa2815 100644 --- a/frontend/models/personalBest.ts +++ b/frontend/models/personalBest.ts @@ -195,7 +195,16 @@ export const PersonalBest = >{ // if falsey, default to current unix timestamp if (!val) return new Date().getTime() / 1000 - const msTimestamp = new Date(val).getTime() + let dateString = val + + // if only date specified, automatically append current time + if (dateString.match(/^\d{4}-\d{2}-\d{2}$/)) { + const currentDate = new Date() + + dateString += ` ${currentDate.getHours()}:${currentDate.getMinutes()}:${currentDate.getSeconds()}` + } + + const msTimestamp = new Date(dateString).getTime() // date cannot be to far in the future if (msTimestamp > new Date().getTime() + 1000 * 60 * 60 * 24) { throw new Error(`Date Happened cannot be in the future`)