Skip to content

Commit 30fcc3e

Browse files
authored
fix(time-range): use UTC date methods for 90-day backfill calculation (#897)
## Summary - Use `getUTCDate()`/`setUTCDate()` instead of `getDate()`/`setDate()` for the 90-day date backfill in `timeRangeToApiParams()` - The input is a UTC ISO 8601 string, so date arithmetic should use UTC methods to avoid off-by-one-day errors in non-UTC timezones Flagged by Cursor Bugbot on #892 ([comment](#892 (comment))).
1 parent e37329b commit 30fcc3e

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

src/lib/time-range.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ export function timeRangeToApiParams(range: TimeRange): TimeRangeApiParams {
363363
params.end = new Date().toISOString();
364364
} else if (params.end && !params.start) {
365365
const endDate = new Date(params.end);
366-
endDate.setDate(endDate.getDate() - 90);
366+
endDate.setUTCDate(endDate.getUTCDate() - 90);
367367
params.start = endDate.toISOString();
368368
}
369369
return params;

test/lib/time-range.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ describe("timeRangeToApiParams", () => {
297297
expect(params.start).toBeDefined();
298298
const startDate = new Date(params.start!);
299299
const expectedStart = new Date("2024-02-01T23:59:59Z");
300-
expectedStart.setDate(expectedStart.getDate() - 90);
300+
expectedStart.setUTCDate(expectedStart.getUTCDate() - 90);
301301
expect(startDate.toISOString()).toBe(expectedStart.toISOString());
302302
});
303303
});

0 commit comments

Comments
 (0)