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: "フォロー" diff --git a/packages/client/src/pages/user/home.vue b/packages/client/src/pages/user/home.vue index 3fa01d9c06..af3a384316 100644 --- a/packages/client/src/pages/user/home.vue +++ b/packages/client/src/pages/user/home.vue @@ -353,18 +353,41 @@ 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-z0-9ÁĆÉǴÍḰĹḾŃÓṔŔŚÚÝŹáćéǵíḱĺḿńóṕŕśúýź\-\'\.\s].*/, + "" + ) + .trim(), + props.user.location!.replace( + /[^A-Za-zÁĆÉǴÍḰĹḾŃÓṔŔŚÚÝŹáćéǵíḱĺḿńóṕŕśúýź\-\'\.].*/, + "" + ), + props.user.location!.replace( + /[^A-Za-zÁĆÉǴÍḰĹḾŃÓṔŔŚÚÝŹáćéǵíḱĺḿńóṕŕśúýź].*/, + "" + ), + ]; + + for (const city of maybeCityNames) { + let tzInfo = cityTimezones.lookupViaCity(city); + if (tzInfo.length == 0) continue; + + const tz = tzInfo[0].timezone; + if (!tz) continue; + + 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) {