Skip to content

Commit

Permalink
fix: testDate to identify invalid date and leap year
Browse files Browse the repository at this point in the history
* Fix testDate to identify invalid date and leap year

* Refine importation
  • Loading branch information
douglas-chanwh committed Dec 15, 2023
1 parent 8c43182 commit e4c6cf0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package io.vertx.json.schema;

import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.impl.JsonUtil;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.Base64;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.impl.JsonUtil;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.Base64;

/**
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/io/vertx/json/schema/impl/Format.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.vertx.json.schema.impl;

import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.regex.Pattern;

public class Format {
Expand Down Expand Up @@ -209,6 +211,14 @@ private static boolean testTime(String value) {
private static final Pattern FASTDATE = Pattern.compile("^\\d\\d\\d\\d-[0-1]\\d-[0-3]\\d$");

private static boolean testDate(String value) {
return FASTDATE.matcher(value).find();
if (!FASTDATE.matcher(value).matches()) {
return false;
}
try {
DateTimeFormatter.ISO_DATE.parse(value);
return true;
} catch (DateTimeParseException e) {
return false;
}
}
}
51 changes: 0 additions & 51 deletions src/test/resources/unsupported-tck-tests.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,6 @@ draft2019-09/optional/ecmascript-regex/ECMA\ 262\ \\s\ matches\ whitespace/EM\ S
draft2019-09/optional/ecmascript-regex/ECMA\ 262\ \\s\ matches\ whitespace/latin-1\ non-breaking-space\ matches=skip
draft2019-09/optional/ecmascript-regex/ECMA\ 262\ \\s\ matches\ whitespace/paragraph\ separator\ matches\ (line\ terminator)=skip
draft2019-09/optional/ecmascript-regex/ECMA\ 262\ \\s\ matches\ whitespace/zero-width\ whitespace\ matches=skip
draft2019-09/optional/format/date/validation\ of\ date\ strings/2021\ is\ not\ a\ leap\ year=skip
draft2019-09/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 29\ days\ in\ February\ (normal)=skip
draft2019-09/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 30\ days\ in\ February\ (leap)=skip
draft2019-09/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 31\ days\ in\ April=skip
draft2019-09/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 31\ days\ in\ June=skip
draft2019-09/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 31\ days\ in\ November=skip
draft2019-09/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 31\ days\ in\ September=skip
draft2019-09/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ August=skip
draft2019-09/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ December=skip
draft2019-09/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ January=skip
draft2019-09/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ July=skip
draft2019-09/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ March=skip
draft2019-09/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ May=skip
draft2019-09/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ October=skip
draft2019-09/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ invalid\ month=skip
draft2019-09/optional/format/date/validation\ of\ date\ strings/invalid\ month-day\ combination=skip
draft2019-09/optional/format/date/validation\ of\ date\ strings/invalid\ month=skip
draft2019-09/optional/format/idn-email/validation\ of\ an\ internationalized\ e-mail\ addresses/an\ invalid\ e-mail\ address=skip
draft2019-09/optional/format/idn-email/validation\ of\ an\ internationalized\ e-mail\ addresses/an\ invalid\ idn\ e-mail\ address=skip
draft2019-09/optional/format/idn-hostname/validation\ of\ internationalized\ host\ names/a\ host\ name\ with\ a\ component\ too\ long=skip
Expand Down Expand Up @@ -126,23 +109,6 @@ draft2020-12/optional/ecmascript-regex/ECMA\ 262\ \\s\ matches\ whitespace/EM\ S
draft2020-12/optional/ecmascript-regex/ECMA\ 262\ \\s\ matches\ whitespace/latin-1\ non-breaking-space\ matches=skip
draft2020-12/optional/ecmascript-regex/ECMA\ 262\ \\s\ matches\ whitespace/paragraph\ separator\ matches\ (line\ terminator)=skip
draft2020-12/optional/ecmascript-regex/ECMA\ 262\ \\s\ matches\ whitespace/zero-width\ whitespace\ matches=skip
draft2020-12/optional/format/date/validation\ of\ date\ strings/2021\ is\ not\ a\ leap\ year=skip
draft2020-12/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 29\ days\ in\ February\ (normal)=skip
draft2020-12/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 30\ days\ in\ February\ (leap)=skip
draft2020-12/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 31\ days\ in\ April=skip
draft2020-12/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 31\ days\ in\ June=skip
draft2020-12/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 31\ days\ in\ November=skip
draft2020-12/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 31\ days\ in\ September=skip
draft2020-12/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ August=skip
draft2020-12/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ December=skip
draft2020-12/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ January=skip
draft2020-12/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ July=skip
draft2020-12/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ March=skip
draft2020-12/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ May=skip
draft2020-12/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ October=skip
draft2020-12/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ invalid\ month=skip
draft2020-12/optional/format/date/validation\ of\ date\ strings/invalid\ month-day\ combination=skip
draft2020-12/optional/format/date/validation\ of\ date\ strings/invalid\ month=skip
draft2020-12/optional/format/idn-email/validation\ of\ an\ internationalized\ e-mail\ addresses/an\ invalid\ e-mail\ address=skip
draft2020-12/optional/format/idn-email/validation\ of\ an\ internationalized\ e-mail\ addresses/an\ invalid\ idn\ e-mail\ address=skip
draft2020-12/optional/format/idn-hostname/validation\ of\ internationalized\ host\ names/a\ host\ name\ with\ a\ component\ too\ long=skip
Expand Down Expand Up @@ -226,23 +192,6 @@ draft7/optional/ecmascript-regex/ECMA\ 262\ \\s\ matches\ whitespace/EM\ SPACE\
draft7/optional/ecmascript-regex/ECMA\ 262\ \\s\ matches\ whitespace/latin-1\ non-breaking-space\ matches=skip
draft7/optional/ecmascript-regex/ECMA\ 262\ \\s\ matches\ whitespace/paragraph\ separator\ matches\ (line\ terminator)=skip
draft7/optional/ecmascript-regex/ECMA\ 262\ \\s\ matches\ whitespace/zero-width\ whitespace\ matches=skip
draft7/optional/format/date/validation\ of\ date\ strings/2021\ is\ not\ a\ leap\ year=skip
draft7/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 29\ days\ in\ February\ (normal)=skip
draft7/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 30\ days\ in\ February\ (leap)=skip
draft7/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 31\ days\ in\ April=skip
draft7/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 31\ days\ in\ June=skip
draft7/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 31\ days\ in\ November=skip
draft7/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 31\ days\ in\ September=skip
draft7/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ August=skip
draft7/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ December=skip
draft7/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ January=skip
draft7/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ July=skip
draft7/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ March=skip
draft7/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ May=skip
draft7/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ 32\ days\ in\ October=skip
draft7/optional/format/date/validation\ of\ date\ strings/a\ invalid\ date\ string\ with\ invalid\ month=skip
draft7/optional/format/date/validation\ of\ date\ strings/invalid\ month-day\ combination=skip
draft7/optional/format/date/validation\ of\ date\ strings/invalid\ month=skip
draft7/optional/format/idn-email/validation\ of\ an\ internationalized\ e-mail\ addresses/an\ invalid\ e-mail\ address=skip
draft7/optional/format/idn-email/validation\ of\ an\ internationalized\ e-mail\ addresses/an\ invalid\ idn\ e-mail\ address=skip
draft7/optional/format/idn-hostname/validation\ of\ internationalized\ host\ names/a\ host\ name\ with\ a\ component\ too\ long=skip
Expand Down

0 comments on commit e4c6cf0

Please sign in to comment.