Fixing date formatting
This commit is contained in:
parent
8d64e2972c
commit
e4d1ae1a28
|
@ -74,7 +74,7 @@ public class ConvertToDataValueObjectModel {
|
|||
|
||||
private static final String NO_TIME = "T00:00";
|
||||
|
||||
public static final String DATE_FORMAT = "dd-MM-yyyy";
|
||||
public static final String DATE_FORMAT = "yyyy-MM-dd";
|
||||
|
||||
public static final String HOURS_MINUTES_SEPARATOR = ":";
|
||||
|
||||
|
@ -709,26 +709,41 @@ public class ConvertToDataValueObjectModel {
|
|||
return null;
|
||||
|
||||
String time = dateTime.toString();
|
||||
return instantToDateFormatString(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instant to date format string. format dd-MM-yyyyT00:00:00.00Z to
|
||||
* DateFormat.format
|
||||
*
|
||||
* @param instantString the instant string
|
||||
* @return the string
|
||||
*/
|
||||
public static String instantToDateFormatString(String instantString) {
|
||||
|
||||
if (instantString == null)
|
||||
return null;
|
||||
|
||||
String time = instantString;
|
||||
DateTimeFormatter formatter = null;
|
||||
try {
|
||||
if (!time.endsWith(NO_TIME)) {
|
||||
formatter = DateTimeFormatter.ofPattern(DATE_FORMAT + " " + TIME_FORMAT);
|
||||
} else {
|
||||
time = time.replace(NO_TIME, "");
|
||||
formatter = DateTimeFormatter.ofPattern(DATE_FORMAT);
|
||||
}
|
||||
formatter = DateTimeFormatter.ofPattern(DATE_FORMAT + " " + TIME_FORMAT);
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Parsing error: ", e);
|
||||
}
|
||||
|
||||
try {
|
||||
if (formatter != null)
|
||||
return dateTime.format(formatter);
|
||||
if (formatter != null) {
|
||||
LocalDateTime instant = LocalDateTime.parse(time);
|
||||
|
||||
return formatter.format(instant);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Date format error: ", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return dateTime.toString();
|
||||
return instantString;
|
||||
}
|
||||
|
||||
// /**
|
||||
|
@ -917,16 +932,18 @@ public class ConvertToDataValueObjectModel {
|
|||
if (keyLower.contains(possibleDate)) {
|
||||
try {
|
||||
LOG.debug("value " + value + " is instance of: " + value.getClass());
|
||||
Document documentDate = new Document((Map) value);
|
||||
String jsonValue = documentDate.toJson();
|
||||
LOG.debug("jsonValue " + value);
|
||||
|
||||
// LocalDate asDate =
|
||||
// objectMapper.readerFor(LocalDate.class).readValue(jsonValue);
|
||||
|
||||
LocalDateTime asDate = org.gcube.application.geoportal.client.utils.Serialization.read(jsonValue,
|
||||
LocalDateTime.class);
|
||||
LOG.info("Casted as date: " + asDate);
|
||||
String asDate = instantToDateFormatString(value.toString());
|
||||
// Document documentDate = new Document((Map) value);
|
||||
// String jsonValue = documentDate.toJson();
|
||||
// LOG.debug("jsonValue " + value);
|
||||
//
|
||||
// // LocalDate asDate =
|
||||
// // objectMapper.readerFor(LocalDate.class).readValue(jsonValue);
|
||||
//
|
||||
// LocalDateTime asDate = org.gcube.application.geoportal.client.utils.Serialization.read(jsonValue,
|
||||
// LocalDateTime.class);
|
||||
// LOG.info("Casted as date: " + asDate);
|
||||
value = asDate;
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
|
|
Loading…
Reference in New Issue