nicer dates in timeline header

This commit is contained in:
Lachlan Kermode
2020-07-01 11:10:18 +02:00
parent e985857d73
commit 109210714f
4 changed files with 23 additions and 17 deletions

View File

@@ -211,3 +211,19 @@ export function findDescriptionInFilterTree (key, node) {
if (descs.length !== 1) return false
return descs[0]
}
export function makeNiceDate (datetime) {
if (datetime === null) return null
// see https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date
const dateTimeFormat = new Intl.DateTimeFormat(
'en',
{ year: 'numeric', month: 'long', day: '2-digit' }
)
const [
{ value: month },,
{ value: day },,
{ value: year }
] = dateTimeFormat.formatToParts(datetime)
return `${day} ${month}, ${year}`
}