fixing instantToDateFormatString

This commit is contained in:
Francesco Mangiacrapa 2022-09-27 16:59:59 +02:00
parent f5cc79ec1f
commit 88fcc4d707
2 changed files with 9 additions and 10 deletions

View File

@ -97,6 +97,7 @@
<groupId>javax.xml.bind</groupId> <groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId> <artifactId>jaxb-api</artifactId>
<version>2.3.0</version> <version>2.3.0</version>
<scope>provided</scope>
</dependency> </dependency>
<!-- LOGGER --> <!-- LOGGER -->

View File

@ -724,23 +724,21 @@ public class ConvertToDataValueObjectModel {
if (instantString == null) if (instantString == null)
return null; return null;
String time = instantString; String time = instantString.trim();
DateTimeFormatter formatter = null; DateTimeFormatter formatter = null;
try { try {
formatter = DateTimeFormatter.ofPattern(DATE_FORMAT + " " + TIME_FORMAT);
} catch (Exception e) { if(time.contains("T")) {
LOG.warn("Parsing error: ", e); formatter = DateTimeFormatter.ofPattern(DATE_FORMAT + " " + TIME_FORMAT);
}
try {
if (formatter != null) {
LocalDateTime instant = LocalDateTime.parse(time); LocalDateTime instant = LocalDateTime.parse(time);
return formatter.format(instant);
}else {
formatter = DateTimeFormatter.ofPattern(DATE_FORMAT);
LocalDate instant = LocalDate.parse(time, formatter);
return formatter.format(instant); return formatter.format(instant);
} }
} catch (Exception e) { } catch (Exception e) {
LOG.warn("Date format error: ", e); LOG.warn("Date format error: ", e);
e.printStackTrace();
} }
return instantString; return instantString;