XsDateTimeFormat extends Format { public Object parseObject(String source, boolean lenient) throws ParseException { ParsePosition pos = new ParsePosition(0); Object result = parseObject(source, pos, lenient); if (pos.getIndex() == 0) { throw new ParseException("Format.parseObject(String) failed", pos.getErrorIndex()); } return result; } XsDateTimeFormat(boolean pParseDate, boolean pParseTime);  XsDateTimeFormat(); Object parseObject(String source, boolean lenient); Object parseObject(String pString, ParsePosition pParsePosition); Object parseObject(String pString, ParsePosition pParsePosition, boolean lenient); StringBuffer format(Object pCalendar, StringBuffer pBuffer, FieldPosition pPos);  }
@Test public void testDate() throws ParseException { XsDateTimeFormat format = new XsDateTimeFormat(); String time = "2014-10-12T09:00:00.000Z"; Object parseObject = format.parseObject(time); assertTrue(parseObject instanceof Calendar); Calendar cal = (Calendar) parseObject; int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); int hours = cal.get(Calendar.HOUR); int mins = cal.get(Calendar.MINUTE); int sec = cal.get(Calendar.SECOND); int millis = cal.get(Calendar.MILLISECOND); assertEquals(year, 2014); assertEquals(month, 9); assertEquals(day, 12); assertEquals(hours, 9); assertEquals(mins, 0); assertEquals(sec, 0); assertEquals(millis, 0); }
@Test(expected = ParseException.class) public void testWrongDate() throws ParseException { XsDateTimeFormat format = new XsDateTimeFormat(); String time = "2014-10-12T09:00Z"; Object parseObject = format.parseObject(time); }
@Test public void testWrongDateLenientNoSec() throws ParseException { XsDateTimeFormat format = new XsDateTimeFormat(); String time = "2014-10-12T09:00Z"; Object parseObject = format.parseObject(time, true); assertTrue(parseObject instanceof Calendar); Calendar cal = (Calendar) parseObject; int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); int hours = cal.get(Calendar.HOUR); int mins = cal.get(Calendar.MINUTE); int sec = cal.get(Calendar.SECOND); int millis = cal.get(Calendar.MILLISECOND); assertEquals(year, 2014); assertEquals(month, 9); assertEquals(day, 12); assertEquals(hours, 9); assertEquals(mins, 0); assertEquals(sec, 0); assertEquals(millis, 0); }
@Test public void testWrongDateLenientNoMins() throws ParseException { XsDateTimeFormat format = new XsDateTimeFormat(); String time = "2014-10-12T09Z"; Object parseObject = format.parseObject(time, true); assertTrue(parseObject instanceof Calendar); Calendar cal = (Calendar) parseObject; int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); int hours = cal.get(Calendar.HOUR); int mins = cal.get(Calendar.MINUTE); int sec = cal.get(Calendar.SECOND); int millis = cal.get(Calendar.MILLISECOND); assertEquals(year, 2014); assertEquals(month, 9); assertEquals(day, 12); assertEquals(hours, 9); assertEquals(mins, 0); assertEquals(sec, 0); assertEquals(millis, 0); }
@Test public void testWrongDateLenientIncomplete() throws ParseException { XsDateTimeFormat format = new XsDateTimeFormat(); String time = "2014-10-12T0Z"; Object parseObject = format.parseObject(time, true); assertTrue(parseObject instanceof Calendar); Calendar cal = (Calendar) parseObject; int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); int hours = cal.get(Calendar.HOUR); int mins = cal.get(Calendar.MINUTE); int sec = cal.get(Calendar.SECOND); int millis = cal.get(Calendar.MILLISECOND); assertEquals(year, 2014); assertEquals(month, 9); assertEquals(day, 12); assertEquals(hours, 0); assertEquals(mins, 0); assertEquals(sec, 0); assertEquals(millis, 0); }
@Test public void testWrongDateLenientIncompleteMins() throws ParseException { XsDateTimeFormat format = new XsDateTimeFormat(); String time = "2014-10-12T05:0Z"; Object parseObject = format.parseObject(time, true); assertTrue(parseObject instanceof Calendar); Calendar cal = (Calendar) parseObject; int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); int hours = cal.get(Calendar.HOUR); int mins = cal.get(Calendar.MINUTE); int sec = cal.get(Calendar.SECOND); int millis = cal.get(Calendar.MILLISECOND); assertEquals(year, 2014); assertEquals(month, 9); assertEquals(day, 12); assertEquals(hours, 5); assertEquals(mins, 0); assertEquals(sec, 0); assertEquals(millis, 0); }