Example usage for org.joda.time DurationFieldType getField

List of usage examples for org.joda.time DurationFieldType getField

Introduction

In this page you can find the example usage for org.joda.time DurationFieldType getField.

Prototype

public abstract DurationField getField(Chronology chronology);

Source Link

Document

Gets a suitable field for this type from the given Chronology.

Usage

From source file:ch.oakmountain.tpa.solver.PeriodicalTimeFrame.java

License:Apache License

/**
 * Checks if the duration type specified is supported by this
 * local datetime and chronology.//from  ww  w .  ja  v  a  2 s.  c  o  m
 *
 * @param type a duration type, usually obtained from DurationFieldType
 * @return true if the field type is supported
 */
public boolean isSupported(DurationFieldType type) {
    if (type == null) {
        return false;
    }
    return type.getField(getChronology()).isSupported();
}

From source file:org.apereo.portal.events.aggr.AggregationInterval.java

License:Apache License

/**
 * Determine the number of intervals between the start and end dates
 *
 * @param start Start, inclusive/*  w  w  w  .j a  va  2s  .co  m*/
 * @param end End, exclusive
 * @return Number of intervals between start and end
 */
public int determineIntervalsBetween(ReadableInstant start, ReadableInstant end) {
    if (!this.isSupportsDetermination()) {
        throw new IllegalArgumentException("Cannot compute intervals between for " + this + " please use "
                + AggregationIntervalHelper.class);
    }

    final DateTimeFieldType dtft;
    final double ratio;
    switch (this) {
    case FIVE_MINUTE: {
        dtft = MINUTE.getDateTimeFieldType();
        ratio = 5;
        break;
    }
    default: {
        dtft = dateTimeFieldType;
        ratio = 1;
    }
    }

    final DurationFieldType durationType = dtft.getDurationType();
    final Chronology chrono = DateTimeUtils.getInstantChronology(start);
    return (int) Math
            .round(durationType.getField(chrono).getDifference(end.getMillis(), start.getMillis()) / ratio);
}