UTCDateUtil { public Date parseUTCDateOptionalTimeZone(final String dateString) { return parseDate(dateString, DATE_FORMAT_FULL, TimeZone.getTimeZone(TIME_ZONE_UTC)); }  Date parseUTCDateOptionalTimeZone(final String dateString); String formatUTCDate(final Date sourceDate); String formatUTCDateOnly(final Date sourceDate); Date parseDate(final String dateString, final String dateFormat, final TimeZone timeZone); static final String DATE_ONLY_FORMAT; static final String DATE_FORMAT_UTC; static final String DATE_FORMAT_FULL; }
@Test public void testParseUTCDateStringWithAMHour() { try { UTCDateUtil utcDateUtil = new UTCDateUtil(); String dateString = "19650123010334"; Date parsedDate = utcDateUtil.parseUTCDateOptionalTimeZone(dateString); assertNotNull("Parsed date was null", parsedDate); Date expectedDate = createUTCDate(1965, 1, 23, 1, 3, 34); assertNotNull("Expected date was null", expectedDate); assertEquals("Expected date not equal", expectedDate, parsedDate); } catch (Throwable t) { t.printStackTrace(); fail(t.getMessage()); } }
@Test public void testParseUTCDateStringWithPMHour() { try { UTCDateUtil utcDateUtil = new UTCDateUtil(); String dateString = "19650123140334"; Date parsedDate = utcDateUtil.parseUTCDateOptionalTimeZone(dateString); assertNotNull("Parsed date was null", parsedDate); Date expectedDate = createUTCDate(1965, 1, 23, 14, 3, 34); assertNotNull("Expected date was null", expectedDate); assertEquals("Expected date not equal", expectedDate, parsedDate); System.out.println("GMT String of parsed date: " + sd.format(parsedDate)); } catch (Throwable t) { t.printStackTrace(); fail(t.getMessage()); } }
@Test public void testParseUTCDateStringWithTZPrevDay() { try { UTCDateUtil utcDateUtil = new UTCDateUtil(); String dateString = "19650122200234-0700"; Date parsedDate = utcDateUtil.parseUTCDateOptionalTimeZone(dateString); assertNotNull("Parsed date was null", parsedDate); Date expectedDate = createUTCDate(1965, 1, 23, 3, 2, 34); System.out.println("Expected date: " + sd.format(expectedDate)); System.out.println("Parsed date: " + sd.format(parsedDate)); assertNotNull("Expected date was null", expectedDate); assertEquals("Parsed date not equal", expectedDate, parsedDate); } catch (Throwable t) { t.printStackTrace(); fail(t.getMessage()); } }
@Test public void testParseUTCDateStringWithAMHourAndTZ() { try { UTCDateUtil utcDateUtil = new UTCDateUtil(); String dateString = "19650123010234-0700"; Date parsedDate = utcDateUtil.parseUTCDateOptionalTimeZone(dateString); assertNotNull("Parsed date was null", parsedDate); Date expectedDate = createUTCDate(1965, 1, 23, 8, 2, 34); assertNotNull("Expected date was null", expectedDate); assertEquals("Parsed date not equal", expectedDate, parsedDate); } catch (Throwable t) { t.printStackTrace(); fail(t.getMessage()); } }
@Test public void testParseUTCDateStringWithCrossAMPMHourAndTZ() { try { UTCDateUtil utcDateUtil = new UTCDateUtil(); String dateString = "19650123080234-0700"; Date parsedDate = utcDateUtil.parseUTCDateOptionalTimeZone(dateString); assertNotNull("Parsed date was null", parsedDate); Date expectedDate = createUTCDate(1965, 1, 23, 15, 2, 34); assertNotNull("Expected date was null", expectedDate); assertEquals("Parsed date not equal", expectedDate, parsedDate); } catch (Throwable t) { t.printStackTrace(); fail(t.getMessage()); } }
@Test public void testParseUTCDateStringWithCrossYearTZ() { try { UTCDateUtil utcDateUtil = new UTCDateUtil(); String dateString = "19641231200234-0700"; Date parsedDate = utcDateUtil.parseUTCDateOptionalTimeZone(dateString); assertNotNull("Parsed date was null", parsedDate); Date expectedDate = createUTCDate(1965, 1, 1, 3, 2, 34); assertNotNull("Expected date was null", expectedDate); assertEquals("Parsed date not equal", expectedDate, parsedDate); } catch (Throwable t) { t.printStackTrace(); fail(t.getMessage()); } }