Add support for another date format

This commit is contained in:
Shinokuni 2020-07-14 22:12:33 +02:00
parent b98b8853ec
commit b433d28177
2 changed files with 11 additions and 0 deletions

View File

@ -21,6 +21,8 @@ public final class DateUtils {
private static final String OFFSET_PATTERN = "Z";
private static final String ISO_PATTERN = ".SSSZZ";
/**
* Date pattern for format : 2019-01-04T22:21:46+00:00
*/
@ -32,6 +34,7 @@ public final class DateUtils {
.appendOptional(DateTimeFormat.forPattern(ATOM_JSON_DATE_FORMAT).getParser())
.appendOptional(DateTimeFormat.forPattern(GMT_PATTERN).getParser())
.appendOptional(DateTimeFormat.forPattern(OFFSET_PATTERN).getParser())
.appendOptional(DateTimeFormat.forPattern(ISO_PATTERN).getParser())
.toFormatter()
.withLocale(Locale.ENGLISH)
.withOffsetParsed();

View File

@ -41,4 +41,12 @@ public class DateUtilsTest {
assertEquals(0, dateTime.compareTo(DateUtils.stringToLocalDateTime("2019-01-04T22:21:46-0000")));
}
@Test
public void isoPatternTest() {
LocalDateTime dateTime = new LocalDateTime(2020, 6, 30, 11, 39, 37, 206);
assertEquals(0, dateTime.compareTo(DateUtils.stringToLocalDateTime("2020-06-30T11:39:37.206-07:00")));
}
}