From 8651f31ebb7cf9c6a0949503f2c2c5755328ce46 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 29 Aug 2024 19:22:53 -0500 Subject: Localize dates, counts (#5027) * refactor: consistent localized formatting * refactor: localized date time * refactor: localize relative time with strings * chore: fix typo from copy-paste * Clean up useTimeAgo * Remove old ago * Const * Reuse * Prettier --------- Co-authored-by: Mary --- src/lib/strings/time.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/lib/strings/time.ts') diff --git a/src/lib/strings/time.ts b/src/lib/strings/time.ts index bfefea9bc..e505b7892 100644 --- a/src/lib/strings/time.ts +++ b/src/lib/strings/time.ts @@ -1,13 +1,12 @@ -export function niceDate(date: number | string | Date) { +import {I18n} from '@lingui/core' + +export function niceDate(i18n: I18n, date: number | string | Date) { const d = new Date(date) - return `${d.toLocaleDateString('en-us', { - year: 'numeric', - month: 'short', - day: 'numeric', - })} at ${d.toLocaleTimeString(undefined, { - hour: 'numeric', - minute: '2-digit', - })}` + + return i18n.date(d, { + dateStyle: 'long', + timeStyle: 'short', + }) } export function getAge(birthDate: Date): number { -- cgit 1.4.1