fix: issue where a end time can be overflowing (#761)

This commit is contained in:
Carlos Valente
2024-02-06 11:42:28 +01:00
committed by GitHub
parent 965a7092d9
commit 467b595375
10 changed files with 94 additions and 13 deletions
@@ -93,6 +93,17 @@ describe('validateTimes()', () => {
expect(timeEnd).toBe(10);
expect(duration).toBe(10);
});
it('ensures values dont overflow dayMs', () => {
const start = 86100000;
const endOverDay = 87420000;
const durationNormal = 1320000;
const { timeStart, timeEnd, duration } = validateTimes(start, endOverDay, durationNormal);
expect(timeStart).toBe(start);
expect(timeEnd).toBe(1020000);
expect(duration).toBe(durationNormal);
});
});
describe('calculateDuration()', () => {
@@ -52,9 +52,9 @@ function convertToInteger(value: unknown): number {
* @param _duration
*/
export function validateTimes(_start?: unknown, _end?: unknown, _duration?: unknown) {
const timeStart = convertToInteger(_start);
const timeEnd = convertToInteger(_end);
const duration = convertToInteger(_duration);
const timeStart = convertToInteger(_start) % dayInMs;
const timeEnd = convertToInteger(_end) % dayInMs;
const duration = convertToInteger(_duration) % dayInMs;
if (_start != null && _end != null) {
// Case 1. if we have start and end, duration must be derived