DateTimeUtil { public static DateTime parseEmbedded(String string0) throws IllegalArgumentException { return parseEmbedded(string0, "yyyy-MM-dd", DateTimeZone.UTC); }  static DateTime toDateTime(Timestamp value); static DateTime copy(DateTime value); static Timestamp toTimestamp(DateTime dt); static DateTime now(); static DateTime parseEmbedded(String string0); static DateTime parseEmbedded(String string0, String pattern, DateTimeZone zone); static DateTime floorToYear(DateTime value); static DateTime floorToMonth(DateTime value); static DateTime floorToDay(DateTime value); static DateTime floorToHour(DateTime value); static DateTime floorToHalfHour(DateTime value); static DateTime floorToQuarterHour(DateTime value); static DateTime floorToTenMinutes(DateTime value); static DateTime floorToFiveMinutes(DateTime value); static DateTime floorToMinutePeriod(DateTime value, int periodInMinutes); static DateTime floorToMinute(DateTime value); static DateTime floorToSecond(DateTime value);  }
@Test public void parseEmbedded() throws Exception { DateTime dt0 = DateTimeUtil.parseEmbedded("app-2009-06-24.log.gz", "yyyy-MM-dd", DateTimeZone.UTC); logger.debug("dt = " + dt0); Assert.assertEquals(new DateTime(2009,6,24,0,0,0,0,DateTimeZone.UTC), dt0); dt0 = DateTimeUtil.parseEmbedded("app-2009-06-24-051112.log.gz", "yyyy-MM-dd-hhmmss", DateTimeZone.UTC); logger.debug("dt = " + dt0); Assert.assertEquals(new DateTime(2009,6,24,5,11,12,0,DateTimeZone.UTC), dt0); dt0 = DateTimeUtil.parseEmbedded("app-20090624-051112.log.gz", "yyyyMMdd-hhmmss", DateTimeZone.UTC); logger.debug("dt = " + dt0); Assert.assertEquals(new DateTime(2009,6,24,5,11,12,0,DateTimeZone.UTC), dt0); dt0 = DateTimeUtil.parseEmbedded("app-200906.log.gz", "yyyyMM", DateTimeZone.UTC); logger.debug("dt = " + dt0); Assert.assertEquals(new DateTime(2009,6,1,0,0,0,0,DateTimeZone.UTC), dt0); try { dt0 = DateTimeUtil.parseEmbedded("app-200906.log.gz", "yyyyMMdd", DateTimeZone.UTC); Assert.fail("parse should have failed"); } catch (IllegalArgumentException e) { } try { dt0 = DateTimeUtil.parseEmbedded("app-20090631.log.gz", "yyyyMMdd", DateTimeZone.UTC); Assert.fail("parse should have failed"); } catch (IllegalArgumentException e) { } try { dt0 = DateTimeUtil.parseEmbedded("app-20090631.log.gz", "yyyyMMtt", DateTimeZone.UTC); Assert.fail("parse should have failed"); } catch (IllegalArgumentException e) { } }
@Test(expected=IllegalArgumentException.class) public void parseEmbeddedThrowsException0() throws Exception { DateTimeUtil.parseEmbedded("app.2008-05-0.log"); }
@Test(expected=IllegalArgumentException.class) public void parseEmbeddedThrowsException1() throws Exception { DateTimeUtil.parseEmbedded("app.2008-0-01.log"); }
@Test(expected=IllegalArgumentException.class) public void parseEmbeddedThrowsException2() throws Exception { DateTimeUtil.parseEmbedded("app.208-05-01.log"); }