Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix parseISO not returning Invalid Date when there are space(s) in passed string #1791

Merged
merged 6 commits into from Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/parseISO/index.js
Expand Up @@ -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.
imballinst marked this conversation as resolved.
Show resolved Hide resolved
// [date], [time], or [date, time].
if (array.length > 2) {
return dateStrings
}

if (/:/.test(array[0])) {
dateStrings.date = null
timeString = array[0]
Expand Down
14 changes: 14 additions & 0 deletions src/parseISO/test.js
Expand Up @@ -286,6 +286,14 @@ describe('parseISO', () => {
})
})

describe('date', () => {
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))
})
})

describe('time', () => {
it('parses 24:00 as midnight of the next day', () => {
const result = parseISO('2014-02-11T24:00')
Expand Down Expand Up @@ -321,6 +329,12 @@ describe('parseISO', () => {
assert(result instanceof Date)
assert(isNaN(result))
})

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))
})
})

describe('timezones', () => {
Expand Down