Skip to content

Commit 6c0074e

Browse files
authored
test(time):asserted integer output for sub-second precision inputs (JhaSourav07#1874)
## Description - Adds two test cases to `utils/time.test.ts` — one for `getSecondsUntilUTCMidnight` and one for `getSecondsUntilMidnightInTimezone` - Each test sets the clock to `23:59:59.999` (1 ms before midnight) and asserts `Number.isInteger(result) === true` - Explicitly verifies that `Math.floor` is applied correctly and sub-second remainders never leak into the return value Fixes JhaSourav07#733 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [X] 🛠️ Other (Bug fix, refactoring, docs) ## 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): ...`). - [x] 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. - [x] 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 c89a578 + 65df59f commit 6c0074e

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

utils/time.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ describe('getSecondsUntilUTCMidnight', () => {
6363

6464
expect(getSecondsUntilUTCMidnight()).toBe(64800); // 18 hours = 64800 s
6565
});
66+
67+
it('always returns an integer with sub-second precision input', () => {
68+
vi.setSystemTime(new Date('2024-06-15T23:59:59.999Z'));
69+
70+
const result = getSecondsUntilUTCMidnight();
71+
expect(Number.isInteger(result)).toBe(true);
72+
expect(result).toBe(0);
73+
});
6674
});
6775

6876
it('returns positive seconds for every hour of day', () => {
@@ -145,6 +153,15 @@ describe('getSecondsUntilMidnightInTimezone', () => {
145153
}
146154
});
147155

156+
it('always returns an integer with sub-second precision input', () => {
157+
// 2024-06-16T03:59:59.999Z is 23:59:59.999 in Etc/GMT+4 (UTC-4)
158+
vi.setSystemTime(new Date('2024-06-16T03:59:59.999Z'));
159+
160+
const result = getSecondsUntilMidnightInTimezone('Etc/GMT+4');
161+
expect(Number.isInteger(result)).toBe(true);
162+
expect(result).toBe(1);
163+
});
164+
148165
it('handles extreme timezone Etc/GMT-14 (UTC+14)', () => {
149166
// UTC 00:00 → local time 14:00 in UTC+14
150167
vi.setSystemTime(new Date('2024-06-15T00:00:00.000Z'));

0 commit comments

Comments
 (0)