List of usage examples for org.joda.time DateTimeConstants MILLIS_PER_HOUR
int MILLIS_PER_HOUR
To view the source code for org.joda.time DateTimeConstants MILLIS_PER_HOUR.
Click Source Link
From source file:com.music.service.text.TimelineToMusicService.java
License:Open Source License
/** * Gets the tempo, depending on the rate of tweeting * * @param tweets//from ww w. j a va 2 s .co m * @return tempo */ private Tempo getTempo(List<Tweet> tweets, TimelineMusic meta) { long totalSpacingInMillis = 0; Tweet previousTweet = null; for (Tweet tweet : tweets) { if (previousTweet != null) { totalSpacingInMillis += Math .abs(previousTweet.getCreatedAt().getTime() - tweet.getCreatedAt().getTime()); } previousTweet = tweet; } double averageSpacing = totalSpacingInMillis / (tweets.size() - 1); meta.setAverageSpacing(averageSpacing); if (averageSpacing > 3 * DateTimeConstants.MILLIS_PER_DAY) { //once every three days return Tempo.VERY_SLOW; } else if (averageSpacing > 1.5 * DateTimeConstants.MILLIS_PER_DAY) { // more than once every 1.5 days return Tempo.SLOW; } else if (averageSpacing > 16 * DateTimeConstants.MILLIS_PER_HOUR) { // more than once every 16 hours return Tempo.MEDIUM; } else if (averageSpacing > 4 * DateTimeConstants.MILLIS_PER_HOUR) { // more than once every 4 hours return Tempo.FAST; } else { return Tempo.VERY_FAST; } }
From source file:influent.server.utilities.DateTimeParser.java
License:MIT License
/** * @see http://joda-time.sourceforge.net/apidocs/org/joda/time/Period.html#normalizedStandard() *//*from w ww . ja v a 2s.com*/ public static Period normalize(Period period) { long millis = period.getMillis(); millis += period.getSeconds() * DateTimeConstants.MILLIS_PER_SECOND; millis += period.getMinutes() * DateTimeConstants.MILLIS_PER_MINUTE; millis += period.getHours() * DateTimeConstants.MILLIS_PER_HOUR; millis += period.getDays() * DateTimeConstants.MILLIS_PER_DAY; millis += period.getWeeks() * DateTimeConstants.MILLIS_PER_WEEK; Period result = new Period(millis, DateTimeUtils.getPeriodType(PeriodType.standard()), ISOChronology.getInstanceUTC()); int years = period.getYears(); int months = period.getMonths(); if (years != 0 || months != 0) { years = FieldUtils.safeAdd(years, months / 12); months = months % 12; if (years != 0) { result = result.withYears(years); } if (months != 0) { result = result.withMonths(months); } } return result; }
From source file:job.myprojects.Task.java
License:Open Source License
private BigDecimal calcDuration() { if (startTime != null && endTime != null && startTime.before(endTime)) { Duration duration = new Duration(startTime.getTime(), endTime.getTime()); return new BigDecimal(duration.getMillis() / (1.0 * DateTimeConstants.MILLIS_PER_HOUR)); }/*from www.j a v a2s . c o m*/ return BigDecimal.ZERO; }
From source file:org.integratedmodelling.time.literals.DurationValue.java
License:Open Source License
/** * Localize a duration to an extent starting at the current moment * using the same resolution that was implied in the generating * text. For example, if the duration was one year, localize to the * current year (jan 1st to dec 31st). Return the start and end points * of the extent./*from w ww .j a v a2 s . co m*/ * * @return */ public Pair<TimeValue, TimeValue> localize() { DateTime date = new DateTime(); TimeValue start = null, end = null; long val = value; switch (precision) { case TemporalPrecision.MILLISECOND: start = new TimeValue(date); end = new TimeValue(date.plus(val)); break; case TemporalPrecision.SECOND: val = value / DateTimeConstants.MILLIS_PER_SECOND; start = new TimeValue(new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.getHourOfDay(), date.getMinuteOfHour(), date.getSecondOfMinute(), 0)); end = new TimeValue(start.getTimeData().plusSeconds((int) val)); break; case TemporalPrecision.MINUTE: val = value / DateTimeConstants.MILLIS_PER_MINUTE; start = new TimeValue(new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.getHourOfDay(), date.getMinuteOfHour(), 0, 0)); end = new TimeValue(start.getTimeData().plusMinutes((int) val)); break; case TemporalPrecision.HOUR: val = value / DateTimeConstants.MILLIS_PER_HOUR; start = new TimeValue(new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.getHourOfDay(), 0, 0, 0)); end = new TimeValue(start.getTimeData().plusHours((int) val)); break; case TemporalPrecision.DAY: val = value / DateTimeConstants.MILLIS_PER_DAY; start = new TimeValue( new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), 0, 0, 0, 0)); end = new TimeValue(start.getTimeData().plusDays((int) val)); break; case TemporalPrecision.MONTH: start = new TimeValue(new DateTime(date.getYear(), date.getMonthOfYear(), 1, 0, 0, 0, 0)); end = new TimeValue(start.getTimeData().plusMonths(origQuantity)); break; case TemporalPrecision.YEAR: start = new TimeValue(new DateTime(date.getYear(), 1, 1, 0, 0, 0, 0)); end = new TimeValue(start.getTimeData().plusYears(origQuantity)); break; } return new Pair<TimeValue, TimeValue>(start, end); }
From source file:org.springframework.cloud.dataflow.shell.command.AggregateCounterCommands.java
License:Apache License
@CliCommand(value = DISPLAY_AGGR_COUNTER, help = "Display aggregate counter values by chosen interval and resolution(minute, hour)") public Table display( @CliOption(key = { "", "name" }, help = "the name of the aggregate counter to display", mandatory = true) String name, @CliOption(key = "from", help = "start-time for the interval. format: 'yyyy-MM-dd HH:mm:ss'", mandatory = false) String from, @CliOption(key = "to", help = "end-time for the interval. format: 'yyyy-MM-dd HH:mm:ss'. defaults to now", mandatory = false) String to, @CliOption(key = "lastHours", help = "set the interval to last 'n' hours", mandatory = false) Integer lastHours, @CliOption(key = "lastDays", help = "set the interval to last 'n' days", mandatory = false) Integer lastDays, @CliOption(key = "resolution", help = "the size of the bucket to aggregate (minute, hour, day, month)", mandatory = false, unspecifiedDefaultValue = "hour") AggregateCounterOperations.Resolution resolution, @CliOption(key = "pattern", help = "the pattern used to format the count values (see DecimalFormat)", mandatory = false, unspecifiedDefaultValue = NumberFormatConverter.DEFAULT) NumberFormat pattern) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try {//w ww. j a v a 2s .com Date fromDate; switch (Assertions.atMostOneOf("from", from, "lastHours", lastHours, "lastDays", lastDays)) { case 0: fromDate = dateFormat.parse(from); break; case 1: fromDate = new Date( System.currentTimeMillis() - ((long) lastHours) * DateTimeConstants.MILLIS_PER_HOUR); break; case 2: fromDate = new Date( System.currentTimeMillis() - ((long) lastDays) * DateTimeConstants.MILLIS_PER_DAY); break; default: fromDate = null; break; } Date toDate = (to == null) ? null : dateFormat.parse(to); AggregateCounterResource aggResource = aggregateCounterOperations().retrieve(name, fromDate, toDate, resolution); return displayAggrCounter(aggResource, pattern); } catch (ParseException pe) { throw new IllegalArgumentException( "Parse exception ocurred while parsing the 'from/to' options. The accepted date format is " + dateFormat.toPattern()); } }
From source file:org.springframework.cloud.dataflow.shell.command.common.AggregateCounterCommands.java
License:Apache License
@CliCommand(value = DISPLAY_AGGR_COUNTER, help = "Display aggregate counter values by chosen interval and " + "resolution(minute, hour)") public Table display( @CliOption(optionContext = "existing-aggregate-counter disable-string-converter", key = { "", "name" }, help = "the name of the aggregate counter to display", mandatory = true) String name, @CliOption(key = "from", help = "start-time for the interval. format: 'yyyy-MM-dd HH:mm:ss'", mandatory = false) String from, @CliOption(key = "to", help = "end-time for the interval. format: 'yyyy-MM-dd HH:mm:ss'. defaults to " + "now", mandatory = false) String to, @CliOption(key = "lastHours", help = "set the interval to last 'n' hours", mandatory = false) Integer lastHours, @CliOption(key = "lastDays", help = "set the interval to last 'n' days", mandatory = false) Integer lastDays, @CliOption(key = "resolution", help = "the size of the bucket to aggregate (minute, hour, day, month)", mandatory = false, unspecifiedDefaultValue = "hour") AggregateCounterOperations.Resolution resolution, @CliOption(key = "pattern", help = "the pattern used to format the count values (see DecimalFormat)", mandatory = false, unspecifiedDefaultValue = NumberFormatConverter.DEFAULT) NumberFormat pattern) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try {/* w ww . java 2 s .c o m*/ Date fromDate; switch (Assertions.atMostOneOf("from", from, "lastHours", lastHours, "lastDays", lastDays)) { case 0: fromDate = dateFormat.parse(from); break; case 1: fromDate = new Date( System.currentTimeMillis() - ((long) lastHours) * DateTimeConstants.MILLIS_PER_HOUR); break; case 2: fromDate = new Date( System.currentTimeMillis() - ((long) lastDays) * DateTimeConstants.MILLIS_PER_DAY); break; default: fromDate = null; break; } Date toDate = (to == null) ? null : dateFormat.parse(to); AggregateCounterResource aggResource = aggregateCounterOperations().retrieve(name, fromDate, toDate, resolution); return displayAggrCounter(aggResource, pattern); } catch (ParseException pe) { throw new IllegalArgumentException( "Parse exception ocurred while parsing the 'from/to' options. The accepted date format is " + dateFormat.toPattern()); } }
From source file:org.springframework.xd.shell.command.AggregateCounterCommands.java
License:Apache License
@CliCommand(value = DISPLAY_AGGR_COUNTER, help = "Display aggregate counter values by chosen interval and resolution(minute, hour)") public Table display(@CliOption(key = { "", "name" }, help = "the name of the aggregate counter to display", mandatory = true, optionContext = "existing-aggregate-counter disable-string-converter") String name, @CliOption(key = "from", help = "start-time for the interval. format: 'yyyy-MM-dd HH:mm:ss'", mandatory = false) String from, @CliOption(key = "to", help = "end-time for the interval. format: 'yyyy-MM-dd HH:mm:ss'. defaults to now", mandatory = false) String to, @CliOption(key = "lastHours", help = "set the interval to last 'n' hours", mandatory = false) Integer lastHours, @CliOption(key = "lastDays", help = "set the interval to last 'n' days", mandatory = false) Integer lastDays, @CliOption(key = "resolution", help = "the size of the bucket to aggregate (minute, hour, day, month)", mandatory = false, unspecifiedDefaultValue = "hour") Resolution resolution, @CliOption(key = "pattern", help = "the pattern used to format the count values (see DecimalFormat)", mandatory = false, unspecifiedDefaultValue = NumberFormatConverter.DEFAULT) NumberFormat pattern) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try {/* w w w.j a v a 2 s . c o m*/ Date fromDate; switch (Assertions.atMostOneOf("from", from, "lastHours", lastHours, "lastDays", lastDays)) { case 0: fromDate = dateFormat.parse(from); break; case 1: fromDate = new Date( System.currentTimeMillis() - ((long) lastHours) * DateTimeConstants.MILLIS_PER_HOUR); break; case 2: fromDate = new Date( System.currentTimeMillis() - ((long) lastDays) * DateTimeConstants.MILLIS_PER_DAY); break; default: fromDate = null; break; } Date toDate = (to == null) ? null : dateFormat.parse(to); AggregateCountsResource aggResource = aggrCounterOperations().retrieve(name, fromDate, toDate, resolution); return displayAggrCounter(aggResource, pattern); } catch (ParseException pe) { throw new IllegalArgumentException( "Parse exception ocurred while parsing the 'from/to' options. The accepted date format is " + dateFormat.toPattern()); } }
From source file:org.wso2.analytics.esb.util.TimeRangeUtils.java
License:Open Source License
public static List<TimeRange> getDateTimeRanges(long from, long to) { List<TimeRange> ranges = new ArrayList<>(10); MutableDateTime fromDate = new MutableDateTime(from); fromDate.set(DateTimeFieldType.millisOfSecond(), 0); MutableDateTime toDate = new MutableDateTime(to); toDate.set(DateTimeFieldType.millisOfSecond(), 0); MutableDateTime tempFromTime = fromDate.copy(); MutableDateTime tempToTime = toDate.copy(); if (log.isDebugEnabled()) { log.debug("Time range: " + formatter.format(fromDate.toDate()) + " -> " + formatter.format(toDate.toDate())); }/* w w w . j a v a 2 s. c om*/ if (toDate.getMillis() - fromDate.getMillis() < DateTimeConstants.MILLIS_PER_MINUTE) { ranges.add(new TimeRange(RangeUnit.SECOND.name(), new long[] { fromDate.getMillis(), toDate.getMillis() })); } else { if (tempFromTime.getSecondOfMinute() != 0 && (toDate.getMillis() - fromDate.getMillis() > DateTimeConstants.MILLIS_PER_MINUTE)) { tempFromTime = tempFromTime.minuteOfHour().roundCeiling(); ranges.add(new TimeRange(RangeUnit.SECOND.name(), new long[] { fromDate.getMillis(), tempFromTime.getMillis() })); } if (tempFromTime.getMinuteOfHour() != 0 && ((toDate.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_MINUTE)) { fromDate = tempFromTime.copy(); if (((toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_MINUTE) < 60) { tempFromTime = tempFromTime.minuteOfHour().add( (toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_MINUTE); } else { tempFromTime = tempFromTime.hourOfDay().roundCeiling(); } ranges.add(new TimeRange(RangeUnit.MINUTE.name(), new long[] { fromDate.getMillis(), tempFromTime.getMillis() })); } if (tempFromTime.getHourOfDay() != 0 && ((toDate.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_HOUR)) { fromDate = tempFromTime.copy(); if (((toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_HOUR) < 24) { tempFromTime = tempFromTime.hourOfDay().add( (toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_HOUR); } else { tempFromTime = tempFromTime.dayOfMonth().roundCeiling(); } ranges.add(new TimeRange(RangeUnit.HOUR.name(), new long[] { fromDate.getMillis(), tempFromTime.getMillis() })); } if (tempFromTime.getDayOfMonth() != 1 && ((toDate.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_DAY)) { fromDate = tempFromTime.copy(); if ((((toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_DAY)) < tempFromTime.dayOfMonth().getMaximumValue()) { tempFromTime = tempFromTime.dayOfMonth().add(((toDate.getMillis() - tempFromTime.getMillis()) / ((long) DateTimeConstants.MILLIS_PER_DAY))); } else { tempFromTime = tempFromTime.monthOfYear().roundCeiling(); } ranges.add(new TimeRange(RangeUnit.DAY.name(), new long[] { fromDate.getMillis(), tempFromTime.getMillis() })); } if (tempToTime.getSecondOfMinute() != 0 && (tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_SECOND) { toDate = tempToTime.copy(); long remainingSeconds = ((toDate.getMillis() - tempFromTime.getMillis()) % DateTimeConstants.MILLIS_PER_MINUTE) / DateTimeConstants.MILLIS_PER_SECOND; if (remainingSeconds < 60) { tempToTime = tempToTime.secondOfMinute().add(-1 * remainingSeconds); } else { tempToTime = tempToTime.secondOfMinute().roundFloor(); } ranges.add(new TimeRange(RangeUnit.SECOND.name(), new long[] { tempToTime.getMillis(), toDate.getMillis() })); } if (tempToTime.getMinuteOfHour() != 0 && ((tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_MINUTE)) { toDate = tempToTime.copy(); long remainingMinutes = ((toDate.getMillis() - tempFromTime.getMillis()) % DateTimeConstants.MILLIS_PER_HOUR) / DateTimeConstants.MILLIS_PER_MINUTE; if (remainingMinutes < 60) { tempToTime = tempToTime.minuteOfHour().add(-1 * remainingMinutes); } else { tempToTime = tempToTime.hourOfDay().roundFloor(); } ranges.add(new TimeRange(RangeUnit.MINUTE.name(), new long[] { tempToTime.getMillis(), toDate.getMillis() })); } if (tempToTime.getHourOfDay() != 0 && ((tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_HOUR)) { toDate = tempToTime.copy(); long remainingHours = ((toDate.getMillis() - tempFromTime.getMillis()) % DateTimeConstants.MILLIS_PER_DAY) / DateTimeConstants.MILLIS_PER_HOUR; if (remainingHours < 24) { tempToTime = tempToTime.hourOfDay().add(-1 * remainingHours); } else { tempToTime = tempToTime.dayOfMonth().roundFloor(); } ranges.add(new TimeRange(RangeUnit.HOUR.name(), new long[] { tempToTime.getMillis(), toDate.getMillis() })); } if (tempToTime.getDayOfMonth() != 1 && ((tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_DAY)) { toDate = tempToTime.copy(); tempToTime = tempToTime.monthOfYear().roundFloor(); ranges.add(new TimeRange(RangeUnit.DAY.name(), new long[] { tempToTime.getMillis(), toDate.getMillis() })); } if (tempToTime.isAfter(tempFromTime)) { ranges.add(new TimeRange(RangeUnit.MONTH.name(), new long[] { tempFromTime.getMillis(), tempToTime.getMillis() })); } } if (log.isDebugEnabled()) { for (TimeRange timeRange : ranges) { log.debug("Unit: " + timeRange.getUnit() + " Range: " + formatter.format(new Date(timeRange.getRange()[0])) + "(" + timeRange.getRange()[0] + ")->" + formatter.format(new Date(timeRange.getRange()[1])) + "(" + timeRange.getRange()[1] + ")"); } } return ranges; }
From source file:org.wso2.analytics.shared.util.time.TimeRangeUtils.java
License:Open Source License
public static List<TimeRange> getDateTimeRanges(long from, long to) { List<TimeRange> ranges = new ArrayList<>(10); MutableDateTime fromDate = new MutableDateTime(from); fromDate.set(DateTimeFieldType.millisOfSecond(), 0); MutableDateTime toDate = new MutableDateTime(to); toDate.set(DateTimeFieldType.millisOfSecond(), 0); MutableDateTime tempFromTime = fromDate.copy(); MutableDateTime tempToTime = toDate.copy(); if (log.isDebugEnabled()) { log.debug("Time range: " + formatter.format(fromDate.toDate()) + "->" + formatter.format(toDate.toDate())); }/*from www. jav a 2 s . c o m*/ if (toDate.getMillis() - fromDate.getMillis() < DateTimeConstants.MILLIS_PER_MINUTE) { ranges.add(new TimeRange(RangeUnit.SECOND.name(), new long[] { fromDate.getMillis(), toDate.getMillis() })); } else { if (tempFromTime.getSecondOfMinute() != 0 && (toDate.getMillis() - fromDate.getMillis() > DateTimeConstants.MILLIS_PER_MINUTE)) { tempFromTime = tempFromTime.minuteOfHour().roundCeiling(); ranges.add(new TimeRange(RangeUnit.SECOND.name(), new long[] { fromDate.getMillis(), tempFromTime.getMillis() })); } if (tempFromTime.getMinuteOfHour() != 0 && ((toDate.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_MINUTE)) { fromDate = tempFromTime.copy(); if (((toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_MINUTE) < 60) { tempFromTime = tempFromTime.minuteOfHour().add( (toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_MINUTE); } else { tempFromTime = tempFromTime.hourOfDay().roundCeiling(); } ranges.add(new TimeRange(RangeUnit.MINUTE.name(), new long[] { fromDate.getMillis(), tempFromTime.getMillis() })); } if (tempFromTime.getHourOfDay() != 0 && ((toDate.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_HOUR)) { fromDate = tempFromTime.copy(); if (((toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_HOUR) < 24) { tempFromTime = tempFromTime.hourOfDay().add( (toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_HOUR); } else { tempFromTime = tempFromTime.dayOfMonth().roundCeiling(); } ranges.add(new TimeRange(RangeUnit.HOUR.name(), new long[] { fromDate.getMillis(), tempFromTime.getMillis() })); } if (tempFromTime.getDayOfMonth() != 1 && ((toDate.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_DAY)) { fromDate = tempFromTime.copy(); if ((((toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_DAY)) < tempFromTime.dayOfMonth().getMaximumValue()) { tempFromTime = tempFromTime.dayOfMonth().add(((toDate.getMillis() - tempFromTime.getMillis()) / ((long) DateTimeConstants.MILLIS_PER_DAY))); } else { tempFromTime = tempFromTime.monthOfYear().roundCeiling(); } ranges.add(new TimeRange(RangeUnit.DAY.name(), new long[] { fromDate.getMillis(), tempFromTime.getMillis() })); } if (tempToTime.getSecondOfMinute() != 0 && (tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_SECOND) { toDate = tempToTime.copy(); long remainingSeconds = ((toDate.getMillis() - tempFromTime.getMillis()) % DateTimeConstants.MILLIS_PER_MINUTE) / DateTimeConstants.MILLIS_PER_SECOND; if (remainingSeconds < 60) { tempToTime = tempToTime.secondOfMinute().add(-1 * remainingSeconds); } else { tempToTime = tempToTime.secondOfMinute().roundFloor(); } ranges.add(new TimeRange(RangeUnit.SECOND.name(), new long[] { tempToTime.getMillis(), toDate.getMillis() })); } if (tempToTime.getMinuteOfHour() != 0 && ((tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_MINUTE)) { toDate = tempToTime.copy(); long remainingMinutes = ((toDate.getMillis() - tempFromTime.getMillis()) % DateTimeConstants.MILLIS_PER_HOUR) / DateTimeConstants.MILLIS_PER_MINUTE; if (remainingMinutes < 60) { tempToTime = tempToTime.minuteOfHour().add(-1 * remainingMinutes); } else { tempToTime = tempToTime.hourOfDay().roundFloor(); } ranges.add(new TimeRange(RangeUnit.MINUTE.name(), new long[] { tempToTime.getMillis(), toDate.getMillis() })); } if (tempToTime.getHourOfDay() != 0 && ((tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_HOUR)) { toDate = tempToTime.copy(); long remainingHours = ((toDate.getMillis() - tempFromTime.getMillis()) % DateTimeConstants.MILLIS_PER_DAY) / DateTimeConstants.MILLIS_PER_HOUR; if (remainingHours < 24) { tempToTime = tempToTime.hourOfDay().add(-1 * remainingHours); } else { tempToTime = tempToTime.dayOfMonth().roundFloor(); } ranges.add(new TimeRange(RangeUnit.HOUR.name(), new long[] { tempToTime.getMillis(), toDate.getMillis() })); } if (tempToTime.getDayOfMonth() != 1 && ((tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_DAY)) { toDate = tempToTime.copy(); tempToTime = tempToTime.monthOfYear().roundFloor(); ranges.add(new TimeRange(RangeUnit.DAY.name(), new long[] { tempToTime.getMillis(), toDate.getMillis() })); } if (tempToTime.isAfter(tempFromTime)) { ranges.add(new TimeRange(RangeUnit.MONTH.name(), new long[] { tempFromTime.getMillis(), tempToTime.getMillis() })); } } if (log.isDebugEnabled()) { for (TimeRange timeRange : ranges) { log.debug("Unit: " + timeRange.getUnit() + " Range: " + formatter.format(new Date(timeRange.getRange()[0])) + "(" + timeRange.getRange()[0] + ")->" + formatter.format(new Date(timeRange.getRange()[1])) + "(" + timeRange.getRange()[1] + ")"); } } return ranges; }