1
0
Fork 0

introduced java8-based date parsing

This commit is contained in:
Claudio Atzori 2021-03-11 12:37:33 +01:00
parent e8789b0cdb
commit 19f3580b3d
2 changed files with 10 additions and 4 deletions

View File

@ -5,6 +5,9 @@ import static com.google.common.base.Preconditions.checkArgument;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -477,8 +480,6 @@ public class ModelSupport {
return ((OafEntity) t).getId(); return ((OafEntity) t).getId();
} }
public static final String ISO8601FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ";
public static String oldest(String dateA, String dateB) throws ParseException { public static String oldest(String dateA, String dateB) throws ParseException {
if (StringUtils.isBlank(dateA)) { if (StringUtils.isBlank(dateA)) {
@ -489,8 +490,8 @@ public class ModelSupport {
} }
if (StringUtils.isNotBlank(dateA) && StringUtils.isNotBlank(dateB)) { if (StringUtils.isNotBlank(dateA) && StringUtils.isNotBlank(dateB)) {
final Date a = new SimpleDateFormat(ISO8601FORMAT).parse(dateA); final Date a = Date.from(Instant.from(DateTimeFormatter.ISO_INSTANT.parse(dateA)));
final Date b = new SimpleDateFormat(ISO8601FORMAT).parse(dateB); final Date b = Date.from(Instant.from(DateTimeFormatter.ISO_INSTANT.parse(dateB)));
return a.before(b) ? dateA : dateB; return a.before(b) ? dateA : dateB;
} else { } else {

View File

@ -85,6 +85,11 @@ public class MergeTest {
b = createRel(true, "2016-04-05T12:41:19.202Z"); b = createRel(true, "2016-04-05T12:41:19.202Z");
a.mergeFrom(b); a.mergeFrom(b);
assertEquals("2016-04-05T12:41:19.202Z", a.getValidationDate()); assertEquals("2016-04-05T12:41:19.202Z", a.getValidationDate());
a = createRel(true, "2016-05-07T12:41:19.202Z");
b = createRel(true, "2016-04-05T12:41:19.202Z");
a.mergeFrom(b);
assertEquals("2016-04-05T12:41:19.202Z", a.getValidationDate());
} }
@Test @Test