Skip to content

Commit

Permalink
fix(gatsby): quick check if string looks like a date (#12700)
Browse files Browse the repository at this point in the history
## Description
Checks if strings start with 4 numbers as all ISO 8601 date-time are using YYYY syntax

## Related Issues
#12692
  • Loading branch information
wardpeet authored Mar 21, 2019
1 parent 95cf45a commit 22a2689
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/gatsby/src/schema/types/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@ const GraphQLDate = new GraphQLScalarType({
// Check if this is a date.
// All the allowed ISO 8601 date-time formats used.
function isDate(value) {
// quick check if value does not look like a date
if (typeof value === `number` || !/^\d{4}/.test(value)) {
return false
}

const momentDate = moment.utc(value, ISO_8601_FORMAT, true)
return momentDate.isValid() && typeof value !== `number`
return momentDate.isValid()
}

const formatDate = ({
Expand Down

0 comments on commit 22a2689

Please sign in to comment.