Skip to content

Commit 932af5e

Browse files
committed
refactor: Use client's preferred format for date and time instead of assuming it in the client-side code
Signed-off-by: Felicitas Pojtinger <felicitas@pojtinger.com>
1 parent dd7c3f7 commit 932af5e

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

assets/js/event-detail-modal.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,18 @@ customElements.define(
138138
day: "numeric",
139139
timeZone: data.timezone || undefined,
140140
};
141-
$("date").textContent = start.toLocaleDateString("en-CA", dateOpts);
141+
$("date").textContent = start.toLocaleDateString(undefined, dateOpts);
142142

143143
const timeOpts = {
144144
hour: "numeric",
145145
minute: "2-digit",
146146
timeZone: data.timezone || undefined,
147147
timeZoneName: data.timezone ? "short" : undefined,
148148
};
149-
let timeText = start.toLocaleTimeString("en-CA", timeOpts);
149+
let timeText = start.toLocaleTimeString(undefined, timeOpts);
150150
if (data.end_at) {
151151
const end = new Date(data.end_at);
152-
timeText += " – " + end.toLocaleTimeString("en-CA", timeOpts);
152+
timeText += " – " + end.toLocaleTimeString(undefined, timeOpts);
153153
}
154154
$("time").textContent = timeText;
155155

assets/js/events.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
export const formatEvent = (evt) => {
1+
export const formatEvent = (evt, api) => {
22
const start = new Date(evt.start_at);
33
const days = Math.ceil((start - new Date()) / 86400000);
44
return {
5+
apiId: evt.api_id,
56
name: evt.name || "VanLUG Meeting",
6-
date: start.toLocaleDateString("en-CA", {
7+
date: start.toLocaleDateString(undefined, {
78
weekday: "short",
89
month: "short",
910
day: "numeric",
1011
}),
11-
time: start.toLocaleTimeString("en-CA", {
12+
time: start.toLocaleTimeString(undefined, {
1213
hour: "numeric",
1314
minute: "2-digit",
1415
}),

assets/js/mastodon-feed.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const renderToot = (toot, data, { isFirst, isLast, inDrawer, profile }) => {
5353
avatar.alt = data.userDisplayName;
5454

5555
$("timestamp").textContent = new Date(toot.timestamp).toLocaleDateString(
56-
"en-CA",
56+
undefined,
5757
{ month: "short", day: "numeric" },
5858
);
5959

0 commit comments

Comments
 (0)