Skip to content

Commit bbaa278

Browse files
derkoegmessner
authored andcommitted
Fix ISO8601 parser for date with colon offset and no space (#422)
Dates with colon offset like "2018-03-12T10:16:46+07:00" threw a DateTimeParseException, changing the order of the offset patterns fixes this
1 parent b1eaceb commit bbaa278

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/main/java/org/gitlab4j/api/utils/ISO8601.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class ISO8601 {
2828
public static final String UTC_PATTERN = "yyyy-MM-dd HH:mm:ss 'UTC'";
2929

3030
private static final DateTimeFormatter ODT_WITH_MSEC_PARSER = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd[['T'][ ]HH:mm:ss.SSS[ ][XXXXX][XXXX]]").toFormatter();
31-
private static final DateTimeFormatter ODT_PARSER = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd[['T'][ ]HH:mm:ss[.SSS][ ][X][XXX]]")
31+
private static final DateTimeFormatter ODT_PARSER = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd[['T'][ ]HH:mm:ss[.SSS][ ][XXX][X]]")
3232
.parseDefaulting(ChronoField.HOUR_OF_DAY, 0)
3333
.parseDefaulting(ChronoField.MINUTE_OF_HOUR, 0)
3434
.parseDefaulting(ChronoField.SECOND_OF_MINUTE, 0)

src/test/java/org/gitlab4j/api/TestISO8601.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ public class TestISO8601 {
2020
private static final String SPACEY_GITLAB_DATE_WITH_MSEC = "2018-03-12 10:16:46.123 +0700";
2121
private static final String ISO8601_GITLAB_DATE_WITH_MSEC ="2018-03-12T10:16:46.123+0700";
2222

23+
private static final String ISO8601_DATE_OFFSET_COLON = "2018-03-12T10:16:46+07:00";
24+
2325
private static final String ISO8601_DATE_MSEC = "2018-03-12T10:16:46.123Z";
24-
private static final String ISO8601_DATE_OFFSET_COLON = "2018-03-12T10:16:46.123+00:00";
26+
private static final String ISO8601_DATE_MSEC_OFFSET_COLON = "2018-03-12T10:16:46.123+00:00";
2527
private static final String ISO8601_GITLAB_DATE_MSEC = "2018-03-12T03:16:46.123-0700";
2628
private static final String SPACEY_GITLAB_UTC_DATE_MSEC = "2018-03-12 10:16:46.123 UTC";
2729

@@ -69,8 +71,15 @@ public void testMsecDateParse() throws ParseException {
6971

7072
@Test
7173
public void testOffsetColonDateParse() throws ParseException {
74+
Date gitlabOffsetDate = ISO8601.toDate(ISO8601_DATE_OFFSET_COLON);
75+
Date gitlabDate = ISO8601.toDate(ISO8601_GITLAB_DATE);
76+
assertEquals(gitlabDate, gitlabOffsetDate);
77+
}
78+
79+
@Test
80+
public void testOffsetColonMsecDateParse() throws ParseException {
7281
Date msecDate = ISO8601.toDate(ISO8601_DATE_MSEC);
73-
Date gitlabMsecDate = ISO8601.toDate(ISO8601_DATE_OFFSET_COLON);
82+
Date gitlabMsecDate = ISO8601.toDate(ISO8601_DATE_MSEC_OFFSET_COLON);
7483
assertEquals(msecDate, gitlabMsecDate);
7584
}
7685
}

0 commit comments

Comments
 (0)