From 818bdcbd18406b9dd7ea68f2ad0a3e589b064d70 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 3fa01d9c0..ef5a6544d 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 4fc833c84cfbb6e3e08c30efc6ad4d1437eefef7 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 ef5a6544d..84ee4b0a3 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 d73a87b1b9eae4616077e7e530465c7b7d227e6c 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 84ee4b0a3..8c1c82d06 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 81a8550d8fbf5697766cb2036260d9f1d9c8caa3 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 d67e3b362..d0a152599 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 2e6795a78..b5c102a65 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 3ecd3cf6a16137f00120c428afab1995021b20f2 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 8c1c82d06..c3d73b573 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 ec96805ddc8b2423466a5f4edd4f8c1556360ab9 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 c3d73b573..af3a38431 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) {