DateUtils { public static long parseIso8601(@Nullable String timeStamp) throws ParseException { if (timeStamp == null) { throw new ParseException("Unable to parse null timestamp", -1); } try { synchronized (lock) { try { return ISO_DATE_FORMAT.parse(timeStamp).getTime(); } catch (ParseException ignored) { return ALT_ISO_DATE_FORMAT.parse(timeStamp).getTime(); } } } catch (Exception e) { throw new ParseException("Unexpected issue when attempting to parse " + timeStamp + " - " + e.getMessage(), -1); } } private  DateUtils(); static long parseIso8601(@Nullable String timeStamp); static long parseIso8601(@NonNull String timeStamp, long defaultValue); @NonNull static String createIso8601TimeStamp(long milliseconds);  }
@Test public void testParseNullStringException() throws ParseException { exception.expect(ParseException.class); assertEquals(-1, DateUtils.parseIso8601(null)); }
@Test public void testParseInvalidStringException() throws ParseException { exception.expect(ParseException.class); assertEquals(-1, DateUtils.parseIso8601("wat")); }
@Test public void testParseInvalidStringDefaultValue() { assertEquals(-1, DateUtils.parseIso8601("wat", -1)); assertEquals(-2, DateUtils.parseIso8601("", -2)); assertEquals(-3, DateUtils.parseIso8601(null, -3)); }
@Test public void testParseTimeStamp() { assertEquals(1427889600000l, DateUtils.parseIso8601("2015-04-01 12:00:00", -1)); assertEquals(1427889600000l, DateUtils.parseIso8601("2015-04-01T12:00:00", -1)); }