Java Code Examples for org.joda.time.DurationField#getUnitMillis()

The following examples show how to use org.joda.time.DurationField#getUnitMillis() . 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: PreciseDateTimeField.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor.
 * 
 * @param type  the field type this field uses
 * @param unit  precise unit duration, like "seconds()".
 * @param range precise range duration, preferably a multiple of the unit,
 * like "minutes()".
 * @throws IllegalArgumentException if either duration field is imprecise
 * @throws IllegalArgumentException if unit milliseconds is less than one
 * or effective value range is less than two.
 */
public PreciseDateTimeField(DateTimeFieldType type,
                            DurationField unit, DurationField range) {
    super(type, unit);

    if (!range.isPrecise()) {
        throw new IllegalArgumentException("Range duration field must be precise");
    }

    long rangeMillis = range.getUnitMillis();
    iRange = (int)(rangeMillis / getUnitMillis());
    if (iRange < 2) {
        throw new IllegalArgumentException("The effective range must be at least 2");
    }

    iRangeField = range;
}
 
Example 2
Source File: PreciseDateTimeField.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor.
 * 
 * @param type  the field type this field uses
 * @param unit  precise unit duration, like "seconds()".
 * @param range precise range duration, preferably a multiple of the unit,
 * like "minutes()".
 * @throws IllegalArgumentException if either duration field is imprecise
 * @throws IllegalArgumentException if unit milliseconds is less than one
 * or effective value range is less than two.
 */
public PreciseDateTimeField(DateTimeFieldType type,
                            DurationField unit, DurationField range) {
    super(type, unit);

    if (!range.isPrecise()) {
        throw new IllegalArgumentException("Range duration field must be precise");
    }

    long rangeMillis = range.getUnitMillis();
    iRange = (int)(rangeMillis / getUnitMillis());
    if (iRange < 2) {
        throw new IllegalArgumentException("The effective range must be at least 2");
    }

    iRangeField = range;
}
 
Example 3
Source File: MillisDurationField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public int compareTo(DurationField otherField) {
    long otherMillis = otherField.getUnitMillis();
    long thisMillis = getUnitMillis();
    // cannot do (thisMillis - otherMillis) as can overflow
    if (thisMillis == otherMillis) {
        return 0;
    }
    if (thisMillis < otherMillis) {
        return -1;
    } else {
        return 1;
    }
}
 
Example 4
Source File: BaseDurationField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public int compareTo(DurationField otherField) {
    long otherMillis = otherField.getUnitMillis();
    long thisMillis = getUnitMillis();
    // cannot do (thisMillis - otherMillis) as can overflow
    if (thisMillis == otherMillis) {
        return 0;
    }
    if (thisMillis < otherMillis) {
        return -1;
    } else {
        return 1;
    }
}
 
Example 5
Source File: PreciseDurationDateTimeField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor.
 * 
 * @param type  the field type
 * @param unit  precise unit duration, like "days()".
 * @throws IllegalArgumentException if duration field is imprecise
 * @throws IllegalArgumentException if unit milliseconds is less than one
 */
public PreciseDurationDateTimeField(DateTimeFieldType type, DurationField unit) {
    super(type);

    if (!unit.isPrecise()) {
        throw new IllegalArgumentException("Unit duration field must be precise");
    }

    iUnitMillis = unit.getUnitMillis();
    if (iUnitMillis < 1) {
        throw new IllegalArgumentException("The unit milliseconds must be at least 1");
    }

    iUnitField = unit;
}
 
Example 6
Source File: MillisDurationField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public int compareTo(DurationField otherField) {
    long otherMillis = otherField.getUnitMillis();
    long thisMillis = getUnitMillis();
    // cannot do (thisMillis - otherMillis) as can overflow
    if (thisMillis == otherMillis) {
        return 0;
    }
    if (thisMillis < otherMillis) {
        return -1;
    } else {
        return 1;
    }
}
 
Example 7
Source File: BaseDurationField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public int compareTo(DurationField otherField) {
    long otherMillis = otherField.getUnitMillis();
    long thisMillis = getUnitMillis();
    // cannot do (thisMillis - otherMillis) as can overflow
    if (thisMillis == otherMillis) {
        return 0;
    }
    if (thisMillis < otherMillis) {
        return -1;
    } else {
        return 1;
    }
}
 
Example 8
Source File: PreciseDurationDateTimeField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor.
 * 
 * @param type  the field type
 * @param unit  precise unit duration, like "days()".
 * @throws IllegalArgumentException if duration field is imprecise
 * @throws IllegalArgumentException if unit milliseconds is less than one
 */
public PreciseDurationDateTimeField(DateTimeFieldType type, DurationField unit) {
    super(type);

    if (!unit.isPrecise()) {
        throw new IllegalArgumentException("Unit duration field must be precise");
    }

    iUnitMillis = unit.getUnitMillis();
    if (iUnitMillis < 1) {
        throw new IllegalArgumentException("The unit milliseconds must be at least 1");
    }

    iUnitField = unit;
}
 
Example 9
Source File: Time_26_ZonedChronology_t.java    From coming with MIT License 4 votes vote down vote up
static boolean useTimeArithmetic(DurationField field) {
    // Use time of day arithmetic rules for unit durations less than
    // typical time zone offsets.
    return field != null && field.getUnitMillis() < DateTimeConstants.MILLIS_PER_HOUR * 12;
}
 
Example 10
Source File: Time_26_ZonedChronology_s.java    From coming with MIT License 4 votes vote down vote up
static boolean useTimeArithmetic(DurationField field) {
    // Use time of day arithmetic rules for unit durations less than
    // typical time zone offsets.
    return field != null && field.getUnitMillis() < DateTimeConstants.MILLIS_PER_HOUR * 12;
}
 
Example 11
Source File: ZonedChronology.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
static boolean useTimeArithmetic(DurationField field) {
    // Use time of day arithmetic rules for unit durations less than
    // typical time zone offsets.
    return field != null && field.getUnitMillis() < DateTimeConstants.MILLIS_PER_HOUR * 12;
}
 
Example 12
Source File: ZonedChronology.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
static boolean useTimeArithmetic(DurationField field) {
    // Use time of day arithmetic rules for unit durations less than
    // typical time zone offsets.
    return field != null && field.getUnitMillis() < DateTimeConstants.MILLIS_PER_HOUR * 12;
}