Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions ark/util/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,15 @@ export const describeCollapsibleDate = (date: Date): string => {
if (hours === 0 && minutes === 0 && seconds === 0 && milliseconds === 0)
return datePortion

let timePortion = date.toLocaleTimeString()
const h = hours % 12 || 12
const suffix = hours < 12 ? " AM" : " PM"

const suffix =
timePortion.endsWith(" AM") || timePortion.endsWith(" PM") ?
timePortion.slice(-3)
: ""

if (suffix) timePortion = timePortion.slice(0, -suffix.length)
let timePortion =
seconds || milliseconds ?
`${h}:${pad(minutes, 2)}:${pad(seconds, 2)}`
: `${h}:${pad(minutes, 2)}`

if (milliseconds) timePortion += `.${pad(milliseconds, 3)}`
else if (timeWithUnnecessarySeconds.test(timePortion))
timePortion = timePortion.slice(0, -3)

return `${timePortion + suffix}, ${datePortion}`
}
Expand All @@ -234,7 +231,5 @@ const months = [
"December"
]

const timeWithUnnecessarySeconds = /:\d\d:00$/

const pad = (value: number, length: number) =>
String(value).padStart(length, "0")
Loading