Skip to content

Commit 19cae3e

Browse files
authored
test(utils): check boundary robustness of time normalization (Variation 2) (JhaSourav07#1877)
## Description Adds a new test block verifying the time normalization utility converts timestamps cleanly to target timezone offsets without calendar shifting. Closes JhaSourav07#1559 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [x] 🕐 Pillar 3 — Timezone Logic Optimization - [ ] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A -- no SVG changes. ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [ ] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have started the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [ ] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [ ] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 08300d8 + 33c252a commit 19cae3e

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

utils/time.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,53 @@ describe('getSecondsUntilUTCMidnight — sliding window boundary robustness', ()
233233
}
234234
});
235235
});
236+
237+
describe('getSecondsUntilMidnightInTimezone — extreme timezone offset boundary robustness', () => {
238+
beforeEach(() => {
239+
vi.useFakeTimers();
240+
});
241+
242+
afterEach(() => {
243+
vi.useRealTimers();
244+
});
245+
246+
it('converts timestamp cleanly to target offset without calendar shifting (UTC+5:30)', () => {
247+
// UTC 2024-06-15T18:30:00Z = 2024-06-16T00:00:00 in Asia/Kolkata (UTC+5:30)
248+
// So exactly at local midnight → 86400 seconds remaining
249+
vi.setSystemTime(new Date('2024-06-15T18:30:00.000Z'));
250+
251+
expect(getSecondsUntilMidnightInTimezone('Asia/Kolkata')).toBe(86400);
252+
});
253+
254+
it('converts timestamp cleanly to target offset without calendar shifting (UTC+14)', () => {
255+
// UTC 2024-06-14T10:00:00Z = 2024-06-15T00:00:00 in Pacific/Kiritimati (UTC+14)
256+
// Exactly local midnight → 86400 seconds remaining, no date shift
257+
vi.setSystemTime(new Date('2024-06-14T10:00:00.000Z'));
258+
259+
expect(getSecondsUntilMidnightInTimezone('Pacific/Kiritimati')).toBe(86400);
260+
});
261+
262+
it('converts timestamp cleanly to target offset without calendar shifting (UTC-12)', () => {
263+
// UTC 2024-06-15T12:00:00Z = 2024-06-15T00:00:00 in Etc/GMT+12 (UTC-12)
264+
// Exactly local midnight → 86400 seconds remaining, no date shift
265+
vi.setSystemTime(new Date('2024-06-15T12:00:00.000Z'));
266+
267+
expect(getSecondsUntilMidnightInTimezone('Etc/GMT+12')).toBe(86400);
268+
});
269+
270+
it('handles a timestamp near year-end boundary without calendar shifting (UTC+14)', () => {
271+
// UTC 2023-12-31T10:00:00Z = 2024-01-01T00:00:00 in Pacific/Kiritimati
272+
// Crosses year boundary cleanly → 86400 seconds remaining
273+
vi.setSystemTime(new Date('2023-12-31T10:00:00.000Z'));
274+
275+
expect(getSecondsUntilMidnightInTimezone('Pacific/Kiritimati')).toBe(86400);
276+
});
277+
278+
it('handles a timestamp near year-end boundary without calendar shifting (UTC-11)', () => {
279+
// UTC 2024-01-01T11:00:00Z = 2024-01-01T00:00:00 in Pacific/Midway (UTC-11)
280+
// Crosses year boundary cleanly → 86400 seconds remaining
281+
vi.setSystemTime(new Date('2024-01-01T11:00:00.000Z'));
282+
283+
expect(getSecondsUntilMidnightInTimezone('Pacific/Midway')).toBe(86400);
284+
});
285+
});

0 commit comments

Comments
 (0)