Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions __tests__/useTime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@ describe('useTime', () => {
});
});

describe('sub-second time', () => {
beforeEach(() => jest.useFakeTimers());
afterEach(() => jest.useRealTimers());

test('does not round the current second up', () => {
jest.setSystemTime(getLocalDateAtTime(14, 30, 45, 500));
const { result } = renderHook(() => useTime());

expect(result.current.seconds).toBe(45);
expect(result.current.milliseconds).toBe(500);
});

test('does not roll minutes and hours over early', () => {
jest.setSystemTime(getLocalDateAtTime(14, 59, 59, 600));
const { result } = renderHook(() => useTime());

expect(result.current.hours).toBe(14);
expect(result.current.minutes).toBe(59);
expect(result.current.seconds).toBe(59);
});
});

describe('interval', () => {
beforeEach(() => jest.useFakeTimers());
afterEach(() => jest.useRealTimers());
Expand Down
2 changes: 1 addition & 1 deletion src/utils/Time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class Time {
seconds: secondsValue,
minutes,
hours,
} = Time.getTimeFromMilliseconds(milliseconds);
} = Time.getTimeFromMilliseconds(milliseconds, false);
let ampm: AMPMType = '';
let hoursValue = hours;

Expand Down