diff options
author | Eric Bailey <git@esb.lol> | 2024-08-29 19:22:53 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-29 19:22:53 -0500 |
commit | 8651f31ebb7cf9c6a0949503f2c2c5755328ce46 (patch) | |
tree | 04f9c08a3770cee554a6cd421a53dc04957457fb /src/view/com/util/numeric | |
parent | d5a76183746bc67f88b858add49c2dba52b99bb5 (diff) | |
download | voidsky-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/view/com/util/numeric')
-rw-r--r-- | src/view/com/util/numeric/format.ts | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/src/view/com/util/numeric/format.ts b/src/view/com/util/numeric/format.ts index 71d8d73e0..cca9fc7e7 100644 --- a/src/view/com/util/numeric/format.ts +++ b/src/view/com/util/numeric/format.ts @@ -1,19 +1,12 @@ -export const formatCount = (num: number) => - Intl.NumberFormat('en-US', { +import type {I18n} from '@lingui/core' + +export const formatCount = (i18n: I18n, num: number) => { + return i18n.number(num, { notation: 'compact', maximumFractionDigits: 1, // `1,953` shouldn't be rounded up to 2k, it should be truncated. // @ts-expect-error: `roundingMode` doesn't seem to be in the typings yet // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#roundingmode roundingMode: 'trunc', - }).format(num) - -export function formatCountShortOnly(num: number): string { - if (num >= 1000000) { - return (num / 1000000).toFixed(1) + 'M' - } - if (num >= 1000) { - return (num / 1000).toFixed(1) + 'K' - } - return String(num) + }) } |