From 55504e2c332a4b099692899ee2587302b470c6a1 Mon Sep 17 00:00:00 2001 From: Ward Peeters Date: Wed, 20 Mar 2019 22:06:20 +0100 Subject: [PATCH] fix(gatsby): quick check if string looks like a date --- packages/gatsby/src/schema/types/date.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/gatsby/src/schema/types/date.js b/packages/gatsby/src/schema/types/date.js index 230df593029dc..b83c425670bb8 100644 --- a/packages/gatsby/src/schema/types/date.js +++ b/packages/gatsby/src/schema/types/date.js @@ -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 = ({