private static DateTimeFormatter basicTime() { if (bt == null) { return new DateTimeFormatterBuilder() .appendFixedDecimal(DateTimeFieldType.hourOfDay(), 2) .appendFixedDecimal(DateTimeFieldType.minuteOfHour(), 2) .appendFixedDecimal(DateTimeFieldType.secondOfMinute(), 2) .appendLiteral('.') .appendFractionOfSecond(3, 9) .appendTimeZoneOffset("Z", false, 2, 2) .toFormatter(); } return bt; }
private static DateTimeFormatter basicDate() { if (bd == null) { return new DateTimeFormatterBuilder() .appendYear(4, 4) .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2) .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2) .toFormatter(); } return bd; }
public static Partial resolveWeek(Partial p) { // Figure out week if (p.isSupported(DateTimeFieldType.dayOfMonth()) && p.isSupported(DateTimeFieldType.monthOfYear()) && p.isSupported(DateTimeFieldType.year())) { Instant t = getInstant(p); // return getPartial(t.toInstant(), p.without(DateTimeFieldType.dayOfMonth()).without(DateTimeFieldType.monthOfYear()).with(DateTimeFieldType.weekOfWeekyear(), 1)); return getPartial(t.toInstant(), p.with(DateTimeFieldType.weekOfWeekyear(), 1)); } else return p; }
@Override public DateTimeFieldType[] getDateTimeFields() { return new DateTimeFieldType[] { DateTimeFieldType.dayOfMonth(), DateTimeFieldType.dayOfWeek(), DateTimeFieldType.dayOfYear() }; } private static final long serialVersionUID = 1;
@Override public DateTimeFieldType[] getDateTimeFields() { return new DateTimeFieldType[] { DateTimeFieldType.year(), DateTimeFieldType.yearOfCentury(), DateTimeFieldType.yearOfEra() }; } private static final long serialVersionUID = 1;
@Override public DateTimeFieldType[] getDateTimeFields() { return new DateTimeFieldType[] { DateTimeFieldType.minuteOfHour(), DateTimeFieldType.minuteOfDay() }; } private static final long serialVersionUID = 1;
public int dayOfWeekTextToValue(String text) { Integer day = iParseDaysOfWeek.get(text); if (day != null) { return day.intValue(); } throw new IllegalFieldValueException(DateTimeFieldType.dayOfWeek(), text); }
public int monthOfYearTextToValue(String text) { Integer month = iParseMonths.get(text); if (month != null) { return month.intValue(); } throw new IllegalFieldValueException(DateTimeFieldType.monthOfYear(), text); }
int inputSize = workingFields.size(); boolean reducedPrec = false; DateTimeFormatterBuilder bld = new DateTimeFormatterBuilder(); if (workingFields.contains(DateTimeFieldType.monthOfYear())) { reducedPrec = dateByMonth(bld, workingFields, extended, strictISO); } else if (workingFields.contains(DateTimeFieldType.dayOfYear())) { reducedPrec = dateByOrdinal(bld, workingFields, extended, strictISO); } else if (workingFields.contains(DateTimeFieldType.weekOfWeekyear())) { reducedPrec = dateByWeek(bld, workingFields, extended, strictISO); } else if (workingFields.contains(DateTimeFieldType.dayOfMonth())) { reducedPrec = dateByMonth(bld, workingFields, extended, strictISO); } else if (workingFields.contains(DateTimeFieldType.dayOfWeek())) { reducedPrec = dateByWeek(bld, workingFields, extended, strictISO); } else if (workingFields.remove(DateTimeFieldType.year())) { bld.append(Constants.ye); reducedPrec = true; } else if (workingFields.remove(DateTimeFieldType.weekyear())) { bld.append(Constants.we); reducedPrec = true;
if (seconds > 0) largestStrideType = secondOfMinute(); if (minutes > 0) largestStrideType = minuteOfHour(); if (hours > 0) largestStrideType = hourOfDay(); if (days > 0) largestStrideType = dayOfMonth(); if (weeks > 0) largestStrideType = weekOfWeekyear(); if (months > 0) largestStrideType = monthOfYear(); if (years > 0) largestStrideType = year(); if (largestStrideType == null) { throw new IllegalArgumentException("Could not determine rotation stride length."); final DateTimeField field = largestStrideType.getField(anchorTime.getChronology()); int periodValue = normalized.get(largestStrideType.getDurationType()); final long fieldValue = field.roundFloor(anchorTime.getMillis()); final int fieldValueInUnit = field.get(fieldValue); if (periodValue == 0) { final long newValue = field.add(fieldValue, -1 * difference); return new DateTime(newValue, DateTimeZone.UTC);
private static DateTimeFormatter basicTimeNoMillis() { if (btx == null) { return new DateTimeFormatterBuilder() .appendFixedDecimal(DateTimeFieldType.hourOfDay(), 2) .appendFixedDecimal(DateTimeFieldType.minuteOfHour(), 2) .appendFixedDecimal(DateTimeFieldType.secondOfMinute(), 2) .appendTimeZoneOffset("Z", false, 2, 2) .toFormatter(); } return btx; }
if (fields.remove(DateTimeFieldType.year())) { bld.append(Constants.ye); if (fields.remove(DateTimeFieldType.monthOfYear())) { if (fields.remove(DateTimeFieldType.dayOfMonth())) { appendSeparator(bld, extended); bld.appendMonthOfYear(2); appendSeparator(bld, extended); bld.appendDayOfMonth(2); } else { if (fields.remove(DateTimeFieldType.dayOfMonth())) { checkNotStrictISO(fields, strictISO); bld.appendLiteral('-'); bld.appendLiteral('-'); } else if (fields.remove(DateTimeFieldType.monthOfYear())) { bld.appendLiteral('-'); bld.appendLiteral('-'); bld.appendMonthOfYear(2); if (fields.remove(DateTimeFieldType.dayOfMonth())) { appendSeparator(bld, extended); } else if (fields.remove(DateTimeFieldType.dayOfMonth())) { bld.appendLiteral('-');
throw new IllegalArgumentException("The field type must not be null"); DurationField unitField = fieldType.getDurationType().getField(iChronology); if (unitField.isSupported()) { for (; i < iTypes.length; i++) { DateTimeFieldType loopType = iTypes[i]; DurationField loopUnitField = loopType.getDurationType().getField(iChronology); if (loopUnitField.isSupported()) { int compare = unitField.compareTo(loopUnitField); if (compare > 0) { break; } else if (compare == 0) { if (fieldType.getRangeDurationType() == null) { break; if (loopType.getRangeDurationType() == null) { continue; DurationField rangeField = fieldType.getRangeDurationType().getField(iChronology); DurationField loopRangeField = loopType.getRangeDurationType().getField(iChronology); if (rangeField.compareTo(loopRangeField) > 0) { break; if (value == getValue(index)) { return this;
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) { // overridden as superclass algorithm can't handle // 2004-02-29 + 48 months -> 2008-02-29 type dates if (valueToAdd == 0) { return values; } if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) { // month is largest field and being added to, such as month-day int curMonth0 = values[0] - 1; int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1; return set(partial, 0, values, newMonth); } if (DateTimeUtils.isContiguous(partial)) { long instant = 0L; for (int i = 0, isize = partial.size(); i < isize; i++) { instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]); } instant = add(instant, valueToAdd); return iChronology.get(partial, instant); } else { return super.add(partial, fieldIndex, values, valueToAdd); } }
private static DateTimeFormatter basicWeekDate() { if (bwd == null) { return new DateTimeFormatterBuilder() .appendWeekyear(4, 4) .appendLiteral('W') .appendFixedDecimal(DateTimeFieldType.weekOfWeekyear(), 2) .appendFixedDecimal(DateTimeFieldType.dayOfWeek(), 1) .toFormatter(); } return bwd; }
if (fields.remove(DateTimeFieldType.weekyear())) { bld.append(Constants.we); if (fields.remove(DateTimeFieldType.weekOfWeekyear())) { appendSeparator(bld, extended); bld.appendLiteral('W'); bld.appendWeekOfWeekyear(2); if (fields.remove(DateTimeFieldType.dayOfWeek())) { appendSeparator(bld, extended); bld.appendDayOfWeek(1); } else { if (fields.remove(DateTimeFieldType.dayOfWeek())) { } else if (fields.remove(DateTimeFieldType.weekOfWeekyear())) { bld.appendLiteral('-'); bld.appendLiteral('W'); bld.appendWeekOfWeekyear(2); if (fields.remove(DateTimeFieldType.dayOfWeek())) { appendSeparator(bld, extended); } else if (fields.remove(DateTimeFieldType.dayOfWeek())) { bld.appendLiteral('-');
/** * Checks if the field type specified is supported by this * local date and chronology. * This can be used to avoid exceptions in {@link #get(DateTimeFieldType)}. * * @param type a field type, usually obtained from DateTimeFieldType * @return true if the field type is supported */ public boolean isSupported(DateTimeFieldType type) { if (type == null) { return false; } DurationFieldType durType = type.getDurationType(); if (DATE_DURATION_TYPES.contains(durType) || durType.getField(getChronology()).getUnitMillis() >= getChronology().days().getUnitMillis()) { return type.getField(getChronology()).isSupported(); } return false; }
private static DateTimeFormatter basicOrdinalDate() { if (bod == null) { return new DateTimeFormatterBuilder() .appendYear(4, 4) .appendFixedDecimal(DateTimeFieldType.dayOfYear(), 3) .toFormatter(); } return bod; }
if (fields.remove(DateTimeFieldType.year())) { bld.append(Constants.ye); if (fields.remove(DateTimeFieldType.dayOfYear())) { appendSeparator(bld, extended); bld.appendDayOfYear(3); } else { } else if (fields.remove(DateTimeFieldType.dayOfYear())) { bld.appendLiteral('-'); bld.appendDayOfYear(3);
if (count > 0) { DurationField months = DurationFieldType.months().getField(iChrono); DurationField days = DurationFieldType.days().getField(iChrono); DurationField first = savedFields[0].iField.getDurationField(); if (compareReverse(first, months) >= 0 && compareReverse(first, days) <= 0) { saveField(DateTimeFieldType.year(), iDefaultYear); return computeMillis(resetFields, text); if (!savedFields[i].iField.isLenient()) { millis = savedFields[i].set(millis, i == (count - 1)); e.prependMessage("Cannot parse \"" + text + '"');