Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@ public static Date parse(String date, ParsePosition pos) throws ParseException {
offset += 1;
} else if (timezoneIndicator == '+' || timezoneIndicator == '-') {
String timezoneOffset = date.substring(offset);
offset += timezoneOffset.length();

// When timezone has no minutes, we should append it, valid timezones are, for example:
// +00:00, +0000 and +00
timezoneOffset = timezoneOffset.length() >= 5 ? timezoneOffset : timezoneOffset + "00";

offset += timezoneOffset.length();
// 18-Jun-2015, tatu: Minor simplification, skip offset of "+0000"/"+00:00"
if (timezoneOffset.equals("+0000") || timezoneOffset.equals("+00:00")) {
timezone = TIMEZONE_UTC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,30 @@ public void testDateParseWithTimezone() throws ParseException {
assertThat(date).isEqualTo(expectedDate);
}

@Test
@SuppressWarnings("JavaUtilDate")
public void testDateParseShortTimezonePosition() throws ParseException {
for (String timezone : new String[] {"+00", "+01", "-02", "+01:30", "+0130"}) {
String dateStr = "2018-06-25T00:00:00" + timezone;
ParsePosition position = new ParsePosition(0);
Date date = ISO8601Utils.parse(dateStr, position);
assertThat(position.getIndex()).isEqualTo(dateStr.length());

String fullTimezone = timezone.length() == 3 ? timezone + ":00" : timezone;
Date expected =
ISO8601Utils.parse("2018-06-25T00:00:00" + fullTimezone, new ParsePosition(0));
assertThat(date.getTime()).isEqualTo(expected.getTime());
}
}

@Test
public void testDateParseShortTimezoneFromNonzeroPosition() throws ParseException {
String dateStr = "prefix 2018-06-25T00:00:00+01";
ParsePosition position = new ParsePosition("prefix ".length());
ISO8601Utils.parse(dateStr, position);
assertThat(position.getIndex()).isEqualTo(dateStr.length());
}

@Test
@SuppressWarnings("UndefinedEquals")
public void testDateParseSpecialTimezone() throws ParseException {
Expand Down