Skip to content

Commit 2f0cd70

Browse files
committed
fix(web): update date parsing to handle local timezone before converting to UTC
1 parent d704c92 commit 2f0cd70

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

packages/web/src/views/Today/util/date-route.util.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export const parseDateFromUrl = (
1414
}
1515

1616
// Use strict parsing to ensure exact format match
17-
// Parse as UTC to avoid timezone issues
18-
const parsed = dayjs.utc(dateString, YEAR_MONTH_DAY_FORMAT, true);
17+
// Parse in local timezone first, then convert to UTC to avoid timezone issues
18+
const parsed = dayjs(dateString, YEAR_MONTH_DAY_FORMAT, true).utc();
1919

2020
if (!parsed.isValid()) {
2121
return null;
@@ -34,8 +34,8 @@ export const correctInvalidDate = (dateString: string): dayjs.Dayjs | null => {
3434
return null;
3535
}
3636

37-
// Try to parse the date string as UTC
38-
const parsed = dayjs.utc(dateString, YEAR_MONTH_DAY_FORMAT, true);
37+
// Try to parse the date string in local timezone first, then convert to UTC
38+
const parsed = dayjs(dateString, YEAR_MONTH_DAY_FORMAT, true).utc();
3939

4040
if (parsed.isValid()) {
4141
return parsed;
@@ -70,24 +70,24 @@ export const correctInvalidDate = (dateString: string): dayjs.Dayjs | null => {
7070
if (isNaN(day) || day < 1) {
7171
correctedDay = 1;
7272
} else {
73-
// Get the last day of the corrected month
74-
const lastDayOfMonth = dayjs
75-
.utc()
73+
// Get the last day of the corrected month in local timezone, then convert to UTC
74+
const lastDayOfMonth = dayjs()
7675
.year(year)
7776
.month(correctedMonth - 1)
7877
.endOf("month")
78+
.utc()
7979
.date();
8080
if (day > lastDayOfMonth) {
8181
correctedDay = lastDayOfMonth;
8282
}
8383
}
8484

85-
// Create corrected date as UTC
86-
const corrected = dayjs
87-
.utc()
85+
// Create corrected date in local timezone first, then convert to UTC
86+
const corrected = dayjs()
8887
.year(year)
8988
.month(correctedMonth - 1)
90-
.date(correctedDay);
89+
.date(correctedDay)
90+
.utc();
9191

9292
if (!corrected.isValid()) {
9393
return null;

0 commit comments

Comments
 (0)