DateTimeUtil { public static DateTime floorToFiveMinutes(DateTime value) { return floorToMinutePeriod(value, 5); }  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 floorToFiveMinutes() throws Exception { DateTime dt0 = new DateTime(2009,6,24,23,30,30,789,DateTimeZone.forID("America/Los_Angeles")); DateTime dt1 = DateTimeUtil.floorToFiveMinutes(dt0); Assert.assertEquals(2009, dt1.getYear()); Assert.assertEquals(6, dt1.getMonthOfYear()); Assert.assertEquals(24, dt1.getDayOfMonth()); Assert.assertEquals(23, dt1.getHourOfDay()); Assert.assertEquals(30, dt1.getMinuteOfHour()); Assert.assertEquals(0, dt1.getSecondOfMinute()); Assert.assertEquals(0, dt1.getMillisOfSecond()); Assert.assertEquals(DateTimeZone.forID("America/Los_Angeles"), dt1.getZone()); DateTime dt2 = DateTimeUtil.floorToFiveMinutes(null); Assert.assertNull(dt2); DateTime dt3 = DateTimeUtil.floorToFiveMinutes(new DateTime(2009,6,24,10,0,0,0)); Assert.assertEquals(new DateTime(2009,6,24,10,0,0,0), dt3); dt3 = DateTimeUtil.floorToFiveMinutes(new DateTime(2009,6,24,10,1,23,456)); Assert.assertEquals(new DateTime(2009,6,24,10,0,0,0), dt3); dt3 = DateTimeUtil.floorToFiveMinutes(new DateTime(2009,6,24,10,2,12,56)); Assert.assertEquals(new DateTime(2009,6,24,10,0,0,0), dt3); dt3 = DateTimeUtil.floorToFiveMinutes(new DateTime(2009,6,24,10,59,59,999)); Assert.assertEquals(new DateTime(2009,6,24,10,55,0,0), dt3); dt3 = DateTimeUtil.floorToFiveMinutes(new DateTime(2009,6,24,10,55,59,999)); Assert.assertEquals(new DateTime(2009,6,24,10,55,0,0), dt3); dt3 = DateTimeUtil.floorToFiveMinutes(new DateTime(2009,6,24,10,46,59,999)); Assert.assertEquals(new DateTime(2009,6,24,10,45,0,0), dt3); }