当前位置: 首页>>代码示例>>Java>>正文


Java DurationField类代码示例

本文整理汇总了Java中org.joda.time.DurationField的典型用法代码示例。如果您正苦于以下问题:Java DurationField类的具体用法?Java DurationField怎么用?Java DurationField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DurationField类属于org.joda.time包,在下文中一共展示了DurationField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: standardPeriodIn

import org.joda.time.DurationField; //导入依赖的package包/类
/**
 * Creates a new instance representing the number of complete standard length units
 * in the specified period.
 * <p>
 * This factory method converts all fields from the period to hours using standardised
 * durations for each field. Only those fields which have a precise duration in
 * the ISO UTC chronology can be converted.
 * <ul>
 * <li>One week consists of 7 days.
 * <li>One day consists of 24 hours.
 * <li>One hour consists of 60 minutes.
 * <li>One minute consists of 60 seconds.
 * <li>One second consists of 1000 milliseconds.
 * </ul>
 * Months and Years are imprecise and periods containing these values cannot be converted.
 *
 * @param period  the period to get the number of hours from, must not be null
 * @param millisPerUnit  the number of milliseconds in one standard unit of this period
 * @throws IllegalArgumentException if the period contains imprecise duration values
 */
protected static int standardPeriodIn(ReadablePeriod period, long millisPerUnit) {
    if (period == null) {
        return 0;
    }
    Chronology iso = ISOChronology.getInstanceUTC();
    long duration = 0L;
    for (int i = 0; i < period.size(); i++) {
        int value = period.getValue(i);
        if (value != 0) {
            DurationField field = period.getFieldType(i).getField(iso);
            if (field.isPrecise() == false) {
                throw new IllegalArgumentException(
                        "Cannot convert period to duration as " + field.getName() +
                        " is not precise in the period " + period);
            }
            duration = FieldUtils.safeAdd(duration, FieldUtils.safeMultiply(field.getUnitMillis(), value));
        }
    }
    return FieldUtils.safeToInt(duration / millisPerUnit);
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:41,代码来源:BaseSingleFieldPeriod.java

示例2: getInstance

import org.joda.time.DurationField; //导入依赖的package包/类
/**
 * Gets an instance of UnsupportedDateTimeField for a specific named field.
 * Names should be of standard format, such as 'monthOfYear' or 'hourOfDay'.
 * The returned instance is cached.
 * 
 * @param type  the type to obtain
 * @return the instance
 * @throws IllegalArgumentException if durationField is null
 */
public static synchronized UnsupportedDateTimeField getInstance(
        DateTimeFieldType type, DurationField durationField) {

    UnsupportedDateTimeField field;
    if (cCache == null) {
        cCache = new HashMap<DateTimeFieldType, UnsupportedDateTimeField>(7);
        field = null;
    } else {
        field = cCache.get(type);
        if (field != null && field.getDurationField() != durationField) {
            field = null;
        }
    }
    if (field == null) {
        field = new UnsupportedDateTimeField(type, durationField);
        cCache.put(type, field);
    }
    return field;
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:29,代码来源:UnsupportedDateTimeField.java

示例3: RemainderDateTimeField

import org.joda.time.DurationField; //导入依赖的package包/类
/**
 * Constructor.
 * 
 * @param field  the field to wrap, like "year()".
 * @param type  the field type this field actually uses
 * @param divisor  divisor, such as 100 years in a century
 * @throws IllegalArgumentException if divisor is less than two
 */
public RemainderDateTimeField(DateTimeField field,
                              DateTimeFieldType type, int divisor) {
    super(field, type);

    if (divisor < 2) {
        throw new IllegalArgumentException("The divisor must be at least 2");
    }

    DurationField rangeField = field.getDurationField();
    if (rangeField == null) {
        iRangeField = null;
    } else {
        iRangeField = new ScaledDurationField(
            rangeField, type.getRangeDurationType(), divisor);
    }

    iDivisor = divisor;
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:27,代码来源:RemainderDateTimeField.java

示例4: PreciseDateTimeField

import org.joda.time.DurationField; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:28,代码来源:PreciseDateTimeField.java

示例5: ZonedDateTimeField

import org.joda.time.DurationField; //导入依赖的package包/类
ZonedDateTimeField(DateTimeField field,
                   DateTimeZone zone,
                   DurationField durationField,
                   DurationField rangeDurationField,
                   DurationField leapDurationField) {
    super(field.getType());
    if (!field.isSupported()) {
        throw new IllegalArgumentException();
    }
    iField = field;
    iZone = zone;
    iDurationField = durationField;
    iTimeField = useTimeArithmetic(durationField);
    iRangeDurationField = rangeDurationField;
    iLeapDurationField = leapDurationField;
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:17,代码来源:ZonedChronology.java

示例6: CutoverField

import org.joda.time.DurationField; //导入依赖的package包/类
/**
 * @param julianField field from the chronology used before the cutover instant
 * @param gregorianField field from the chronology used at and after the cutover
 * @param cutoverMillis  the millis of the cutover
 * @param convertByWeekyear
 */
CutoverField(DateTimeField julianField, DateTimeField gregorianField,
             long cutoverMillis, boolean convertByWeekyear) {
    super(gregorianField.getType());
    iJulianField = julianField;
    iGregorianField = gregorianField;
    iCutover = cutoverMillis;
    iConvertByWeekyear = convertByWeekyear;
    // Although average length of Julian and Gregorian years differ,
    // use the Gregorian duration field because it is more accurate.
    iDurationField = gregorianField.getDurationField();

    DurationField rangeField = gregorianField.getRangeDurationField();
    if (rangeField == null) {
        rangeField = julianField.getRangeDurationField();
    }
    iRangeDurationField = rangeField;
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:24,代码来源:GJChronology.java

示例7: get

import org.joda.time.DurationField; //导入依赖的package包/类
/**
 * Gets the values of a period from an interval.
 *
 * @param period  the period instant to use
 * @param duration  the duration to query
 * @return the values of the period extracted from the duration
 */
public int[] get(ReadablePeriod period, long duration) {
    int size = period.size();
    int[] values = new int[size];
    if (duration != 0) {
        long current = 0;
        for (int i = 0; i < size; i++) {
            DurationField field = period.getFieldType(i).getField(this);
            if (field.isPrecise()) {
                int value = field.getDifference(duration, current);
                current = field.add(current, value);
                values[i] = value;
            }
        }
    }
    return values;
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:24,代码来源:BaseChronology.java

示例8: DelegatedDurationField

import org.joda.time.DurationField; //导入依赖的package包/类
/**
 * Constructor.
 * 
 * @param field  the base field
 * @param type  the field type to use
 */
protected DelegatedDurationField(DurationField field, DurationFieldType type) {
    super();
    if (field == null) {
        throw new IllegalArgumentException("The field must not be null");
    }
    iField = field;
    iType = (type == null ? field.getType() : type);
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:15,代码来源:DelegatedDurationField.java

示例9: compareTo

import org.joda.time.DurationField; //导入依赖的package包/类
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;
    }
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:14,代码来源:MillisDurationField.java

示例10: DividedDateTimeField

import org.joda.time.DurationField; //导入依赖的package包/类
/**
 * Constructor.
 * 
 * @param field  the field to wrap, like "year()".
 * @param type  the field type this field will actually use
 * @param divisor  divisor, such as 100 years in a century
 * @throws IllegalArgumentException if divisor is less than two
 */
public DividedDateTimeField(DateTimeField field,
                            DateTimeFieldType type, int divisor) {
    super(field, type);
            
    if (divisor < 2) {
        throw new IllegalArgumentException("The divisor must be at least 2");
    }

    DurationField unitField = field.getDurationField();
    if (unitField == null) {
        iDurationField = null;
    } else {
        iDurationField = new ScaledDurationField(
            unitField, type.getDurationType(), divisor);
    }

    iDivisor = divisor;

    int i = field.getMinimumValue();
    int min = (i >= 0) ? i / divisor : ((i + 1) / divisor - 1);

    int j = field.getMaximumValue();
    int max = (j >= 0) ? j / divisor : ((j + 1) / divisor - 1);

    iMin = min;
    iMax = max;
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:36,代码来源:DividedDateTimeField.java

示例11: PreciseDurationDateTimeField

import org.joda.time.DurationField; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:23,代码来源:PreciseDurationDateTimeField.java

示例12: compareReverse

import org.joda.time.DurationField; //导入依赖的package包/类
static int compareReverse(DurationField a, DurationField b) {
    if (a == null || !a.isSupported()) {
        if (b == null || !b.isSupported()) {
            return 0;
        }
        return -1;
    }
    if (b == null || !b.isSupported()) {
        return 1;
    }
    return -a.compareTo(b);
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:13,代码来源:DateTimeParserBucket.java

示例13: convertField

import org.joda.time.DurationField; //导入依赖的package包/类
private DurationField convertField(DurationField field, HashMap<Object, Object> converted) {
    if (field == null || !field.isSupported()) {
        return field;
    }
    if (converted.containsKey(field)) {
        return (DurationField)converted.get(field);
    }
    LimitDurationField limitField = new LimitDurationField(field);
    converted.put(field, limitField);
    return limitField;
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:12,代码来源:LimitChronology.java

示例14: LimitDateTimeField

import org.joda.time.DurationField; //导入依赖的package包/类
LimitDateTimeField(DateTimeField field,
                   DurationField durationField,
                   DurationField rangeDurationField,
                   DurationField leapDurationField) {
    super(field, field.getType());
    iDurationField = durationField;
    iRangeDurationField = rangeDurationField;
    iLeapDurationField = leapDurationField;
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:10,代码来源:LimitChronology.java

示例15: convertField

import org.joda.time.DurationField; //导入依赖的package包/类
private DurationField convertField(DurationField field, HashMap<Object, Object> converted) {
    if (field == null || !field.isSupported()) {
        return field;
    }
    if (converted.containsKey(field)) {
        return (DurationField)converted.get(field);
    }
    ZonedDurationField zonedField = new ZonedDurationField(field, getZone());
    converted.put(field, zonedField);
    return zonedField;
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:12,代码来源:ZonedChronology.java


注:本文中的org.joda.time.DurationField类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。