From b433d281770d79685d7b50ce79871c707e0efce8 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Tue, 14 Jul 2020 22:12:33 +0200 Subject: [PATCH] Add support for another date format --- app/src/main/java/com/readrops/app/utils/DateUtils.java | 3 +++ app/src/test/java/com/readrops/app/DateUtilsTest.java | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/app/src/main/java/com/readrops/app/utils/DateUtils.java b/app/src/main/java/com/readrops/app/utils/DateUtils.java index a2302145..6577c885 100644 --- a/app/src/main/java/com/readrops/app/utils/DateUtils.java +++ b/app/src/main/java/com/readrops/app/utils/DateUtils.java @@ -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(); diff --git a/app/src/test/java/com/readrops/app/DateUtilsTest.java b/app/src/test/java/com/readrops/app/DateUtilsTest.java index 3ecfc545..2cb8ac2a 100644 --- a/app/src/test/java/com/readrops/app/DateUtilsTest.java +++ b/app/src/test/java/com/readrops/app/DateUtilsTest.java @@ -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"))); + } } \ No newline at end of file