Try use more system locale

Hopefully locale doesn't change half way
This commit is contained in:
Lim Chee Aun 2023-07-08 13:43:25 +08:00
parent 41fa08536e
commit b02cae4967
2 changed files with 5 additions and 2 deletions

View file

@ -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',

View file

@ -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);
}