Skip to content

Commit

Permalink
As requested in open issue 1511, have parser default to UTC if timezo…
Browse files Browse the repository at this point in the history
…ne is not provided
  • Loading branch information
Ruoyang committed Aug 26, 2023
1 parent 2432cf7 commit f3d55e8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public static Date parse(String date, ParsePosition pos) throws ParseException {

if (!hasT && (date.length() <= offset)) {
Calendar calendar = new GregorianCalendar(year, month - 1, day);
calendar.setTimeZone(TIMEZONE_UTC);
calendar.setLenient(false);

pos.setIndex(offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ public void testDateFormatWithTimezone() {

@Test
@SuppressWarnings("UndefinedEquals")
public void testDateParseWithDefaultTimezone() throws ParseException {
public void testDateParseDefaultsToUTC() throws ParseException {
String dateStr = "2018-06-25";
Date date = ISO8601Utils.parse(dateStr, new ParsePosition(0));
Date expectedDate = new GregorianCalendar(2018, Calendar.JUNE, 25).getTime();
GregorianCalendar calendar = createUtcCalendar();
calendar.set(2018, Calendar.JUNE, 25);
Date expectedDate = calendar.getTime();
assertThat(date).isEqualTo(expectedDate);
}

Expand Down

0 comments on commit f3d55e8

Please sign in to comment.