-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: initialize all Intl formatters lazily (#2026)
fixes #2024
- Loading branch information
1 parent
3c307a4
commit 69ef9f2
Showing
7 changed files
with
23 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
// adapted from https://unpkg.com/[email protected]/lib/index.js | ||
import { LOCALE } from '../../_static/intl' | ||
import { thunk } from '../../_utils/thunk' | ||
|
||
const IndexMapEn = ['second', 'minute', 'hour', 'day', 'week', 'month', 'year'] | ||
const SEC_ARRAY = [60, 60, 24, 7, 365 / 7 / 12, 12] | ||
const intlFormat = new Intl.RelativeTimeFormat(LOCALE) | ||
const intlFormat = thunk(() => new Intl.RelativeTimeFormat(LOCALE)) | ||
|
||
function formatRelativeTime (number, index) { | ||
if (index === 0) { | ||
|
@@ -14,7 +15,7 @@ function formatRelativeTime (number, index) { | |
} | ||
const unit = IndexMapEn[Math.floor(index / 2)] | ||
|
||
return intlFormat.format(number, unit) | ||
return intlFormat().format(number, unit) | ||
} | ||
|
||
function formatDiff (seconds) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
import { LOCALE } from '../_static/intl' | ||
import { thunk } from './thunk' | ||
|
||
export const absoluteDateFormatter = new Intl.DateTimeFormat(LOCALE, { | ||
export const absoluteDateFormatter = thunk(() => new Intl.DateTimeFormat(LOCALE, { | ||
year: 'numeric', | ||
month: 'long', | ||
day: 'numeric', | ||
hour: '2-digit', | ||
minute: '2-digit' | ||
}) | ||
})) | ||
|
||
export const shortAbsoluteDateFormatter = new Intl.DateTimeFormat(LOCALE, { | ||
export const shortAbsoluteDateFormatter = thunk(() => new Intl.DateTimeFormat(LOCALE, { | ||
year: 'numeric', | ||
month: 'short', | ||
day: 'numeric', | ||
hour: '2-digit', | ||
minute: '2-digit' | ||
}) | ||
})) | ||
|
||
export const dayOnlyAbsoluteDateFormatter = new Intl.DateTimeFormat(LOCALE, { | ||
export const dayOnlyAbsoluteDateFormatter = thunk(() => new Intl.DateTimeFormat(LOCALE, { | ||
year: 'numeric', | ||
month: 'short', | ||
day: 'numeric' | ||
}) | ||
})) |