From afa8f06ef66ada4077ceffddb90ff657a89132d6 Mon Sep 17 00:00:00 2001 From: naskya Date: Sat, 15 Apr 2023 00:40:13 +0900 Subject: [PATCH 1/6] improve city search --- packages/client/src/pages/user/home.vue | 34 ++++++++++++++++--------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/packages/client/src/pages/user/home.vue b/packages/client/src/pages/user/home.vue index 3fa01d9c06..ef5a6544d5 100644 --- a/packages/client/src/pages/user/home.vue +++ b/packages/client/src/pages/user/home.vue @@ -353,18 +353,28 @@ const age = $computed(() => { }); const timeForThem = $computed(() => { - const tzInfo = cityTimezones.lookupViaCity( - props.user.location!.replace(/\s.*/, "") - ); - if (tzInfo.length == 0) return ""; - const tz = tzInfo[0].timezone; - const theirTime = new Date().toLocaleString("en-US", { - timeZone: tz, - hour12: false, - }); - return ` (${theirTime.split(",")[1].trim().split(":")[0]}:${theirTime - .split(" ")[1] - .slice(-5, -3)})`; + const maybeCityNames = [ + props.user.location!, + props.user.location!.replace(/[^A-Za-z].*/, ""), + props.user.location!.replace(/[^A-Za-z\-\'\.].*/, ""), + props.user.location!.replace(/[^A-Za-z0-9\-\'\.\s].*/, ""), + ]; + + for (const city of maybeCityNames) { + let tzInfo = cityTimezones.lookupViaCity(city); + if (tzInfo.length == 0) continue; + + const tz = tzInfo[0].timezone; + const theirTime = new Date().toLocaleString("en-US", { + timeZone: tz, + hour12: false, + }); + return ` (${theirTime.split(",")[1].trim().split(":")[0]}:${theirTime + .split(" ")[1] + .slice(-5, -3)})`; + } + + return ""; }); function menu(ev) { From 4d0245f1a5fe3617ddce47b2477a06568e479b32 Mon Sep 17 00:00:00 2001 From: naskya Date: Sat, 15 Apr 2023 01:00:43 +0900 Subject: [PATCH 2/6] allow acute accent --- packages/client/src/pages/user/home.vue | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/client/src/pages/user/home.vue b/packages/client/src/pages/user/home.vue index ef5a6544d5..84ee4b0a30 100644 --- a/packages/client/src/pages/user/home.vue +++ b/packages/client/src/pages/user/home.vue @@ -355,9 +355,18 @@ const age = $computed(() => { const timeForThem = $computed(() => { const maybeCityNames = [ props.user.location!, - props.user.location!.replace(/[^A-Za-z].*/, ""), - props.user.location!.replace(/[^A-Za-z\-\'\.].*/, ""), - props.user.location!.replace(/[^A-Za-z0-9\-\'\.\s].*/, ""), + props.user.location!.replace( + /[^A-Za-zÁĆÉǴÍḰĹḾŃÓṔŔŚÚÝŹáćéǵíḱĺḿńóṕŕśúýź].*/, + "" + ), + props.user.location!.replace( + /[^A-Za-zÁĆÉǴÍḰĹḾŃÓṔŔŚÚÝŹáćéǵíḱĺḿńóṕŕśúýź\-\'\.].*/, + "" + ), + props.user.location!.replace( + /[^A-Za-z0-9ÁĆÉǴÍḰĹḾŃÓṔŔŚÚÝŹáćéǵíḱĺḿńóṕŕśúýź\-\'\.\s].*/, + "" + ), ]; for (const city of maybeCityNames) { From a2e56314fe10cc4b45fb6a684473e1cd39a9982b Mon Sep 17 00:00:00 2001 From: naskya Date: Sat, 15 Apr 2023 01:01:36 +0900 Subject: [PATCH 3/6] prevent crashes due to timezone === null --- packages/client/src/pages/user/home.vue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/client/src/pages/user/home.vue b/packages/client/src/pages/user/home.vue index 84ee4b0a30..8c1c82d065 100644 --- a/packages/client/src/pages/user/home.vue +++ b/packages/client/src/pages/user/home.vue @@ -374,6 +374,8 @@ const timeForThem = $computed(() => { if (tzInfo.length == 0) continue; const tz = tzInfo[0].timezone; + if (!tz) continue; + const theirTime = new Date().toLocaleString("en-US", { timeZone: tz, hour12: false, From 06d56aeb41e8444ad34021cc69ff90910e21d45b Mon Sep 17 00:00:00 2001 From: naskya Date: Sat, 15 Apr 2023 01:10:59 +0900 Subject: [PATCH 4/6] update locale --- locales/en-US.yml | 2 +- locales/ja-JP.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/locales/en-US.yml b/locales/en-US.yml index d67e3b362f..d0a1525994 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -1426,7 +1426,7 @@ _profile: metadataContent: "Content" changeAvatar: "Change avatar" changeBanner: "Change banner" - locationDescription: "If you enter your city, it will display your local time to other users." + locationDescription: "If you enter your city first, it will display your local time to other users." _exportOrImport: allNotes: "All posts" followingList: "Followed users" diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 2e6795a785..b5c102a655 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -1423,7 +1423,7 @@ _profile: metadataContent: "内容" changeAvatar: "アバター画像を変更" changeBanner: "バナー画像を変更" - locationDescription: "正しく入力すると、あなたの現地時間が他のユーザーに表示されます。" + locationDescription: "英語表記の都市名から始まる内容を入力すると、現地時間がユーザーページに表示されます。" _exportOrImport: allNotes: "全ての投稿" followingList: "フォロー" From f531ed2ab223e9ee87037c892f028192b93f6e0b Mon Sep 17 00:00:00 2001 From: naskya Date: Sat, 15 Apr 2023 01:37:53 +0900 Subject: [PATCH 5/6] fix a bug --- packages/client/src/pages/user/home.vue | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/client/src/pages/user/home.vue b/packages/client/src/pages/user/home.vue index 8c1c82d065..c3d73b5731 100644 --- a/packages/client/src/pages/user/home.vue +++ b/packages/client/src/pages/user/home.vue @@ -363,10 +363,12 @@ const timeForThem = $computed(() => { /[^A-Za-zÁĆÉǴÍḰĹḾŃÓṔŔŚÚÝŹáćéǵíḱĺḿńóṕŕśúýź\-\'\.].*/, "" ), - props.user.location!.replace( - /[^A-Za-z0-9ÁĆÉǴÍḰĹḾŃÓṔŔŚÚÝŹáćéǵíḱĺḿńóṕŕśúýź\-\'\.\s].*/, - "" - ), + props.user + .location!.replace( + /[^A-Za-z0-9ÁĆÉǴÍḰĹḾŃÓṔŔŚÚÝŹáćéǵíḱĺḿńóṕŕśúýź\-\'\.\s].*/, + "" + ) + .trim(), ]; for (const city of maybeCityNames) { From 429b926fcfa30f54bffafaa1c693cf370ab27522 Mon Sep 17 00:00:00 2001 From: naskya Date: Sat, 15 Apr 2023 01:41:49 +0900 Subject: [PATCH 6/6] change regex priority --- packages/client/src/pages/user/home.vue | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/client/src/pages/user/home.vue b/packages/client/src/pages/user/home.vue index c3d73b5731..af3a384316 100644 --- a/packages/client/src/pages/user/home.vue +++ b/packages/client/src/pages/user/home.vue @@ -355,20 +355,20 @@ const age = $computed(() => { const timeForThem = $computed(() => { const maybeCityNames = [ props.user.location!, - props.user.location!.replace( - /[^A-Za-zÁĆÉǴÍḰĹḾŃÓṔŔŚÚÝŹáćéǵíḱĺḿńóṕŕśúýź].*/, - "" - ), - props.user.location!.replace( - /[^A-Za-zÁĆÉǴÍḰĹḾŃÓṔŔŚÚÝŹáćéǵíḱĺḿńóṕŕśúýź\-\'\.].*/, - "" - ), props.user .location!.replace( /[^A-Za-z0-9ÁĆÉǴÍḰĹḾŃÓṔŔŚÚÝŹáćéǵíḱĺḿńóṕŕśúýź\-\'\.\s].*/, "" ) .trim(), + props.user.location!.replace( + /[^A-Za-zÁĆÉǴÍḰĹḾŃÓṔŔŚÚÝŹáćéǵíḱĺḿńóṕŕśúýź\-\'\.].*/, + "" + ), + props.user.location!.replace( + /[^A-Za-zÁĆÉǴÍḰĹḾŃÓṔŔŚÚÝŹáćéǵíḱĺḿńóṕŕśúýź].*/, + "" + ), ]; for (const city of maybeCityNames) {