Skip to content

Commit 5a36c96

Browse files
committed
Fixed VALID_DATE_IO method
1 parent 32af147 commit 5a36c96

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
**Version 4.7**
44

55
- Added new differenceInDays methods to the edits context.
6+
- Fixed VALID_DATE_IO metafile functions to allow trailing 0's for day and month.
67
- Changed the minimum Java language for this library from Java 11 to Java 21.
78
- Updated dependencies.
89

src/main/java/com/imsweb/validation/functions/MetafileContextFunctions.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,20 +230,24 @@ public boolean GEN_VALID_DATE_IOP(Binding binding, Object value) {
230230
}
231231

232232
int month = val.trim().length() >= 6 ? Integer.parseInt(val.substring(4, 6)) : 1;
233+
if (month == 0) // non-documented feature: 0 is allowed (treated as blank)
234+
month = 1;
233235
if (month <= 0 || month > 12) {
234236
binding.setVariable(BINDING_KEY_DATE_COMPONENT, "invalid as to month");
235237
return false;
236238
}
237239

238240
try {
239241
int day = val.trim().length() == 8 ? Integer.parseInt(val.substring(6, 8)) : 1;
242+
if (day == 0) // non-documented feature: 0 is allowed (treated as blank)
243+
day = 1;
240244
if (day <= 0 || day > 31) {
241245
binding.setVariable(BINDING_KEY_DATE_COMPONENT, "invalid as to day");
242246
return false;
243247
}
244248
LocalDate toCheck = LocalDate.of(year, month, day);
245249
int actualMaxDay = YearMonth.of(year, month).lengthOfMonth();
246-
if (day <= 0 || day > actualMaxDay) {
250+
if (day > actualMaxDay) {
247251
binding.setVariable(BINDING_KEY_DATE_COMPONENT, "invalid as to day");
248252
return false;
249253
}

src/test/java/com/imsweb/validation/functions/MetafileContextFunctionsTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,14 @@ public void testGEN_VALID_DATE_IOP() {
679679
Assert.assertFalse(_functions.GEN_VALID_DATE_IOP(binding, "20100230"));
680680
Assert.assertFalse(_functions.GEN_VALID_DATE_IOP(binding, "20100229"));
681681
Assert.assertTrue(_functions.GEN_VALID_DATE_IOP(binding, "20120229"));
682+
Assert.assertFalse(_functions.GEN_VALID_DATE_IOP(binding, "201102"));
683+
Assert.assertFalse(_functions.GEN_VALID_DATE_IOP(binding, "2011"));
684+
Assert.assertFalse(_functions.GEN_VALID_DATE_IOP(binding, "20110299"));
685+
Assert.assertFalse(_functions.GEN_VALID_DATE_IOP(binding, "20119999"));
686+
Assert.assertFalse(_functions.GEN_VALID_DATE_IOP(binding, "99999999"));
687+
Assert.assertTrue(_functions.GEN_VALID_DATE_IOP(binding, "20110200")); // trailing 0's for day is allowed (hidden feature, not in the documentation)
688+
Assert.assertTrue(_functions.GEN_VALID_DATE_IOP(binding, "20110000")); // trailing 0's for month/day is allowed (hidden feature, not in the documentation)
689+
Assert.assertFalse(_functions.GEN_VALID_DATE_IOP(binding, "00000000"));
682690

683691
//today
684692
Assert.assertTrue(_functions.GEN_VALID_DATE_IOP(binding, today.format(yearMonthDayFormatter)));

0 commit comments

Comments
 (0)