Package org.goda.time

Examples of org.goda.time.DurationField


            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;
        }
View Full Code Here


    public int[] get(ReadablePeriod period, long startInstant, long endInstant) {
        int size = period.size();
        int[] values = new int[size];
        if (startInstant != endInstant) {
            for (int i = 0; i < size; i++) {
                DurationField field = period.getFieldType(i).getField(this);
                int value = field.getDifference(endInstant, startInstant);
                startInstant = field.add(startInstant, value);
                values[i] = value;
            }
        }
        return values;
    }
View Full Code Here

        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;
View Full Code Here

            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;
        }
View Full Code Here

            fields.copyFieldsFrom(iBase);
        }
        assemble(fields);

        {
            DurationField f;
            iMillis    = (f = fields.millis)    != null ? f : super.millis();
            iSeconds   = (f = fields.seconds)   != null ? f : super.seconds();
            iMinutes   = (f = fields.minutes)   != null ? f : super.minutes();
            iHours     = (f = fields.hours)     != null ? f : super.hours();
            iHalfdays  = (f = fields.halfdays!= null ? f : super.halfdays();
View Full Code Here

        /**
         * Copy the supported fields from a chronology into this container.
         */
        public void copyFieldsFrom(Chronology chrono) {
            {
                DurationField f;
                if (isSupported(f = chrono.millis())) {
                    millis = f;
                }
                if (isSupported(f = chrono.seconds())) {
                    seconds = f;
View Full Code Here

        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);
    }
View Full Code Here

        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);
View Full Code Here

        return FieldUtils.safeToInt(getDifferenceAsLong(minuendInstant, subtrahendInstant));
    }

    //------------------------------------------------------------------------
    public int compareTo(Object durationField) {
        DurationField otherField = (DurationField) durationField;
        long otherMillis = otherField.getUnitMillis();
        long thisMillis = getUnitMillis();
        // cannot do (thisMillis - otherMillis) as can overflow
        if (thisMillis == otherMillis) {
            return 0;
        }
View Full Code Here

        return FieldUtils.safeSubtract(minuendInstant, subtrahendInstant);
    }

    //------------------------------------------------------------------------
    public int compareTo(Object durationField) {
        DurationField otherField = (DurationField) durationField;
        long otherMillis = otherField.getUnitMillis();
        long thisMillis = getUnitMillis();
        // cannot do (thisMillis - otherMillis) as can overflow
        if (thisMillis == otherMillis) {
            return 0;
        }
View Full Code Here

TOP

Related Classes of org.goda.time.DurationField

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.