From b02cae4967702311372d4d0f365542809726374e Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Sat, 8 Jul 2023 13:43:25 +0800 Subject: [PATCH] Try use more system locale Hopefully locale doesn't change half way --- src/utils/nice-date-time.js | 3 ++- src/utils/shorten-number.jsx | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/utils/nice-date-time.js b/src/utils/nice-date-time.js index ce349acc..33f9036f 100644 --- a/src/utils/nice-date-time.js +++ b/src/utils/nice-date-time.js @@ -1,9 +1,10 @@ +const { locale } = new Intl.DateTimeFormat().resolvedOptions(); + function niceDateTime(date, { hideTime, formatOpts } = {}) { if (!(date instanceof Date)) { date = new Date(date); } const currentYear = new Date().getFullYear(); - const locale = new Intl.DateTimeFormat().resolvedOptions().locale; const dateText = Intl.DateTimeFormat(locale, { // Show year if not current year year: date.getFullYear() === currentYear ? undefined : 'numeric', diff --git a/src/utils/shorten-number.jsx b/src/utils/shorten-number.jsx index 43dd0680..e165b716 100644 --- a/src/utils/shorten-number.jsx +++ b/src/utils/shorten-number.jsx @@ -1,5 +1,7 @@ +const { locale } = Intl.NumberFormat().resolvedOptions(); + export default function shortenNumber(num) { - return Intl.NumberFormat('en-US', { + return Intl.NumberFormat(locale, { notation: 'compact', }).format(num); }