Skip to content

Commit

Permalink
add a test wrt #570 in master
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 3, 2014
1 parent 9973218 commit 8e2901e
Showing 1 changed file with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,61 @@ public void testDateUtilISO8601() throws Exception
assertEquals(30, c.get(Calendar.DAY_OF_MONTH));
}

// [Databind#570]
public void testISO8601PartialMilliseconds() throws Exception
{
String inputStr;
Date inputDate;
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));

inputStr = "2014-10-03T18:00:00.6-05:00";
inputDate = MAPPER.readValue(quote(inputStr), java.util.Date.class);
c.setTime(inputDate);
assertEquals(2014, c.get(Calendar.YEAR));
assertEquals(Calendar.OCTOBER, c.get(Calendar.MONTH));
assertEquals(3, c.get(Calendar.DAY_OF_MONTH));
assertEquals(600, c.get(Calendar.MILLISECOND));

inputStr = "2014-10-03T18:00:00.61-05:00";
inputDate = MAPPER.readValue(quote(inputStr), java.util.Date.class);
c.setTime(inputDate);
assertEquals(2014, c.get(Calendar.YEAR));
assertEquals(Calendar.OCTOBER, c.get(Calendar.MONTH));
assertEquals(3, c.get(Calendar.DAY_OF_MONTH));
assertEquals(18 + 5, c.get(Calendar.HOUR_OF_DAY));
assertEquals(0, c.get(Calendar.MINUTE));
assertEquals(0, c.get(Calendar.SECOND));
assertEquals(610, c.get(Calendar.MILLISECOND));

inputStr = "1997-07-16T19:20:30.45+01:00";
inputDate = MAPPER.readValue(quote(inputStr), java.util.Date.class);
c.setTime(inputDate);
assertEquals(1997, c.get(Calendar.YEAR));
assertEquals(Calendar.JULY, c.get(Calendar.MONTH));
assertEquals(16, c.get(Calendar.DAY_OF_MONTH));
assertEquals(19 - 1, c.get(Calendar.HOUR_OF_DAY));
assertEquals(20, c.get(Calendar.MINUTE));
assertEquals(30, c.get(Calendar.SECOND));
assertEquals(450, c.get(Calendar.MILLISECOND));
}

public void testISO8601MissingSeconds() throws Exception
{
String inputStr;
Date inputDate;
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));

inputStr = "1997-07-16T19:20+01:00";
inputDate = MAPPER.readValue(quote(inputStr), java.util.Date.class);
c.setTime(inputDate);
assertEquals(1997, c.get(Calendar.YEAR));
assertEquals(Calendar.JULY, c.get(Calendar.MONTH));
assertEquals(16, c.get(Calendar.DAY_OF_MONTH));
assertEquals(19 - 1, c.get(Calendar.HOUR_OF_DAY));
assertEquals(0, c.get(Calendar.SECOND));
assertEquals(0, c.get(Calendar.MILLISECOND));
}

public void testDateUtilISO8601NoTimezone() throws Exception
{
// Timezone itself is optional as well...
Expand Down Expand Up @@ -180,7 +235,7 @@ public void testDateUtilISO8601NoMilliseconds() throws Exception
assertEquals(0, c.get(Calendar.MILLISECOND));

// 03-Nov-2013, tatu: This wouldn't work, and is the nominal reason
// for #338 I thinl
// for #338 I think
/*
inputDate = ISO8601Utils.parse(INPUT_STR);
c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
Expand Down

0 comments on commit 8e2901e

Please sign in to comment.