From f1a656d1ebbce8257101fd3296261195f9e2c246 Mon Sep 17 00:00:00 2001 From: Try Ajitiono Date: Wed, 20 May 2020 21:59:45 +0700 Subject: [PATCH 1/6] fix parseISO not returning Invalid Date when there are space(s) Signed-off-by: Try Ajitiono --- src/parseISO/index.js | 6 ++++++ src/parseISO/test.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/parseISO/index.js b/src/parseISO/index.js index f9c57f707c..490081f632 100644 --- a/src/parseISO/index.js +++ b/src/parseISO/index.js @@ -154,6 +154,12 @@ function splitDateString(dateString) { var array = dateString.split(patterns.dateTimeDelimiter) var timeString + // The regex match should only return at maximum two array. + // [date], [time], or [date, time]. + if (array.length > 2) { + return dateStrings + } + if (/:/.test(array[0])) { dateStrings.date = null timeString = array[0] diff --git a/src/parseISO/test.js b/src/parseISO/test.js index e9618ad59b..debf97d380 100644 --- a/src/parseISO/test.js +++ b/src/parseISO/test.js @@ -321,6 +321,12 @@ describe('parseISO', () => { assert(result instanceof Date) assert(isNaN(result)) }) + + it('returns `Invalid Date` when time contains space', () => { + const result = parseISO('2014-02-11T21 basketball') + assert(result instanceof Date) + assert(isNaN(result)) + }) }) describe('timezones', () => { From 4708065356deb6e346775c13e3e24cb98004a6cd Mon Sep 17 00:00:00 2001 From: Try Ajitiono Date: Wed, 20 May 2020 22:04:49 +0700 Subject: [PATCH 2/6] separate test in describe Signed-off-by: Try Ajitiono --- src/parseISO/test.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/parseISO/test.js b/src/parseISO/test.js index debf97d380..937903d62c 100644 --- a/src/parseISO/test.js +++ b/src/parseISO/test.js @@ -286,6 +286,14 @@ describe('parseISO', () => { }) }) + describe('date', () => { + it('returns `Invalid Date` when date contains spaces', () => { + const result = parseISO('2014-02-11 basketball') + assert(result instanceof Date) + assert(isNaN(result)) + }) + }) + describe('time', () => { it('parses 24:00 as midnight of the next day', () => { const result = parseISO('2014-02-11T24:00') @@ -322,8 +330,8 @@ describe('parseISO', () => { assert(isNaN(result)) }) - it('returns `Invalid Date` when time contains space', () => { - const result = parseISO('2014-02-11T21 basketball') + it('returns `Invalid Date` when time contains spaces', () => { + const result = parseISO('21:59:00 basketball') assert(result instanceof Date) assert(isNaN(result)) }) From 582b6b8d79373b10c3f5a6b5a9a837a095bd989d Mon Sep 17 00:00:00 2001 From: Try Ajitiono Date: Wed, 20 May 2020 22:42:16 +0700 Subject: [PATCH 3/6] update comment and test Signed-off-by: Try Ajitiono --- src/parseISO/index.js | 2 +- src/parseISO/test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parseISO/index.js b/src/parseISO/index.js index 490081f632..2d7e6a0158 100644 --- a/src/parseISO/index.js +++ b/src/parseISO/index.js @@ -155,7 +155,7 @@ function splitDateString(dateString) { var timeString // The regex match should only return at maximum two array. - // [date], [time], or [date, time]. + // [date] or [date, time]. if (array.length > 2) { return dateStrings } diff --git a/src/parseISO/test.js b/src/parseISO/test.js index 937903d62c..ce07083a4a 100644 --- a/src/parseISO/test.js +++ b/src/parseISO/test.js @@ -331,7 +331,7 @@ describe('parseISO', () => { }) it('returns `Invalid Date` when time contains spaces', () => { - const result = parseISO('21:59:00 basketball') + const result = parseISO('2014-02-11T21:59:00 basketball') assert(result instanceof Date) assert(isNaN(result)) }) From 28ec6e9df303699b85f5dbb5aaba3bd1f352290b Mon Sep 17 00:00:00 2001 From: Try Ajitiono Date: Wed, 20 May 2020 22:45:43 +0700 Subject: [PATCH 4/6] add [time] Signed-off-by: Try Ajitiono --- src/parseISO/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parseISO/index.js b/src/parseISO/index.js index 2d7e6a0158..490081f632 100644 --- a/src/parseISO/index.js +++ b/src/parseISO/index.js @@ -155,7 +155,7 @@ function splitDateString(dateString) { var timeString // The regex match should only return at maximum two array. - // [date] or [date, time]. + // [date], [time], or [date, time]. if (array.length > 2) { return dateStrings } From edceccd958a5f261c890088b86161fe2be7a5e4d Mon Sep 17 00:00:00 2001 From: Try Ajitiono Date: Wed, 20 May 2020 22:46:22 +0700 Subject: [PATCH 5/6] fix test name Signed-off-by: Try Ajitiono --- src/parseISO/test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parseISO/test.js b/src/parseISO/test.js index ce07083a4a..3bed0ab105 100644 --- a/src/parseISO/test.js +++ b/src/parseISO/test.js @@ -287,7 +287,7 @@ describe('parseISO', () => { }) describe('date', () => { - it('returns `Invalid Date` when date contains spaces', () => { + it('returns `Invalid Date` when it contains spaces after the date', () => { const result = parseISO('2014-02-11 basketball') assert(result instanceof Date) assert(isNaN(result)) @@ -330,7 +330,7 @@ describe('parseISO', () => { assert(isNaN(result)) }) - it('returns `Invalid Date` when time contains spaces', () => { + it('returns `Invalid Date` when it contains spaces after the time', () => { const result = parseISO('2014-02-11T21:59:00 basketball') assert(result instanceof Date) assert(isNaN(result)) From 70aa7fe7bfe584f553bdc4cc53a133886332a23b Mon Sep 17 00:00:00 2001 From: Try Ajitiono Date: Fri, 17 Jul 2020 17:27:21 +0700 Subject: [PATCH 6/6] update comment --- src/parseISO/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parseISO/index.js b/src/parseISO/index.js index 490081f632..54d57c10d3 100644 --- a/src/parseISO/index.js +++ b/src/parseISO/index.js @@ -154,7 +154,7 @@ function splitDateString(dateString) { var array = dateString.split(patterns.dateTimeDelimiter) var timeString - // The regex match should only return at maximum two array. + // The regex match should only return at maximum two array elements. // [date], [time], or [date, time]. if (array.length > 2) { return dateStrings