From: Jérôme Benoit Date: Sat, 13 Jan 2024 15:16:24 +0000 (+0100) Subject: fix: ensure convertToDate() convert null date to undefined X-Git-Tag: v1.2.32~21 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=79fd697f69253d44e4b3df2b1edd7a73338d12b2;p=e-mobility-charging-stations-simulator.git fix: ensure convertToDate() convert null date to undefined Signed-off-by: Jérôme Benoit --- diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 6f4517be..9d2b92fa 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -77,9 +77,9 @@ export const isValidDate = (date: Date | number | undefined): date is Date | num export const convertToDate = ( value: Date | string | number | undefined | null -): Date | undefined | null => { +): Date | undefined => { if (value == null) { - return value + return undefined } if (isDate(value)) { return value diff --git a/tests/utils/Utils.test.ts b/tests/utils/Utils.test.ts index 0a8a4882..703bfec0 100644 --- a/tests/utils/Utils.test.ts +++ b/tests/utils/Utils.test.ts @@ -80,7 +80,7 @@ await describe('Utils test suite', async () => { await it('Verify convertToDate()', () => { expect(convertToDate(undefined)).toBe(undefined) - expect(convertToDate(null)).toBe(null) + expect(convertToDate(null)).toBe(undefined) expect(() => convertToDate('')).toThrow(new Error("Cannot convert to date: ''")) expect(() => convertToDate('00:70:61')).toThrow(new Error("Cannot convert to date: '00:70:61'")) expect(convertToDate(0)).toStrictEqual(new Date('1970-01-01T00:00:00.000Z'))