merge-upstream-5.0.1 #66

Merged
778a69cd merged 80 commits from merge-upstream-5.0.1 into main 2024-12-26 12:55:41 +01:00
2 changed files with 41 additions and 74 deletions
Showing only changes of commit 3c0db7877c - Show all commits

View file

@ -3,14 +3,6 @@
<span>{{ <span>{{
formatDateTimeString(beginsOn, timezoneToShow, showStartTime) formatDateTimeString(beginsOn, timezoneToShow, showStartTime)
}}</span> }}</span>
<br />
<o-switch
size="small"
v-model="showLocalTimezone"
v-if="differentFromUserTimezone"
>
{{ singleTimeZone }}
</o-switch>
</p> </p>
<!-- endsOn is set and isSameDay() --> <!-- endsOn is set and isSameDay() -->
<template v-else-if="isSameDay()"> <template v-else-if="isSameDay()">
@ -18,24 +10,16 @@
<span>{{ <span>{{
t("On {date} from {startTime} to {endTime}", { t("On {date} from {startTime} to {endTime}", {
date: formatDate(beginsOn), date: formatDate(beginsOn),
startTime: formatTime(beginsOn, timezoneToShow), startTime: formatTime(beginsOn),
endTime: formatTime(endsOn, timezoneToShow), endTime: formatTime(endsOn),
}) })
}}</span> }}</span>
<br />
<o-switch
size="small"
v-model="showLocalTimezone"
v-if="differentFromUserTimezone"
>
{{ singleTimeZone }}
</o-switch>
</p> </p>
<p v-else-if="showStartTime && !showEndTime"> <p v-else-if="showStartTime && !showEndTime">
{{ {{
t("On {date} starting at {startTime}", { t("On {date} starting at {startTime}", {
date: formatDate(beginsOn), date: formatDate(beginsOn),
startTime: formatTime(beginsOn, timezoneToShow), startTime: formatTime(beginsOn),
}) })
}} }}
</p> </p>
@ -43,7 +27,7 @@
{{ {{
t("On {date} ending at {endTime}", { t("On {date} ending at {endTime}", {
date: formatDate(beginsOn), date: formatDate(beginsOn),
endTime: formatTime(endsOn, timezoneToShow), endTime: formatTime(endsOn),
}) })
}} }}
</p> </p>
@ -57,39 +41,23 @@
{{ {{
t("From the {startDate} at {startTime} to the {endDate} at {endTime}", { t("From the {startDate} at {startTime} to the {endDate} at {endTime}", {
startDate: formatDate(beginsOn), startDate: formatDate(beginsOn),
startTime: formatTime(beginsOn, timezoneToShow), startTime: formatTime(beginsOn),
endDate: formatDate(endsOn), endDate: formatDate(endsOn),
endTime: formatTime(endsOn, timezoneToShow), endTime: formatTime(endsOn),
}) })
}} }}
</span> </span>
<br />
<o-switch
size="small"
v-model="showLocalTimezone"
v-if="differentFromUserTimezone"
>
{{ multipleTimeZones }}
</o-switch>
</p> </p>
<p v-else-if="showStartTime && !showEndTime"> <p v-else-if="showStartTime && !showEndTime">
<span> <span>
{{ {{
t("From the {startDate} at {startTime} to the {endDate}", { t("From the {startDate} at {startTime} to the {endDate}", {
startDate: formatDate(beginsOn), startDate: formatDate(beginsOn),
startTime: formatTime(beginsOn, timezoneToShow), startTime: formatTime(beginsOn),
endDate: formatDate(endsOn), endDate: formatDate(endsOn),
}) })
}} }}
</span> </span>
<br />
<o-switch
size="small"
v-model="showLocalTimezone"
v-if="differentFromUserTimezone"
>
{{ singleTimeZone }}
</o-switch>
</p> </p>
<p v-else-if="!showStartTime && showEndTime"> <p v-else-if="!showStartTime && showEndTime">
<span> <span>
@ -97,18 +65,10 @@
t("From the {startDate} to the {endDate} at {endTime}", { t("From the {startDate} to the {endDate} at {endTime}", {
startDate: formatDate(beginsOn), startDate: formatDate(beginsOn),
endDate: formatDate(endsOn), endDate: formatDate(endsOn),
endTime: formatTime(endsOn, timezoneToShow), endTime: formatTime(endsOn),
}) })
}} }}
</span> </span>
<br />
<o-switch
size="small"
v-model="showLocalTimezone"
v-if="differentFromUserTimezone"
>
{{ singleTimeZone }}
</o-switch>
</p> </p>
<p v-else> <p v-else>
{{ {{
@ -118,6 +78,13 @@
}) })
}} }}
</p> </p>
<o-switch
size="small"
v-model="showLocalTimezone"
v-if="differentFromUserTimezone"
>
{{ singleTimeZone }}
</o-switch>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { import {
@ -163,33 +130,43 @@ const userActualTimezone = computed((): string => {
}); });
const formatDate = (value: string): string | undefined => { const formatDate = (value: string): string | undefined => {
return formatDateString(value); return formatDateString(value, timezoneToShow.value ?? "Etc/UTC");
}; };
const formatTime = ( const formatTime = (value: string): string | undefined => {
value: string, return formatTimeString(value, timezoneToShow.value ?? "Etc/UTC");
timezone: string | undefined = undefined
): string | undefined => {
return formatTimeString(value, timezone ?? "Etc/UTC");
}; };
// We need to compare date after the offset is applied
// Because some date can be in the same day in a time zone, but different day in another.
// Example : From 2025-11-30 at 23:00 to 2025-12-01 01:00 in Asia/Shanghai (different days)
// It is from 2025-11-30 at 16:00 to 2025-11-30 at 18:00 in Europe/Paris (same day)
const isSameDay = (): boolean => { const isSameDay = (): boolean => {
if (!props.endsOn) return false; if (!props.endsOn) return false;
const offset =
getTimezoneOffset(timezoneToShow.value ?? "Etc/UTC", new Date()) /
(60 * 1000);
const beginsOnOffset = new Date(props.beginsOn);
beginsOnOffset.setUTCMinutes(beginsOnOffset.getUTCMinutes() + offset);
const endsOnOffset = new Date(props.endsOn);
endsOnOffset.setUTCMinutes(endsOnOffset.getUTCMinutes() + offset);
return ( return (
beginsOnDate.value.toDateString() === new Date(props.endsOn).toDateString() beginsOnOffset.getUTCFullYear() === endsOnOffset.getUTCFullYear() &&
beginsOnOffset.getUTCMonth() === endsOnOffset.getUTCMonth() &&
beginsOnOffset.getUTCDate() === endsOnOffset.getUTCDate()
); );
}; };
const beginsOnDate = computed((): Date => {
return new Date(props.beginsOn);
});
const differentFromUserTimezone = computed((): boolean => { const differentFromUserTimezone = computed((): boolean => {
return ( return (
!!props.timezone && !!props.timezone &&
!!userActualTimezone.value && !!userActualTimezone.value &&
getTimezoneOffset(props.timezone, beginsOnDate.value) !== getTimezoneOffset(props.timezone, new Date()) !==
getTimezoneOffset(userActualTimezone.value, beginsOnDate.value) && getTimezoneOffset(userActualTimezone.value, new Date()) &&
props.timezone !== userActualTimezone.value props.timezone !== userActualTimezone.value
); );
}); });
@ -204,15 +181,4 @@ const singleTimeZone = computed((): string => {
timezone: timezoneToShow.value, timezone: timezoneToShow.value,
}); });
}); });
const multipleTimeZones = computed((): string => {
if (showLocalTimezone.value) {
return t("Local times ({timezone})", {
timezone: timezoneToShow.value,
});
}
return t("Times in your timezone ({timezone})", {
timezone: timezoneToShow.value,
});
});
</script> </script>

View file

@ -8,12 +8,13 @@ function formatDateISOStringWithoutTime(value: string): string {
return parseDateTime(value).toISOString().split("T")[0]; return parseDateTime(value).toISOString().split("T")[0];
} }
function formatDateString(value: string): string { function formatDateString(value: string, timeZone?: string): string {
return parseDateTime(value).toLocaleString(locale(), { return parseDateTime(value).toLocaleString(locale(), {
weekday: "long", weekday: "long",
year: "numeric", year: "numeric",
month: "long", month: "long",
day: "numeric", day: "numeric",
timeZone: timeZone,
}); });
} }
@ -21,7 +22,7 @@ function formatTimeString(value: string, timeZone?: string): string {
return parseDateTime(value).toLocaleTimeString(locale(), { return parseDateTime(value).toLocaleTimeString(locale(), {
hour: "numeric", hour: "numeric",
minute: "numeric", minute: "numeric",
timeZone, timeZone: timeZone,
}); });
} }