Example usage for org.joda.time Hours THREE

List of usage examples for org.joda.time Hours THREE

Introduction

In this page you can find the example usage for org.joda.time Hours THREE.

Prototype

Hours THREE

To view the source code for org.joda.time Hours THREE.

Click Source Link

Document

Constant representing three hours.

Usage

From source file:org.sleuthkit.autopsy.timeline.utils.RangeDivisionInfo.java

License:Open Source License

/**
 * Static factory method./*w w  w  . ja  v  a  2 s  .  com*/
 *
 * Determine the period size, number of periods, whole period bounds, and
 * formatters to use to visualize the given timerange.
 *
 * @param timeRange
 *
 * @return
 */
public static RangeDivisionInfo getRangeDivisionInfo(Interval timeRange) {
    //Check from largest to smallest unit

    //TODO: make this more generic... reduce code duplication -jm
    DateTimeFieldType timeUnit;
    final DateTime startWithZone = timeRange.getStart().withZone(TimeLineController.getJodaTimeZone());
    final DateTime endWithZone = timeRange.getEnd().withZone(TimeLineController.getJodaTimeZone());

    if (Years.yearsIn(timeRange).isGreaterThan(Years.THREE)) {
        timeUnit = DateTimeFieldType.year();
        long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis();
        long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis();
        return new RangeDivisionInfo(timeRange, Years.yearsIn(timeRange).get(timeUnit.getDurationType()) + 1,
                TimeUnits.YEARS, ISODateTimeFormat.year(), lower, upper);
    } else if (Months.monthsIn(timeRange).isGreaterThan(Months.THREE)) {
        timeUnit = DateTimeFieldType.monthOfYear();
        long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis();
        long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis();
        return new RangeDivisionInfo(timeRange, Months.monthsIn(timeRange).getMonths() + 1, TimeUnits.MONTHS,
                DateTimeFormat.forPattern("YYYY'-'MMMM"), lower, upper); // NON-NLS
    } else if (Days.daysIn(timeRange).isGreaterThan(Days.THREE)) {
        timeUnit = DateTimeFieldType.dayOfMonth();
        long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis();
        long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis();
        return new RangeDivisionInfo(timeRange, Days.daysIn(timeRange).getDays() + 1, TimeUnits.DAYS,
                DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd"), lower, upper); // NON-NLS
    } else if (Hours.hoursIn(timeRange).isGreaterThan(Hours.THREE)) {
        timeUnit = DateTimeFieldType.hourOfDay();
        long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis();
        long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis();
        return new RangeDivisionInfo(timeRange, Hours.hoursIn(timeRange).getHours() + 1, TimeUnits.HOURS,
                DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd HH"), lower, upper); // NON-NLS
    } else if (Minutes.minutesIn(timeRange).isGreaterThan(Minutes.THREE)) {
        timeUnit = DateTimeFieldType.minuteOfHour();
        long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis();
        long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis();
        return new RangeDivisionInfo(timeRange, Minutes.minutesIn(timeRange).getMinutes() + 1,
                TimeUnits.MINUTES, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd HH':'mm"), lower, upper); // NON-NLS
    } else {
        timeUnit = DateTimeFieldType.secondOfMinute();
        long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis();
        long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis();
        return new RangeDivisionInfo(timeRange, Seconds.secondsIn(timeRange).getSeconds() + 1,
                TimeUnits.SECONDS, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd HH':'mm':'ss"), lower, upper); // NON-NLS
    }
}