diff options
| author | かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com> | 2024-09-10 18:39:53 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-10 18:39:53 +0900 |
| commit | 837a8e15d893a670ab2ce51b3ec87e6b62a51da7 (patch) | |
| tree | 0b651782db2bf440f1c789606d6367226f2e2253 /packages/frontend-shared/js/intl-const.ts | |
| parent | Dev: cypressをdev containerで実行可に(e2e-dev-container) (#14526) (diff) | |
| download | misskey-837a8e15d893a670ab2ce51b3ec87e6b62a51da7.tar.gz misskey-837a8e15d893a670ab2ce51b3ec87e6b62a51da7.tar.bz2 misskey-837a8e15d893a670ab2ce51b3ec87e6b62a51da7.zip | |
refactor(frontend): frontend-embed/src/to-be-sharedを共通化 (#14536)
* refactor(frontend): shouldCollapsedを共通化
* refactor(frontend): config.js, worker-multi-dispatch.js, intl-const.jsを共通化
* fix(frontend-shared): fix type error
* refactor(frontend): is-link.jsと、同一の振る舞いをする記述を共通化
* fix
* fix lint
* lint fixes
Diffstat (limited to 'packages/frontend-shared/js/intl-const.ts')
| -rw-r--r-- | packages/frontend-shared/js/intl-const.ts | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/packages/frontend-shared/js/intl-const.ts b/packages/frontend-shared/js/intl-const.ts new file mode 100644 index 0000000000..33b65b6e9b --- /dev/null +++ b/packages/frontend-shared/js/intl-const.ts @@ -0,0 +1,51 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { lang } from '@@/js/config.js'; + +// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition +export const versatileLang = (lang ?? 'ja-JP').replace('ja-KS', 'ja-JP'); + +let _dateTimeFormat: Intl.DateTimeFormat; +try { + _dateTimeFormat = new Intl.DateTimeFormat(versatileLang, { + year: 'numeric', + month: 'numeric', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + second: 'numeric', + }); +} catch (err) { + console.warn(err); + if (_DEV_) console.log('[Intl] Fallback to en-US'); + + // Fallback to en-US + _dateTimeFormat = new Intl.DateTimeFormat('en-US', { + year: 'numeric', + month: 'numeric', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + second: 'numeric', + }); +} +export const dateTimeFormat = _dateTimeFormat; + +export const timeZone = dateTimeFormat.resolvedOptions().timeZone; + +export const hemisphere = /^(australia|pacific|antarctica|indian)\//i.test(timeZone) ? 'S' : 'N'; + +let _numberFormat: Intl.NumberFormat; +try { + _numberFormat = new Intl.NumberFormat(versatileLang); +} catch (err) { + console.warn(err); + if (_DEV_) console.log('[Intl] Fallback to en-US'); + + // Fallback to en-US + _numberFormat = new Intl.NumberFormat('en-US'); +} +export const numberFormat = _numberFormat; |