Skip to content

Commit

Permalink
fix: format date-time validation
Browse files Browse the repository at this point in the history
  • Loading branch information
sagold committed Jun 6, 2024
1 parent 94cf3ec commit 1096736
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 6 additions & 4 deletions lib/validation/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ const formatValidators: Record<
if (typeof value !== "string" || value === "") {
return undefined;
}
if (value === "" || isValidDateTime.test(value)) {
if (new Date(value).toString() === "Invalid Date") {
return draft.errors.formatDateTimeError({ value, pointer, schema });
const dateAndTime = value.split(/t/i);
if (dateAndTime.length === 2) {
const dateIsValid = formatValidators.date(node, dateAndTime[0]) === undefined;
const timeIsValid = formatValidators.time(node, dateAndTime[1]) === undefined;
if (dateIsValid && timeIsValid) {
return undefined;
}
return undefined;
}
return draft.errors.formatDateTimeError({ value, pointer, schema });
},
Expand Down
4 changes: 1 addition & 3 deletions test/spec/v2019-09/draft2019-09.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ const supportedTestCases = (t: FeatureTest) =>
"ecmascript-regex", // should
"float-overflow",
"dependencies-compatibility", // should
"format-date-time", // MUST
// "format-time", // MUST
"format-iri",
"format-iri-reference",
"format-idn-hostname",
Expand All @@ -46,7 +44,7 @@ const supportedTestCases = (t: FeatureTest) =>

const draftFeatureTests = getDraftTests("2019-09")
// .filter((testcase) => testcase.name === "dependencies-compatibility")
// .filter((testcase) => testcase.name === "format-time")
// .filter((testcase) => testcase.name === "format-date-time")
.filter(supportedTestCases);

/*
Expand Down

0 comments on commit 1096736

Please sign in to comment.