Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
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
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'))