Skip to content

Commit

Permalink
Adjust how 00 in dates is ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
GenieTim committed Dec 1, 2023
1 parent 25f4ae1 commit 5d755eb
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,18 @@ protected JSONObject dateToNahima(String date, boolean allowInvalid) throws Pars
JSONObject returnValue = new JSONObject();
// remove all trailing zeros, so we don't have to deal with formats like
// 2021/00/00
date = StringUtils.strip(date, "0./");
date = StringUtils.strip(date.replaceAll("/00|00/|\\.00|00\\.", ""), "./");
// find different formats
// year-only dates are allowed in Nahima, somehow
if (date.matches("^[0-9]{4}$")) {
returnValue.put("value", date);
return returnValue;
}
// as are month & year
if (date.matches("^[0-9]{4}/[0-9]{2}$")) {
returnValue.put("value", date.replace("/", "-"));
return returnValue;
}
if (date.matches("^[0-9]{1,2}\\.^[0-9]{1,2}\\.^[0-9]{2,4}$")) {
// try manually, knowing the Swiss type of date
try {
Expand All @@ -376,16 +386,6 @@ protected JSONObject dateToNahima(String date, boolean allowInvalid) throws Pars
} catch (ParseException ex) {
}
}
// year-only dates are allowed in Nahima, somehow
if (date.matches("^[0-9]{4}$")) {
returnValue.put("value", date);
return returnValue;
}
// as are month & year
if (date.matches("^[0-9]{4}/[0-9]{2}$")) {
returnValue.put("value", date.replace("/", "-"));
return returnValue;
}
if (!allowInvalid) {
log.error("Failed to convert date from " + date, e);
throw e;
Expand Down

0 comments on commit 5d755eb

Please sign in to comment.