Package org.goda.time

Examples of org.goda.time.DateTimeField


        public void printTo(
                StringBuffer buf, long instant, Chronology chrono,
                int displayOffset, DateTimeZone displayZone, Locale locale) {
            try {
                DateTimeField field = iFieldType.getField(chrono);
                FormatUtils.appendUnpaddedInteger(buf, field.get(instant));
            } catch (RuntimeException e) {
                buf.append('\ufffd');
            }
        }
View Full Code Here


        public void printTo(
                StringBuffer buf, long instant, Chronology chrono,
                int displayOffset, DateTimeZone displayZone, Locale locale) {
            try {
                DateTimeField field = iFieldType.getField(chrono);
                FormatUtils.appendPaddedInteger(buf, field.get(instant), iMinPrintedDigits);
            } catch (RuntimeException e) {
                appendUnknownString(buf, iMinPrintedDigits);
            }
        }
View Full Code Here

//                out.write('\ufffd');
//            }
//        }

        private String print(long instant, Chronology chrono, Locale locale) {
            DateTimeField field = iFieldType.getField(chrono);
            if (iShort) {
                return field.getAsShortText(instant, locale);
            } else {
                return field.getAsText(instant, locale);
            }
        }
View Full Code Here

            }
        }

        private String print(ReadablePartial partial, Locale locale) {
            if (partial.isSupported(iFieldType)) {
                DateTimeField field = iFieldType.getField(partial.getChronology());
                if (iShort) {
                    return field.getAsShortText(partial, locale);
                } else {
                    return field.getAsText(partial, locale);
                }
            } else {
                return "\ufffd";
            }
        }
View Full Code Here

     *
     * @return the interval of this field
     * @since 1.2
     */
    public Interval toInterval() {
        DateTimeField field = getField();
        long start = field.roundFloor(getMillis());
        long end = field.add(start, 1);
        Interval interval = new Interval(start, end);
        return interval;
    }
View Full Code Here

            return values;
        }
        // there are more efficient algorithms than this (especially for time only fields)
        // trouble is when dealing with days and months, so we use this technique of
        // adding/removing one from the larger field at a time
        DateTimeField nextField = null;
       
        while (valueToAdd > 0) {
            int max = getMaximumValue(instant, values);
            long proposed = values[fieldIndex] + valueToAdd;
            if (proposed <= max) {
                values[fieldIndex] = (int) proposed;
                break;
            }
            if (nextField == null) {
                if (fieldIndex == 0) {
                    throw new IllegalArgumentException("Maximum value exceeded for add");
                }
                nextField = instant.getField(fieldIndex - 1);
                // test only works if this field is UTC (ie. local)
                if (getRangeDurationField().getType() != nextField.getDurationField().getType()) {
                    throw new IllegalArgumentException("Fields invalid for add");
                }
            }
            valueToAdd -= (max + 1) - values[fieldIndex]// reduce the amount to add
            values = nextField.add(instant, fieldIndex - 1, values, 1)// add 1 to next bigger field
            values[fieldIndex] = getMinimumValue(instant, values)// reset this field to zero
        }
        while (valueToAdd < 0) {
            int min = getMinimumValue(instant, values);
            long proposed = values[fieldIndex] + valueToAdd;
            if (proposed >= min) {
                values[fieldIndex] = (int) proposed;
                break;
            }
            if (nextField == null) {
                if (fieldIndex == 0) {
                    throw new IllegalArgumentException("Maximum value exceeded for add");
                }
                nextField = instant.getField(fieldIndex - 1);
                if (getRangeDurationField().getType() != nextField.getDurationField().getType()) {
                    throw new IllegalArgumentException("Fields invalid for add");
                }
            }
            valueToAdd -= (min - 1) - values[fieldIndex]// reduce the amount to add
            values = nextField.add(instant, fieldIndex - 1, values, -1)// subtract 1 from next bigger field
            values[fieldIndex] = getMaximumValue(instant, values)// reset this field to max value
        }
       
        return set(instant, fieldIndex, values, values[fieldIndex])// adjusts smaller fields
    }
View Full Code Here

            return values;
        }
        // there are more efficient algorithms than this (especially for time only fields)
        // trouble is when dealing with days and months, so we use this technique of
        // adding/removing one from the larger field at a time
        DateTimeField nextField = null;
       
        while (valueToAdd > 0) {
            int max = getMaximumValue(instant, values);
            long proposed = values[fieldIndex] + valueToAdd;
            if (proposed <= max) {
                values[fieldIndex] = (int) proposed;
                break;
            }
            if (nextField == null) {
                if (fieldIndex == 0) {
                    valueToAdd -= (max + 1) - values[fieldIndex];
                    values[fieldIndex] = getMinimumValue(instant, values);
                    continue;
                }
                nextField = instant.getField(fieldIndex - 1);
                // test only works if this field is UTC (ie. local)
                if (getRangeDurationField().getType() != nextField.getDurationField().getType()) {
                    throw new IllegalArgumentException("Fields invalid for add");
                }
            }
            valueToAdd -= (max + 1) - values[fieldIndex]// reduce the amount to add
            values = nextField.addWrapPartial(instant, fieldIndex - 1, values, 1)// add 1 to next bigger field
            values[fieldIndex] = getMinimumValue(instant, values)// reset this field to zero
        }
        while (valueToAdd < 0) {
            int min = getMinimumValue(instant, values);
            long proposed = values[fieldIndex] + valueToAdd;
            if (proposed >= min) {
                values[fieldIndex] = (int) proposed;
                break;
            }
            if (nextField == null) {
                if (fieldIndex == 0) {
                    valueToAdd -= (min - 1) - values[fieldIndex];
                    values[fieldIndex] = getMaximumValue(instant, values);
                    continue;
                }
                nextField = instant.getField(fieldIndex - 1);
                if (getRangeDurationField().getType() != nextField.getDurationField().getType()) {
                    throw new IllegalArgumentException("Fields invalid for add");
                }
            }
            valueToAdd -= (min - 1) - values[fieldIndex]// reduce the amount to add
            values = nextField.addWrapPartial(instant, fieldIndex - 1, values, -1)// subtract 1 from next bigger field
            values[fieldIndex] = getMaximumValue(instant, values)// reset this field to max value
        }
       
        return set(instant, fieldIndex, values, values[fieldIndex])// adjusts smaller fields
    }
View Full Code Here

        FieldUtils.verifyValueBounds(this, newValue, getMinimumValue(partial, values), getMaximumValue(partial, values));
        values[fieldIndex] = newValue;
       
        // may need to adjust smaller fields
        for (int i = fieldIndex + 1; i < partial.size(); i++) {
            DateTimeField field = partial.getField(i);
            if (values[i] > field.getMaximumValue(partial, values)) {
                values[i] = field.getMaximumValue(partial, values);
            }
            if (values[i] < field.getMinimumValue(partial, values)) {
                values[i] = field.getMinimumValue(partial, values);
            }
        }
        return values;
    }
View Full Code Here

    public DividedDateTimeField(RemainderDateTimeField remainderField, DateTimeFieldType type) {
        super(remainderField.getWrappedField(), type);
        int divisor = iDivisor = remainderField.iDivisor;
        iDurationField = remainderField.iRangeField;

        DateTimeField field = getWrappedField();
        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;
    }
View Full Code Here

    public int getMaximumValue() {
        return iMax;
    }

    public long roundFloor(long instant) {
        DateTimeField field = getWrappedField();
        return field.roundFloor(field.set(instant, get(instant) * iDivisor));
    }
View Full Code Here

TOP

Related Classes of org.goda.time.DateTimeField

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.