public static DateTime floor(DateTime date, HistogramIntervalType interval) {
        DateTime rval = date.withMillisOfSecond(0);

        switch (interval) {
        case day:
            rval = rval.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
            break;
        case hour:
            rval = rval.withMinuteOfHour(0).withSecondOfMinute(0);
            break;
        case minute:
            rval = rval.withSecondOfMinute(0);
            break;
        case month:
            rval = rval.withDayOfMonth(1).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
            break;
        case week:
            rval = rval.withDayOfWeek(DateTimeConstants.MONDAY).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
            break;
        }

        return rval;
    }
Based on the given interval, create a "floor" value relative to the
given date.  This basically means zero'ing out certain fields (different
fields based on the interval type) and returning the modified date.
@param date the date
@param interval the interval
manager/api/core/src/main/java/io/apiman/manager/api/core/metrics/MetricsAccessorHelper.java