Skip to content

Commit

Permalink
Merge pull request #817 from wingspan/2.5
Browse files Browse the repository at this point in the history
Allow date-only ISO strings to have no time zone. #816
  • Loading branch information
cowtowncoder committed Jun 5, 2015
2 parents d4923ea + 3cbb7bc commit 6671559
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ public static Date parse(String date, ParsePosition pos) throws ParseException {
int minutes = 0;
int seconds = 0;
int milliseconds = 0; // always use 0 otherwise returned date will include millis of current time

// if the value has no time component (and no time zone), we are done
if (!checkOffset(date, offset, 'T') && (date.length() <= offset)) {
Calendar calendar = new GregorianCalendar(year, month - 1, day);

pos.setIndex(offset);
return calendar.getTime();
}

if (checkOffset(date, offset, 'T')) {

// extract hours, minutes, seconds and milliseconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;

/**
* @see ISO8601DateFormat
Expand Down Expand Up @@ -33,6 +32,16 @@ public void testFormat() {
public void testParse() throws Exception {
Date result = df.parse("2007-08-13T19:51:23Z");
assertEquals(date, result);

// Test parsing date-only values with and without a timezone designation
Date dateOnly = df.parse("2007-08-14");
Calendar cal = new GregorianCalendar(2007, 8-1, 14);
assertEquals(cal.getTime(), dateOnly);

dateOnly = df.parse("2007-08-14Z");
cal = new GregorianCalendar(2007, 8-1, 14);
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
assertEquals(cal.getTime(), dateOnly);
}

public void testPartialParse() throws Exception {
Expand Down

0 comments on commit 6671559

Please sign in to comment.