Skip to content

Commit

Permalink
If Date Happened is specified for a PB, the local time will be automa…
Browse files Browse the repository at this point in the history
…tically appended to the field on frontend
  • Loading branch information
big213 committed Apr 16, 2021
1 parent 51c417b commit 2744f9b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion frontend/models/personalBest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,16 @@ export const PersonalBest = <RecordInfo<'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`)
Expand Down

0 comments on commit 2744f9b

Please sign in to comment.