From 4e9115ab0598d0b12c53560309964984e7c2148f Mon Sep 17 00:00:00 2001 From: Valerii Sidorenko Date: Mon, 30 Sep 2024 09:50:39 +0200 Subject: [PATCH] fix(dateTimeParse): parse 0 as valid dateTime --- src/parser/parser.test.ts | 5 +++++ src/parser/parser.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/parser/parser.test.ts b/src/parser/parser.test.ts index 98f24d3..bfedf59 100644 --- a/src/parser/parser.test.ts +++ b/src/parser/parser.test.ts @@ -54,6 +54,11 @@ describe('Parser', () => { expect(Boolean(date)).toEqual(false); }); + it('should return DateTime in case of 0 input arg', () => { + const date = dateTimeParse(0)?.toISOString(); + expect(date).toEqual('1970-01-01T00:00:00.000Z'); + }); + test.each<[string | undefined, string]>([ ['ru', '07 авг. 2021'], ['en', '07 Aug 2021'], diff --git a/src/parser/parser.ts b/src/parser/parser.ts index 7450c9c..0b4c9c4 100644 --- a/src/parser/parser.ts +++ b/src/parser/parser.ts @@ -46,7 +46,7 @@ export const dateTimeParse: DateTimeParser = ( input, options, ): DateTime | undefined => { - if (!input) { + if (input === undefined) { return undefined; }