Skip to content

Commit bb27ef6

Browse files
fix(server): make startOfToday IST-aware
The client picks 'today' in IST local time but the server's startOfToday() returned UTC midnight. For an IST user adding an expense between 00:00 and 05:30 IST, the expense got stored on UTC day X, and any later /expenses/today query (which used UTC again) hit UTC day X+1 — empty. Meanwhile /expenses/by-date?date=<IST-today> worked because the client sends the IST calendar date. Shift now() by +5:30 before reading UTC components so 'today' on the server matches what the IST client sees.
1 parent ee6906e commit bb27ef6

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

server/src/shared/lib/date.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
// UTC midnight to avoid TZ drift on day boundaries.
1+
// UTC midnight of "today in IST" — the project ships only to IST users, and
2+
// the client picks dates in IST. Without this shift, expenses added between
3+
// 00:00 and 05:30 IST land on the previous UTC day, so /expenses/today
4+
// silently misses them while /expenses/by-date?date=<IST-today> finds them.
5+
const IST_OFFSET_MS = 5.5 * 60 * 60 * 1000;
26
export const startOfToday = (): Date => {
3-
const now = new Date();
4-
return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
7+
const istNow = new Date(Date.now() + IST_OFFSET_MS);
8+
return new Date(Date.UTC(istNow.getUTCFullYear(), istNow.getUTCMonth(), istNow.getUTCDate()));
59
};
610

711
export const startOfTomorrow = (): Date => {

0 commit comments

Comments
 (0)