From a1b368ca4d298ebec5fa9fa99566d93a88214279 Mon Sep 17 00:00:00 2001 From: Frudrax Cheng Date: Tue, 26 Nov 2024 11:41:38 +0800 Subject: [PATCH 01/10] Fix post time localization on native --- package.json | 1 + src/lib/strings/time.ts | 21 +++++++++++++++++---- src/locale/i18n.ts | 27 +++++++++++++++++++++++++++ yarn.lock | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 8449e1dee4..bea6db5b9d 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "@expo/webpack-config": "^19.0.0", "@floating-ui/dom": "^1.6.3", "@floating-ui/react-dom": "^2.0.8", + "@formatjs/intl-datetimeformat": "^6.16.5", "@formatjs/intl-locale": "^4.0.0", "@formatjs/intl-numberformat": "^8.10.3", "@formatjs/intl-pluralrules": "^5.2.14", diff --git a/src/lib/strings/time.ts b/src/lib/strings/time.ts index e505b7892e..05797f344e 100644 --- a/src/lib/strings/time.ts +++ b/src/lib/strings/time.ts @@ -1,12 +1,25 @@ +import {DateTimeFormat} from '@formatjs/intl-datetimeformat' import {I18n} from '@lingui/core' +import {isNative,isWeb} from '#/platform/detection' + export function niceDate(i18n: I18n, date: number | string | Date) { const d = new Date(date) - return i18n.date(d, { - dateStyle: 'long', - timeStyle: 'short', - }) + if (isWeb) { + return i18n.date(d, { + dateStyle: 'long', + timeStyle: 'short', + }) + } + + if (isNative) { + const dateFormatter = new DateTimeFormat(i18n.locale, { + dateStyle: 'long', + timeStyle: 'short', + }) + return dateFormatter.format(d) + } } export function getAge(birthDate: Date): number { diff --git a/src/locale/i18n.ts b/src/locale/i18n.ts index 791549a589..30da09b4b7 100644 --- a/src/locale/i18n.ts +++ b/src/locale/i18n.ts @@ -1,8 +1,10 @@ // Don't remove -force from these because detection is VERY slow on low-end Android. // https://github.com/formatjs/formatjs/issues/4463#issuecomment-2176070577 import '@formatjs/intl-locale/polyfill-force' +import '@formatjs/intl-datetimeformat/polyfill-force' import '@formatjs/intl-pluralrules/polyfill-force' import '@formatjs/intl-numberformat/polyfill-force' +import '@formatjs/intl-datetimeformat/locale-data/en' import '@formatjs/intl-pluralrules/locale-data/en' import '@formatjs/intl-numberformat/locale-data/en' @@ -47,6 +49,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.ca: { i18n.loadAndActivate({locale, messages: messagesCa}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/ca'), import('@formatjs/intl-pluralrules/locale-data/ca'), import('@formatjs/intl-numberformat/locale-data/ca'), ]) @@ -55,6 +58,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.de: { i18n.loadAndActivate({locale, messages: messagesDe}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/de'), import('@formatjs/intl-pluralrules/locale-data/de'), import('@formatjs/intl-numberformat/locale-data/de'), ]) @@ -63,6 +67,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.en_GB: { i18n.loadAndActivate({locale, messages: messagesEn_GB}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/en-GB'), import('@formatjs/intl-pluralrules/locale-data/en'), import('@formatjs/intl-numberformat/locale-data/en-GB'), ]) @@ -71,6 +76,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.es: { i18n.loadAndActivate({locale, messages: messagesEs}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/es'), import('@formatjs/intl-pluralrules/locale-data/es'), import('@formatjs/intl-numberformat/locale-data/es'), ]) @@ -79,6 +85,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.fi: { i18n.loadAndActivate({locale, messages: messagesFi}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/fi'), import('@formatjs/intl-pluralrules/locale-data/fi'), import('@formatjs/intl-numberformat/locale-data/fi'), ]) @@ -87,6 +94,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.fr: { i18n.loadAndActivate({locale, messages: messagesFr}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/fr'), import('@formatjs/intl-pluralrules/locale-data/fr'), import('@formatjs/intl-numberformat/locale-data/fr'), ]) @@ -95,6 +103,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.ga: { i18n.loadAndActivate({locale, messages: messagesGa}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/ga'), import('@formatjs/intl-pluralrules/locale-data/ga'), import('@formatjs/intl-numberformat/locale-data/ga'), ]) @@ -103,6 +112,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.gl: { i18n.loadAndActivate({locale, messages: messagesGl}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/gl'), import('@formatjs/intl-pluralrules/locale-data/gl'), import('@formatjs/intl-numberformat/locale-data/gl'), ]) @@ -111,6 +121,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.hi: { i18n.loadAndActivate({locale, messages: messagesHi}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/hi'), import('@formatjs/intl-pluralrules/locale-data/hi'), import('@formatjs/intl-numberformat/locale-data/hi'), ]) @@ -119,6 +130,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.hu: { i18n.loadAndActivate({locale, messages: messagesHu}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/hu'), import('@formatjs/intl-pluralrules/locale-data/hu'), import('@formatjs/intl-numberformat/locale-data/hu'), ]) @@ -127,6 +139,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.id: { i18n.loadAndActivate({locale, messages: messagesId}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/id'), import('@formatjs/intl-pluralrules/locale-data/id'), import('@formatjs/intl-numberformat/locale-data/id'), ]) @@ -135,6 +148,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.it: { i18n.loadAndActivate({locale, messages: messagesIt}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/it'), import('@formatjs/intl-pluralrules/locale-data/it'), import('@formatjs/intl-numberformat/locale-data/it'), ]) @@ -143,6 +157,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.ja: { i18n.loadAndActivate({locale, messages: messagesJa}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/ja'), import('@formatjs/intl-pluralrules/locale-data/ja'), import('@formatjs/intl-numberformat/locale-data/ja'), ]) @@ -151,6 +166,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.ko: { i18n.loadAndActivate({locale, messages: messagesKo}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/ko'), import('@formatjs/intl-pluralrules/locale-data/ko'), import('@formatjs/intl-numberformat/locale-data/ko'), ]) @@ -159,6 +175,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.nl: { i18n.loadAndActivate({locale, messages: messagesNl}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/nl'), import('@formatjs/intl-pluralrules/locale-data/nl'), import('@formatjs/intl-numberformat/locale-data/nl'), ]) @@ -167,6 +184,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.pl: { i18n.loadAndActivate({locale, messages: messagesPl}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/pl'), import('@formatjs/intl-pluralrules/locale-data/pl'), import('@formatjs/intl-numberformat/locale-data/pl'), ]) @@ -175,6 +193,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.pt_BR: { i18n.loadAndActivate({locale, messages: messagesPt_BR}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/pt'), import('@formatjs/intl-pluralrules/locale-data/pt'), import('@formatjs/intl-numberformat/locale-data/pt'), ]) @@ -183,6 +202,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.ru: { i18n.loadAndActivate({locale, messages: messagesRu}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/ru'), import('@formatjs/intl-pluralrules/locale-data/ru'), import('@formatjs/intl-numberformat/locale-data/ru'), ]) @@ -191,6 +211,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.th: { i18n.loadAndActivate({locale, messages: messagesTh}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/th'), import('@formatjs/intl-pluralrules/locale-data/th'), import('@formatjs/intl-numberformat/locale-data/th'), ]) @@ -199,6 +220,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.tr: { i18n.loadAndActivate({locale, messages: messagesTr}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/tr'), import('@formatjs/intl-pluralrules/locale-data/tr'), import('@formatjs/intl-numberformat/locale-data/tr'), ]) @@ -207,6 +229,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.uk: { i18n.loadAndActivate({locale, messages: messagesUk}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/uk'), import('@formatjs/intl-pluralrules/locale-data/uk'), import('@formatjs/intl-numberformat/locale-data/uk'), ]) @@ -215,6 +238,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.vi: { i18n.loadAndActivate({locale, messages: messagesVi}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/vi'), import('@formatjs/intl-pluralrules/locale-data/vi'), import('@formatjs/intl-numberformat/locale-data/vi'), ]) @@ -223,6 +247,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.zh_CN: { i18n.loadAndActivate({locale, messages: messagesZh_CN}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/zh-Hans'), import('@formatjs/intl-pluralrules/locale-data/zh'), import('@formatjs/intl-numberformat/locale-data/zh'), ]) @@ -231,6 +256,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.zh_HK: { i18n.loadAndActivate({locale, messages: messagesZh_HK}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/yue'), import('@formatjs/intl-pluralrules/locale-data/zh'), import('@formatjs/intl-numberformat/locale-data/zh'), ]) @@ -239,6 +265,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.zh_TW: { i18n.loadAndActivate({locale, messages: messagesZh_TW}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/zh-Hant'), import('@formatjs/intl-pluralrules/locale-data/zh'), import('@formatjs/intl-numberformat/locale-data/zh'), ]) diff --git a/yarn.lock b/yarn.lock index 16dbba3974..4647da40f6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4113,6 +4113,31 @@ "@formatjs/intl-localematcher" "0.5.4" tslib "^2.4.0" +"@formatjs/ecma402-abstract@2.2.4": + version "2.2.4" + resolved "https://registry.yarnpkg.com/@formatjs/ecma402-abstract/-/ecma402-abstract-2.2.4.tgz#355e42d375678229d46dc8ad7a7139520dd03e7b" + integrity sha512-lFyiQDVvSbQOpU+WFd//ILolGj4UgA/qXrKeZxdV14uKiAUiPAtX6XAn7WBCRi7Mx6I7EybM9E5yYn4BIpZWYg== + dependencies: + "@formatjs/fast-memoize" "2.2.3" + "@formatjs/intl-localematcher" "0.5.8" + tslib "2" + +"@formatjs/fast-memoize@2.2.3": + version "2.2.3" + resolved "https://registry.yarnpkg.com/@formatjs/fast-memoize/-/fast-memoize-2.2.3.tgz#74e64109279d5244f9fc281f3ae90c407cece823" + integrity sha512-3jeJ+HyOfu8osl3GNSL4vVHUuWFXR03Iz9jjgI7RwjG6ysu/Ymdr0JRCPHfF5yGbTE6JCrd63EpvX1/WybYRbA== + dependencies: + tslib "2" + +"@formatjs/intl-datetimeformat@^6.16.5": + version "6.16.5" + resolved "https://registry.yarnpkg.com/@formatjs/intl-datetimeformat/-/intl-datetimeformat-6.16.5.tgz#65302d7cfe532cbeebf818728fe370a2a4dfbec3" + integrity sha512-IukSD4pmyZZzpT5ysm6ONRKSu/OQq3vFKHA3exJDWSMjboPO+wO/bT9vOOw1y957N3vtrqvxHSfja6TYwbPpkQ== + dependencies: + "@formatjs/ecma402-abstract" "2.2.4" + "@formatjs/intl-localematcher" "0.5.8" + tslib "2" + "@formatjs/intl-enumerator@1.4.7": version "1.4.7" resolved "https://registry.yarnpkg.com/@formatjs/intl-enumerator/-/intl-enumerator-1.4.7.tgz#6ab697f3f8f18cf0cc6a6b028cb9c40db6001f3d" @@ -4144,6 +4169,13 @@ dependencies: tslib "^2.4.0" +"@formatjs/intl-localematcher@0.5.8": + version "0.5.8" + resolved "https://registry.yarnpkg.com/@formatjs/intl-localematcher/-/intl-localematcher-0.5.8.tgz#b11bbd04bd3551f7cadcb1ef1e231822d0e3c97e" + integrity sha512-I+WDNWWJFZie+jkfkiK5Mp4hEDyRSEvmyfYadflOno/mmKJKcB17fEpEH0oJu/OWhhCJ8kJBDz2YMd/6cDl7Mg== + dependencies: + tslib "2" + "@formatjs/intl-numberformat@^8.10.3": version "8.10.3" resolved "https://registry.yarnpkg.com/@formatjs/intl-numberformat/-/intl-numberformat-8.10.3.tgz#abc97cc6a7b7f1b20da9f07a976b5589c1192ab8" @@ -18235,6 +18267,11 @@ ts-node@^10.9.1: v8-compile-cache-lib "^3.0.1" yn "3.1.1" +tslib@2: + version "2.8.1" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f" + integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w== + tslib@^1.11.1, tslib@^1.8.1, tslib@^1.9.0: version "1.14.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" From c451b7be07f183dd32c0a749cda8e1817364f980 Mon Sep 17 00:00:00 2001 From: Frudrax Cheng Date: Tue, 26 Nov 2024 13:15:15 +0800 Subject: [PATCH 02/10] Fix timezone --- src/lib/strings/time.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib/strings/time.ts b/src/lib/strings/time.ts index 05797f344e..c14049741e 100644 --- a/src/lib/strings/time.ts +++ b/src/lib/strings/time.ts @@ -1,8 +1,16 @@ import {DateTimeFormat} from '@formatjs/intl-datetimeformat' import {I18n} from '@lingui/core' -import {isNative,isWeb} from '#/platform/detection' +import {isNative, isWeb} from '#/platform/detection' +/** + * Formats the given date into a localized string. + * + * This function chooses different formatting approaches based on the platform: + * - On the Web, it uses the `i18n.date` method to format the date. + * - On Native, it adjusts the time zone offset and uses `DateTimeFormat` for formatting. + * + */ export function niceDate(i18n: I18n, date: number | string | Date) { const d = new Date(date) @@ -14,6 +22,9 @@ export function niceDate(i18n: I18n, date: number | string | Date) { } if (isNative) { + const timeZoneOffsetInMinutes = new Date().getTimezoneOffset() + d.setMinutes(d.getMinutes() - timeZoneOffsetInMinutes) + const dateFormatter = new DateTimeFormat(i18n.locale, { dateStyle: 'long', timeStyle: 'short', From e6cfdd89bc822824786a2d1054f67730bc0d1f54 Mon Sep 17 00:00:00 2001 From: Frudrax Cheng Date: Tue, 3 Dec 2024 13:31:19 +0800 Subject: [PATCH 03/10] Revent time.ts --- src/lib/strings/time.ts | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/src/lib/strings/time.ts b/src/lib/strings/time.ts index c14049741e..e505b7892e 100644 --- a/src/lib/strings/time.ts +++ b/src/lib/strings/time.ts @@ -1,36 +1,12 @@ -import {DateTimeFormat} from '@formatjs/intl-datetimeformat' import {I18n} from '@lingui/core' -import {isNative, isWeb} from '#/platform/detection' - -/** - * Formats the given date into a localized string. - * - * This function chooses different formatting approaches based on the platform: - * - On the Web, it uses the `i18n.date` method to format the date. - * - On Native, it adjusts the time zone offset and uses `DateTimeFormat` for formatting. - * - */ export function niceDate(i18n: I18n, date: number | string | Date) { const d = new Date(date) - if (isWeb) { - return i18n.date(d, { - dateStyle: 'long', - timeStyle: 'short', - }) - } - - if (isNative) { - const timeZoneOffsetInMinutes = new Date().getTimezoneOffset() - d.setMinutes(d.getMinutes() - timeZoneOffsetInMinutes) - - const dateFormatter = new DateTimeFormat(i18n.locale, { - dateStyle: 'long', - timeStyle: 'short', - }) - return dateFormatter.format(d) - } + return i18n.date(d, { + dateStyle: 'long', + timeStyle: 'short', + }) } export function getAge(birthDate: Date): number { From b8b15f64d32f751186a50aa7df7826ef83ab2972 Mon Sep 17 00:00:00 2001 From: Frudrax Cheng Date: Tue, 3 Dec 2024 13:40:49 +0800 Subject: [PATCH 04/10] Add time.android.ts --- src/lib/strings/time.android.ts | 24 +++++++++++++++++++++ src/view/com/post-thread/PostThreadItem.tsx | 6 +++++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/lib/strings/time.android.ts diff --git a/src/lib/strings/time.android.ts b/src/lib/strings/time.android.ts new file mode 100644 index 0000000000..9cf686ffc6 --- /dev/null +++ b/src/lib/strings/time.android.ts @@ -0,0 +1,24 @@ +import {DateTimeFormat} from '@formatjs/intl-datetimeformat' +import {I18n} from '@lingui/core' + +/** + * Formats the given date into a localized string. + * + * This function chooses different formatting approaches based on the platform: + * - On Web, it uses the `i18n.date` method to format the date. + * - On Android, it adjusts the time zone offset and uses `DateTimeFormat` for formatting. + * + */ + +export function niceDate(i18n: I18n, date: number | string | Date) { + const d = new Date(date) + + const timeZoneOffsetInMinutes = new Date().getTimezoneOffset() + d.setMinutes(d.getMinutes() - timeZoneOffsetInMinutes) + + const dateFormatter = new DateTimeFormat(i18n.locale, { + dateStyle: 'long', + timeStyle: 'short', + }) + return dateFormatter.format(d) +} diff --git a/src/view/com/post-thread/PostThreadItem.tsx b/src/view/com/post-thread/PostThreadItem.tsx index 035f7a681b..3dad6846e5 100644 --- a/src/view/com/post-thread/PostThreadItem.tsx +++ b/src/view/com/post-thread/PostThreadItem.tsx @@ -23,9 +23,11 @@ import {makeProfileLink} from '#/lib/routes/links' import {sanitizeDisplayName} from '#/lib/strings/display-names' import {sanitizeHandle} from '#/lib/strings/handles' import {countLines} from '#/lib/strings/helpers' -import {niceDate} from '#/lib/strings/time' +import {niceDate as niceDateWebOriOS} from '#/lib/strings/time' +import {niceDate as niceDateAndroid} from '#/lib/strings/time.android' import {s} from '#/lib/styles' import {getTranslatorLink, isPostInLanguage} from '#/locale/helpers' +import {isAndroid} from '#/platform/detection' import {POST_TOMBSTONE, Shadow, usePostShadow} from '#/state/cache/post-shadow' import {useLanguagePrefs} from '#/state/preferences' import {ThreadPost} from '#/state/queries/post-thread' @@ -740,6 +742,7 @@ function ExpandedPostDetails({ const {_, i18n} = useLingui() const openLink = useOpenLink() const isRootPost = !('reply' in post.record) + const niceDate = isAndroid ? niceDateAndroid : niceDateWebOriOS const onTranslatePress = React.useCallback( (e: GestureResponderEvent) => { @@ -784,6 +787,7 @@ function BackdatedPostIndicator({post}: {post: AppBskyFeedDefs.PostView}) { const t = useTheme() const {_, i18n} = useLingui() const control = Prompt.usePromptControl() + const niceDate = isAndroid ? niceDateAndroid : niceDateWebOriOS const indexedAt = new Date(post.indexedAt) const createdAt = AppBskyFeedPost.isRecord(post.record) From 74943c9fe680cf1d6f934d2b705d4674c5098fd0 Mon Sep 17 00:00:00 2001 From: Frudrax Cheng Date: Tue, 3 Dec 2024 14:37:54 +0800 Subject: [PATCH 05/10] Add missing 'an' and 'ast' --- src/locale/i18n.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/locale/i18n.ts b/src/locale/i18n.ts index 35a8baa134..5620ab3203 100644 --- a/src/locale/i18n.ts +++ b/src/locale/i18n.ts @@ -51,6 +51,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.an: { i18n.loadAndActivate({locale, messages: messagesAn}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/es'), import('@formatjs/intl-pluralrules/locale-data/an'), import('@formatjs/intl-numberformat/locale-data/es'), ]) @@ -59,6 +60,7 @@ export async function dynamicActivate(locale: AppLanguage) { case AppLanguage.ast: { i18n.loadAndActivate({locale, messages: messagesAst}) await Promise.all([ + import('@formatjs/intl-datetimeformat/locale-data/ast'), import('@formatjs/intl-pluralrules/locale-data/ast'), import('@formatjs/intl-numberformat/locale-data/ast'), ]) From 9badf5351342f3e990abcd3d17a1fc64fff610b9 Mon Sep 17 00:00:00 2001 From: Frudrax Cheng Date: Sat, 7 Dec 2024 08:25:40 +0800 Subject: [PATCH 06/10] Revent PostThreadItem.tsx --- src/view/com/post-thread/PostThreadItem.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/view/com/post-thread/PostThreadItem.tsx b/src/view/com/post-thread/PostThreadItem.tsx index 3dad6846e5..035f7a681b 100644 --- a/src/view/com/post-thread/PostThreadItem.tsx +++ b/src/view/com/post-thread/PostThreadItem.tsx @@ -23,11 +23,9 @@ import {makeProfileLink} from '#/lib/routes/links' import {sanitizeDisplayName} from '#/lib/strings/display-names' import {sanitizeHandle} from '#/lib/strings/handles' import {countLines} from '#/lib/strings/helpers' -import {niceDate as niceDateWebOriOS} from '#/lib/strings/time' -import {niceDate as niceDateAndroid} from '#/lib/strings/time.android' +import {niceDate} from '#/lib/strings/time' import {s} from '#/lib/styles' import {getTranslatorLink, isPostInLanguage} from '#/locale/helpers' -import {isAndroid} from '#/platform/detection' import {POST_TOMBSTONE, Shadow, usePostShadow} from '#/state/cache/post-shadow' import {useLanguagePrefs} from '#/state/preferences' import {ThreadPost} from '#/state/queries/post-thread' @@ -742,7 +740,6 @@ function ExpandedPostDetails({ const {_, i18n} = useLingui() const openLink = useOpenLink() const isRootPost = !('reply' in post.record) - const niceDate = isAndroid ? niceDateAndroid : niceDateWebOriOS const onTranslatePress = React.useCallback( (e: GestureResponderEvent) => { @@ -787,7 +784,6 @@ function BackdatedPostIndicator({post}: {post: AppBskyFeedDefs.PostView}) { const t = useTheme() const {_, i18n} = useLingui() const control = Prompt.usePromptControl() - const niceDate = isAndroid ? niceDateAndroid : niceDateWebOriOS const indexedAt = new Date(post.indexedAt) const createdAt = AppBskyFeedPost.isRecord(post.record) From 346ab50fe6aea5e0126422557edc762872651d06 Mon Sep 17 00:00:00 2001 From: Frudrax Cheng Date: Sat, 7 Dec 2024 20:53:13 +0800 Subject: [PATCH 07/10] Resolve duplicate versions in lockfile --- package.json | 2 +- yarn.lock | 42 +++++++----------------------------------- 2 files changed, 8 insertions(+), 36 deletions(-) diff --git a/package.json b/package.json index 78d5c1f928..84b4919a82 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "@expo/webpack-config": "^19.0.0", "@floating-ui/dom": "^1.6.3", "@floating-ui/react-dom": "^2.0.8", - "@formatjs/intl-datetimeformat": "^6.16.5", + "@formatjs/intl-datetimeformat": "6.12.6", "@formatjs/intl-locale": "^4.0.0", "@formatjs/intl-numberformat": "^8.10.3", "@formatjs/intl-pluralrules": "^5.2.14", diff --git a/yarn.lock b/yarn.lock index 81aab05b52..f31082b2bd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4258,30 +4258,14 @@ "@formatjs/intl-localematcher" "0.5.4" tslib "^2.4.0" -"@formatjs/ecma402-abstract@2.2.4": - version "2.2.4" - resolved "https://registry.yarnpkg.com/@formatjs/ecma402-abstract/-/ecma402-abstract-2.2.4.tgz#355e42d375678229d46dc8ad7a7139520dd03e7b" - integrity sha512-lFyiQDVvSbQOpU+WFd//ILolGj4UgA/qXrKeZxdV14uKiAUiPAtX6XAn7WBCRi7Mx6I7EybM9E5yYn4BIpZWYg== - dependencies: - "@formatjs/fast-memoize" "2.2.3" - "@formatjs/intl-localematcher" "0.5.8" - tslib "2" - -"@formatjs/fast-memoize@2.2.3": - version "2.2.3" - resolved "https://registry.yarnpkg.com/@formatjs/fast-memoize/-/fast-memoize-2.2.3.tgz#74e64109279d5244f9fc281f3ae90c407cece823" - integrity sha512-3jeJ+HyOfu8osl3GNSL4vVHUuWFXR03Iz9jjgI7RwjG6ysu/Ymdr0JRCPHfF5yGbTE6JCrd63EpvX1/WybYRbA== - dependencies: - tslib "2" - -"@formatjs/intl-datetimeformat@^6.16.5": - version "6.16.5" - resolved "https://registry.yarnpkg.com/@formatjs/intl-datetimeformat/-/intl-datetimeformat-6.16.5.tgz#65302d7cfe532cbeebf818728fe370a2a4dfbec3" - integrity sha512-IukSD4pmyZZzpT5ysm6ONRKSu/OQq3vFKHA3exJDWSMjboPO+wO/bT9vOOw1y957N3vtrqvxHSfja6TYwbPpkQ== +"@formatjs/intl-datetimeformat@6.12.6": + version "6.12.6" + resolved "https://registry.yarnpkg.com/@formatjs/intl-datetimeformat/-/intl-datetimeformat-6.12.6.tgz#45d12e1d95a5f631b4d911c9ab47a6aa032dcfbc" + integrity sha512-T7bEek4GXKXdTKcJdizgixLg9UNq3DRaFsi/yFG9x5K9ZtaGMXd7LTNrBaY6QpLjtFfapEGo3SwX7yEc0S0GwA== dependencies: - "@formatjs/ecma402-abstract" "2.2.4" - "@formatjs/intl-localematcher" "0.5.8" - tslib "2" + "@formatjs/ecma402-abstract" "2.0.0" + "@formatjs/intl-localematcher" "0.5.4" + tslib "^2.4.0" "@formatjs/intl-enumerator@1.4.7": version "1.4.7" @@ -4314,13 +4298,6 @@ dependencies: tslib "^2.4.0" -"@formatjs/intl-localematcher@0.5.8": - version "0.5.8" - resolved "https://registry.yarnpkg.com/@formatjs/intl-localematcher/-/intl-localematcher-0.5.8.tgz#b11bbd04bd3551f7cadcb1ef1e231822d0e3c97e" - integrity sha512-I+WDNWWJFZie+jkfkiK5Mp4hEDyRSEvmyfYadflOno/mmKJKcB17fEpEH0oJu/OWhhCJ8kJBDz2YMd/6cDl7Mg== - dependencies: - tslib "2" - "@formatjs/intl-numberformat@^8.10.3": version "8.10.3" resolved "https://registry.yarnpkg.com/@formatjs/intl-numberformat/-/intl-numberformat-8.10.3.tgz#abc97cc6a7b7f1b20da9f07a976b5589c1192ab8" @@ -18137,11 +18114,6 @@ ts-node@^10.9.1: v8-compile-cache-lib "^3.0.1" yn "3.1.1" -tslib@2: - version "2.8.1" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f" - integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w== - tslib@^1.11.1, tslib@^1.8.1, tslib@^1.9.0: version "1.14.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" From 385b300fa3526dc47a52bab0fbd0627d758e4109 Mon Sep 17 00:00:00 2001 From: Frudrax Cheng Date: Sat, 7 Dec 2024 21:09:59 +0800 Subject: [PATCH 08/10] Move to time.native.ts --- src/lib/strings/{time.android.ts => time.native.ts} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/lib/strings/{time.android.ts => time.native.ts} (88%) diff --git a/src/lib/strings/time.android.ts b/src/lib/strings/time.native.ts similarity index 88% rename from src/lib/strings/time.android.ts rename to src/lib/strings/time.native.ts index 9cf686ffc6..c5b22ed546 100644 --- a/src/lib/strings/time.android.ts +++ b/src/lib/strings/time.native.ts @@ -6,7 +6,7 @@ import {I18n} from '@lingui/core' * * This function chooses different formatting approaches based on the platform: * - On Web, it uses the `i18n.date` method to format the date. - * - On Android, it adjusts the time zone offset and uses `DateTimeFormat` for formatting. + * - On Native, it adjusts the time zone offset and uses `DateTimeFormat` for formatting. * */ From 91d15adc4d1f61037902dd81b1a15ba8c10e2160 Mon Sep 17 00:00:00 2001 From: Frudrax Cheng Date: Thu, 12 Dec 2024 09:23:01 +0800 Subject: [PATCH 09/10] Follow #7055 to upgrade intl-datetimeformat version --- package.json | 2 +- yarn.lock | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 3bcb9cfca8..e6bd015d7d 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "@expo/webpack-config": "^19.0.0", "@floating-ui/dom": "^1.6.3", "@floating-ui/react-dom": "^2.0.8", - "@formatjs/intl-datetimeformat": "6.12.6", + "@formatjs/intl-datetimeformat": "^6.17.1", "@formatjs/intl-locale": "^4.2.8", "@formatjs/intl-numberformat": "^8.15.1", "@formatjs/intl-pluralrules": "^5.4.1", diff --git a/yarn.lock b/yarn.lock index f4fa149d4f..5e9ba6e268 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4260,15 +4260,6 @@ decimal.js "10" tslib "2" -"@formatjs/intl-datetimeformat@6.12.6": - version "6.12.6" - resolved "https://registry.yarnpkg.com/@formatjs/intl-datetimeformat/-/intl-datetimeformat-6.12.6.tgz#45d12e1d95a5f631b4d911c9ab47a6aa032dcfbc" - integrity sha512-T7bEek4GXKXdTKcJdizgixLg9UNq3DRaFsi/yFG9x5K9ZtaGMXd7LTNrBaY6QpLjtFfapEGo3SwX7yEc0S0GwA== - dependencies: - "@formatjs/ecma402-abstract" "2.0.0" - "@formatjs/intl-localematcher" "0.5.4" - tslib "^2.4.0" - "@formatjs/fast-memoize@2.2.5": version "2.2.5" resolved "https://registry.yarnpkg.com/@formatjs/fast-memoize/-/fast-memoize-2.2.5.tgz#54a4a1793d773b72c372d3dcab3595149aee7880" @@ -4276,6 +4267,15 @@ dependencies: tslib "2" +"@formatjs/intl-datetimeformat@^6.17.1": + version "6.17.1" + resolved "https://registry.yarnpkg.com/@formatjs/intl-datetimeformat/-/intl-datetimeformat-6.17.1.tgz#d5e800891f9d79c8f1af1999f51db51f1384eca1" + integrity sha512-a18NqRo6R73xpREuMZo8FqjO+LnYFDHoeoviTh5de4ebI46wqLSDgbAIKoceuWblTQt8bvCpJIwvKgLItea88Q== + dependencies: + "@formatjs/ecma402-abstract" "2.3.1" + "@formatjs/intl-localematcher" "0.5.9" + tslib "2" + "@formatjs/intl-enumerator@1.8.7": version "1.8.7" resolved "https://registry.yarnpkg.com/@formatjs/intl-enumerator/-/intl-enumerator-1.8.7.tgz#3f004753333f80cc468ae34046bd8416772a0412" From 7b489d3cb6ad587d7a0347c3ab145132c379aeca Mon Sep 17 00:00:00 2001 From: Frudrax Cheng Date: Sun, 15 Dec 2024 11:12:15 +0800 Subject: [PATCH 10/10] Remove time.native.ts --- src/lib/strings/time.native.ts | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 src/lib/strings/time.native.ts diff --git a/src/lib/strings/time.native.ts b/src/lib/strings/time.native.ts deleted file mode 100644 index c5b22ed546..0000000000 --- a/src/lib/strings/time.native.ts +++ /dev/null @@ -1,24 +0,0 @@ -import {DateTimeFormat} from '@formatjs/intl-datetimeformat' -import {I18n} from '@lingui/core' - -/** - * Formats the given date into a localized string. - * - * This function chooses different formatting approaches based on the platform: - * - On Web, it uses the `i18n.date` method to format the date. - * - On Native, it adjusts the time zone offset and uses `DateTimeFormat` for formatting. - * - */ - -export function niceDate(i18n: I18n, date: number | string | Date) { - const d = new Date(date) - - const timeZoneOffsetInMinutes = new Date().getTimezoneOffset() - d.setMinutes(d.getMinutes() - timeZoneOffsetInMinutes) - - const dateFormatter = new DateTimeFormat(i18n.locale, { - dateStyle: 'long', - timeStyle: 'short', - }) - return dateFormatter.format(d) -}