fix: ensure convertToDate() convert null date to undefined
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 13 Jan 2024 15:16:24 +0000 (16:16 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 13 Jan 2024 15:16:24 +0000 (16:16 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/utils/Utils.ts
tests/utils/Utils.test.ts

index 6f4517bee1b5aaf213698fbb976c421660ef1f6d..9d2b92fa4239856b0c064d062168dc5cb121a93d 100644 (file)
@@ -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
index 0a8a488282bfe99c01b6f7d5c0fc81b2aa4934f6..703bfec0aade94ab48f4e292f917744871b5d427 100644 (file)
@@ -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'))