Merge pull request 'feat: improved local time display' (#9851) from naskya/calckey:localtime-improvement into develop

Reviewed-on: https://codeberg.org/calckey/calckey/pulls/9851
This commit is contained in:
Kainoa Kanter 2023-04-14 22:32:34 +00:00
commit 64a737d001
3 changed files with 37 additions and 14 deletions

View File

@ -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"

View File

@ -1423,7 +1423,7 @@ _profile:
metadataContent: "内容"
changeAvatar: "アバター画像を変更"
changeBanner: "バナー画像を変更"
locationDescription: "正しく入力すると、あなたの現地時間が他のユーザーに表示されます。"
locationDescription: "英語表記の都市名から始まる内容を入力すると、現地時間がユーザーページに表示されます。"
_exportOrImport:
allNotes: "全ての投稿"
followingList: "フォロー"

View File

@ -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) {