Skip to content

Commit f2a04af

Browse files
committed
Fix the date issue due to the timezone problem.
1 parent 405d4b2 commit f2a04af

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/components/Events/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,18 @@ const formatDate = (dateStr: string, endDateStr?: string): string => {
6969
month: "long",
7070
day: "numeric",
7171
};
72-
const startDate = new Date(dateStr).toLocaleDateString("en-US", options);
72+
73+
// Parse as local date to avoid timezone issues
74+
// (new Date("YYYY-MM-DD") parses as UTC, causing off-by-one day errors in some timezones)
75+
const parseLocalDate = (str: string): Date => {
76+
const [year, month, day] = str.split("-").map(Number);
77+
return new Date(year, month - 1, day);
78+
};
79+
80+
const startDate = parseLocalDate(dateStr).toLocaleDateString("en-US", options);
7381

7482
if (endDateStr) {
75-
const endDate = new Date(endDateStr).toLocaleDateString("en-US", options);
83+
const endDate = parseLocalDate(endDateStr).toLocaleDateString("en-US", options);
7684
return `${startDate} - ${endDate}`;
7785
}
7886

0 commit comments

Comments
 (0)