Skip to content
Snippets Groups Projects
Commit 157acdb9 authored by Jonas Blatt's avatar Jonas Blatt :ant:
Browse files

Check Date format

parent 68199a13
No related branches found
No related tags found
No related merge requests found
......@@ -40,24 +40,35 @@ public class DateVerifier extends AbstractVerifier {
private void checkDateValue(VDmnValue dateValue) {
if (!dateValue.getText().isEmpty()) {
// 1. check pattern
Matcher matcher = datePattern.matcher(dateValue.getText());
if (!matcher.find()) {
for (String dateStringValue : dateValue.getText()
.replace("<", "")
.replace(">", "")
.replace("[", "")
.replace("]", "")
.split("..")) {
checkCorrectDate(dateValue, dateStringValue);
}
}
}
private void checkCorrectDate(VDmnValue dateValue, String dateStringValue) {
// 1. check pattern
Matcher matcher = datePattern.matcher(dateStringValue);
if (!matcher.find()) {
vref.addElement(VerificationResultEntryElement.create(dateValue));
vref.addToEntry(
VerificationClassification.ERROR,
"Date value '%s' does not match 'date and time(\"yyyy-mm-ddTHH:MM:SS\").'",
dateStringValue);
} else {
// 2. check correct date
String dateTime = matcher.group("datetime");
try {
LocalDateTime.parse(dateTime);
} catch (DateTimeParseException e) {
vref.addElement(VerificationResultEntryElement.create(dateValue));
vref.addToEntry(
VerificationClassification.ERROR,
"Date value '%s' does not match 'date and time(\"yyyy-mm-ddTHH:MM:SS\").'",
dateValue.getText());
} else {
// 2. check correct date
String dateTime = matcher.group("datetime");
try {
LocalDateTime.parse(dateTime);
} catch (DateTimeParseException e) {
vref.addElement(VerificationResultEntryElement.create(dateValue));
vref.addToEntry(
VerificationClassification.ERROR, "Date value '%s' is no valid date.", dateTime);
}
VerificationClassification.ERROR, "Date value '%s' is no valid date.", dateTime);
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment