about summary refs log tree commit diff
path: root/src/lib/strings
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2024-08-29 19:22:53 -0500
committerGitHub <noreply@github.com>2024-08-29 19:22:53 -0500
commit8651f31ebb7cf9c6a0949503f2c2c5755328ce46 (patch)
tree04f9c08a3770cee554a6cd421a53dc04957457fb /src/lib/strings
parentd5a76183746bc67f88b858add49c2dba52b99bb5 (diff)
downloadvoidsky-8651f31ebb7cf9c6a0949503f2c2c5755328ce46.tar.zst
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 <git@mary.my.id>
Diffstat (limited to 'src/lib/strings')
-rw-r--r--src/lib/strings/time.ts17
1 files changed, 8 insertions, 9 deletions
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 {