Skip to content

Commit c75f696

Browse files
committed
test(time):asserted integer output for sub-second precision inputs
Signed-off-by: Himanshujha7 <tigmanshujah@gmail.com>
1 parent 022ebb1 commit c75f696

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

utils/time.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ 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+
expect(Number.isInteger(getSecondsUntilUTCMidnight())).toBe(true);
71+
});
72+
6673
});
6774

6875
it('returns positive seconds for every hour of day', () => {
@@ -145,6 +152,13 @@ describe('getSecondsUntilMidnightInTimezone', () => {
145152
}
146153
});
147154

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

0 commit comments

Comments
 (0)