From 3c0db7877c94b2ef3abff682bfb62ccc8cf6717d Mon Sep 17 00:00:00 2001
From: Massedil
Date: Wed, 6 Nov 2024 18:22:58 +0100
Subject: [PATCH] Issue #1511: Date display problem :
- the time zone is used to calculate the date
- use the offset to know if beginsOn and endsOn are the same day
- refactor the
Solves, for example, this display problem :
The date range "2024-12-31 17:45 to 2025-01-01 01:00" in the Asia/Shanghai time zone (spanning different years and days) is equivalent to "2024-12-31 at 10:45 to 2024-12-31 at 18:00" in the Europe/Paris time zone (same year and same day).
---
src/components/Event/EventFullDate.vue | 110 +++++++++----------------
src/filters/datetime.ts | 5 +-
2 files changed, 41 insertions(+), 74 deletions(-)
diff --git a/src/components/Event/EventFullDate.vue b/src/components/Event/EventFullDate.vue
index 30354084d..74494df8f 100644
--- a/src/components/Event/EventFullDate.vue
+++ b/src/components/Event/EventFullDate.vue
@@ -3,14 +3,6 @@
{{
formatDateTimeString(beginsOn, timezoneToShow, showStartTime)
}}
-
-
- {{ singleTimeZone }}
-
@@ -18,24 +10,16 @@
{{
t("On {date} from {startTime} to {endTime}", {
date: formatDate(beginsOn),
- startTime: formatTime(beginsOn, timezoneToShow),
- endTime: formatTime(endsOn, timezoneToShow),
+ startTime: formatTime(beginsOn),
+ endTime: formatTime(endsOn),
})
}}
-
-
- {{ singleTimeZone }}
-
{{
t("On {date} starting at {startTime}", {
date: formatDate(beginsOn),
- startTime: formatTime(beginsOn, timezoneToShow),
+ startTime: formatTime(beginsOn),
})
}}
@@ -43,7 +27,7 @@
{{
t("On {date} ending at {endTime}", {
date: formatDate(beginsOn),
- endTime: formatTime(endsOn, timezoneToShow),
+ endTime: formatTime(endsOn),
})
}}
@@ -57,39 +41,23 @@
{{
t("From the {startDate} at {startTime} to the {endDate} at {endTime}", {
startDate: formatDate(beginsOn),
- startTime: formatTime(beginsOn, timezoneToShow),
+ startTime: formatTime(beginsOn),
endDate: formatDate(endsOn),
- endTime: formatTime(endsOn, timezoneToShow),
+ endTime: formatTime(endsOn),
})
}}
-
-
- {{ multipleTimeZones }}
-
{{
t("From the {startDate} at {startTime} to the {endDate}", {
startDate: formatDate(beginsOn),
- startTime: formatTime(beginsOn, timezoneToShow),
+ startTime: formatTime(beginsOn),
endDate: formatDate(endsOn),
})
}}
-
-
- {{ singleTimeZone }}
-
@@ -97,18 +65,10 @@
t("From the {startDate} to the {endDate} at {endTime}", {
startDate: formatDate(beginsOn),
endDate: formatDate(endsOn),
- endTime: formatTime(endsOn, timezoneToShow),
+ endTime: formatTime(endsOn),
})
}}
-
-
- {{ singleTimeZone }}
-
{{
@@ -118,6 +78,13 @@
})
}}
+
+ {{ singleTimeZone }}
+
diff --git a/src/filters/datetime.ts b/src/filters/datetime.ts
index a11933e21..c1f812739 100644
--- a/src/filters/datetime.ts
+++ b/src/filters/datetime.ts
@@ -8,12 +8,13 @@ function formatDateISOStringWithoutTime(value: string): string {
return parseDateTime(value).toISOString().split("T")[0];
}
-function formatDateString(value: string): string {
+function formatDateString(value: string, timeZone?: string): string {
return parseDateTime(value).toLocaleString(locale(), {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
+ timeZone: timeZone,
});
}
@@ -21,7 +22,7 @@ function formatTimeString(value: string, timeZone?: string): string {
return parseDateTime(value).toLocaleTimeString(locale(), {
hour: "numeric",
minute: "numeric",
- timeZone,
+ timeZone: timeZone,
});
}