Java Code Examples for org.joda.time.PeriodType#hours()

The following examples show how to use org.joda.time.PeriodType#hours() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrgDateTimeUtils.java    From org-java with GNU General Public License v3.0 6 votes vote down vote up
private static PeriodType getPeriodType(OrgInterval.Unit unit) {
    switch (unit) {
        case HOUR:
            return PeriodType.hours();
        case DAY:
            return PeriodType.days();
        case WEEK:
            return PeriodType.weeks();
        case MONTH:
            return PeriodType.months();
        case YEAR:
            return PeriodType.years();
        default:
            throw new IllegalArgumentException("Unknown unit " + unit);
    }
}
 
Example 2
Source File: ConfigUtils.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Helper for heuristically parsing period unit from config (e.g. 'millis', 'hour', 'd')
 *
 * @param type period type string
 * @return PeriodType
 */
static PeriodType parsePeriodType(String type) {
  type = type.toLowerCase();

  if (type.startsWith("y") || type.startsWith("a")) {
    return PeriodType.years();
  }
  if (type.startsWith("mo")) {
    return PeriodType.months();
  }
  if (type.startsWith("w")) {
    return PeriodType.weeks();
  }
  if (type.startsWith("d")) {
    return PeriodType.days();
  }
  if (type.startsWith("h")) {
    return PeriodType.hours();
  }
  if (type.startsWith("s")) {
    return PeriodType.seconds();
  }
  if (type.startsWith("mill") || type.startsWith("ms")) {
    return PeriodType.millis();
  }
  if (type.startsWith("m")) {
    return PeriodType.minutes();
  }

  throw new IllegalArgumentException(String.format("Invalid period type '%s'", type));
}
 
Example 3
Source File: BaselineAggregate.java    From incubator-pinot with Apache License 2.0 3 votes vote down vote up
/**
 * Returns an instance of BaselineAggregate for the specified type and {@code numDays} offsets
 * computed on a consecutive day-over-day basis starting with a lag of {@code offsetHours}.
 * <br/><b>NOTE:</b> this will <b>NOT</b> apply DST correction
 *
 * @see BaselineAggregateType
 *
 * @param type aggregation type
 * @param numHours number of consecutive weeks
 * @param offsetHours lag for starting consecutive weeks
 * @param timeZone time zone
 * @return BaselineAggregate with given type and daily offsets
 */
public static BaselineAggregate fromHourOverHour(BaselineAggregateType type, int numHours, int offsetHours, DateTimeZone timeZone) {
  List<Period> offsets = new ArrayList<>();
  for (int i = 0; i < numHours; i++) {
    offsets.add(new Period(0, 0, 0, 0, -1 * (i + offsetHours), 0, 0, 0, PeriodType.hours()));
  }
  return new BaselineAggregate(type, offsets, timeZone, PeriodType.hours());
}