org.joda.time.ReadablePartial Java Examples

The following examples show how to use org.joda.time.ReadablePartial. 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: Time_14_BasicMonthOfYearDateTimeField_s.java    From coming with MIT License 6 votes vote down vote up
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;
    }
        // month is largest field and being added to, such as month-day
    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);
    }
}
 
Example #2
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void printTo(StringBuffer buf, ReadablePartial partial, Locale locale) {
    DateTimePrinter[] elements = iPrinters;
    if (elements == null) {
        throw new UnsupportedOperationException();
    }

    if (locale == null) {
        // Guard against default locale changing concurrently.
        locale = Locale.getDefault();
    }

    int len = elements.length;
    for (int i=0; i<len; i++) {
        elements[i].printTo(buf, partial, locale);
    }
}
 
Example #3
Source File: Nopol2017_0086_t.java    From coming with MIT License 6 votes vote down vote up
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;
    }
        // month is largest field and being added to, such as month-day
    if ((!(((fieldIndex) != (1)) && (valueToAdd <= values.length))) || (valueToAdd < -1)) {
        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);
    }
}
 
Example #4
Source File: Time_10_BaseSingleFieldPeriod_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Calculates the number of whole units between the two specified partial datetimes.
 * <p>
 * The two partials must contain the same fields, for example you can specify
 * two <code>LocalDate</code> objects.
 *
 * @param start  the start partial date, validated to not be null
 * @param end  the end partial date, validated to not be null
 * @param zeroInstance  the zero instance constant, must not be null
 * @return the period
 * @throws IllegalArgumentException if the partials are null or invalid
 */
protected static int between(ReadablePartial start, ReadablePartial end, ReadablePeriod zeroInstance) {
    if (start == null || end == null) {
        throw new IllegalArgumentException("ReadablePartial objects must not be null");
    }
    if (start.size() != end.size()) {
        throw new IllegalArgumentException("ReadablePartial objects must have the same set of fields");
    }
    for (int i = 0, isize = start.size(); i < isize; i++) {
        if (start.getFieldType(i) != end.getFieldType(i)) {
            throw new IllegalArgumentException("ReadablePartial objects must have the same set of fields");
        }
    }
    if (DateTimeUtils.isContiguous(start) == false) {
        throw new IllegalArgumentException("ReadablePartial objects must be contiguous");
    }
    Chronology chrono = DateTimeUtils.getChronology(start.getChronology()).withUTC();
    int[] values = chrono.get(zeroInstance, chrono.set(start, START_1972), chrono.set(end, START_1972));
    return values[0];
}
 
Example #5
Source File: patch1-Time-14-Nopol2017_patch1-Time-14-Nopol2017_s.java    From coming with MIT License 6 votes vote down vote up
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;
    }
        // month is largest field and being added to, such as month-day
    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);
    }
}
 
Example #6
Source File: DateTimeConverter.java    From BootsFaces-OSP with Apache License 2.0 6 votes vote down vote up
@Override
public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) {
	this.facesContext = facesContext;
	Class<?> type = ValueExpressionHelper.getValueType(facesContext, uiComponent,
			Lists.<Class<?>> newArrayList(DateTime.class, LocalDate.class, LocalTime.class));
	Preconditions.checkArgument(type != null, "DateTimeConverter is not attached to a component bound to either a"
			+ " DateTime, LocalDate, or LocalTime.");
	if (value instanceof LocalDate) {
		LocalDate localDate = (LocalDate) value;
		return getAsStringValue(facesContext, uiComponent, localDate.toDateTimeAtStartOfDay(getTimeZone()));
	}
	if (value instanceof LocalTime) {
		LocalTime localTime = (LocalTime) value;
		return getAsStringValue(facesContext, uiComponent, localTime.toDateTimeToday(getTimeZone()));
	}
	if (value instanceof ReadablePartial) {
		ReadablePartial readablePartial = (ReadablePartial) value;
		return getAsStringValue(facesContext, uiComponent, readablePartial.toDateTime(new DateTime()));
	}
	this.facesContext = null;
	return getAsStringValue(facesContext, uiComponent, value);
}
 
Example #7
Source File: Time_20_DateTimeFormatterBuilder_t.java    From coming with MIT License 5 votes vote down vote up
public void printTo(Writer out, ReadablePartial partial, Locale locale) throws IOException {
    if (partial.isSupported(iFieldType)) {
        try {
            FormatUtils.writeUnpaddedInteger(out, partial.get(iFieldType));
        } catch (RuntimeException e) {
            out.write('\ufffd');
        }
    } else {
        out.write('\ufffd');
    }
}
 
Example #8
Source File: Time_20_DateTimeFormatterBuilder_s.java    From coming with MIT License 5 votes vote down vote up
public void printTo(Writer out, ReadablePartial partial, Locale locale) throws IOException {
    try {
        out.write(print(partial, locale));
    } catch (RuntimeException e) {
        out.write('\ufffd');
    }
}
 
Example #9
Source File: Time_20_DateTimeFormatterBuilder_t.java    From coming with MIT License 5 votes vote down vote up
public void printTo(Writer out, ReadablePartial partial, Locale locale) throws IOException {
    try {
        out.write(print(partial, locale));
    } catch (RuntimeException e) {
        out.write('\ufffd');
    }
}
 
Example #10
Source File: Joda.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public void printTo(Writer out, ReadablePartial partial, Locale locale) throws IOException {
    if (hasMilliSecondPrecision) {
        out.append(String.valueOf(getDateTimeMillis(partial)));
    } else {
        out.append(String.valueOf(getDateTimeMillis(partial) / 1000));
    }
}
 
Example #11
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void printTo(StringBuffer buf, ReadablePartial partial, Locale locale) {
    if (partial.isSupported(iFieldType)) {
        try {
            FormatUtils.appendPaddedInteger(buf, partial.get(iFieldType), iMinPrintedDigits);
        } catch (RuntimeException e) {
            appendUnknownString(buf, iMinPrintedDigits);
        }
    } else {
        appendUnknownString(buf, iMinPrintedDigits);
    }
}
 
Example #12
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void printTo(StringBuffer buf, ReadablePartial partial, Locale locale) {
    // removed check whether field is supported, as input field is typically
    // secondOfDay which is unsupported by TimeOfDay
    long millis = partial.getChronology().set(partial, 0L);
    try {
        printTo(buf, null, millis, partial.getChronology());
    } catch (IOException e) {
        // Not gonna happen.
    }
}
 
Example #13
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void printTo(Writer out, ReadablePartial partial, Locale locale) throws IOException {
    // no zone info
}
 
Example #14
Source File: Time_20_DateTimeFormatterBuilder_t.java    From coming with MIT License 4 votes vote down vote up
public void printTo(Writer out, ReadablePartial partial, Locale locale) throws IOException {
    // no zone info
}
 
Example #15
Source File: AcademicYearDateTimeField.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public int getMaximumValue(ReadablePartial instant) {

    throw unsupported();
}
 
Example #16
Source File: Cardumen_00283_s.java    From coming with MIT License 4 votes vote down vote up
public int[] addWrapField(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd) {
    return getWrappedField().addWrapField(instant, fieldIndex, values, valueToAdd);
}
 
Example #17
Source File: AcademicTrimesterDateTimeField.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public int getMinimumValue(ReadablePartial instant) {
    throw unsupported();
}
 
Example #18
Source File: Arja_00173_t.java    From coming with MIT License 4 votes vote down vote up
public int[] addWrapField(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd) {
    return getWrappedField().addWrapField(instant, fieldIndex, values, valueToAdd);
}
 
Example #19
Source File: Time_26_ZonedChronology_s.java    From coming with MIT License 4 votes vote down vote up
public int getMinimumValue(ReadablePartial instant) {
    return iField.getMinimumValue(instant);
}
 
Example #20
Source File: AcademicYearDateTimeField.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public String getAsText(ReadablePartial partial, int fieldValue, Locale locale) {

    throw unsupported();
}
 
Example #21
Source File: DelegatedDateTimeField.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public int getMaximumValue(ReadablePartial instant) {
    return iField.getMaximumValue(instant);
}
 
Example #22
Source File: DelegatedDateTimeField.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public int[] set(ReadablePartial instant, int fieldIndex, int[] values, int newValue) {
    return iField.set(instant, fieldIndex, values, newValue);
}
 
Example #23
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void printTo(Writer out, ReadablePartial partial, Locale locale) throws IOException {
    // no zone info
}
 
Example #24
Source File: Cardumen_00240_s.java    From coming with MIT License 4 votes vote down vote up
public int[] addWrapField(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd) {
    return getWrappedField().addWrapField(instant, fieldIndex, values, valueToAdd);
}
 
Example #25
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void printTo(StringBuffer buf, ReadablePartial partial, Locale locale) {
    // no zone info
}
 
Example #26
Source File: DayOfAcademicSemesterDateTimeField.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public int getMaximumValue(ReadablePartial instant) {

    throw unsupported();
}
 
Example #27
Source File: AcademicTrimesterDateTimeField.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public String getAsText(ReadablePartial partial, int fieldValue, Locale locale) {
    throw unsupported();
}
 
Example #28
Source File: JGenProg2017_0043_t.java    From coming with MIT License 4 votes vote down vote up
public int[] addWrapField(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd) {
    return getWrappedField().addWrapField(instant, fieldIndex, values, valueToAdd);
}
 
Example #29
Source File: DateTimeFormat.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void printTo(Writer out, ReadablePartial partial, Locale locale) throws IOException {
    DateTimePrinter p = getFormatter(locale).getPrinter();
    p.printTo(out, partial, locale);
}
 
Example #30
Source File: Time_6_GJChronology_t.java    From coming with MIT License 4 votes vote down vote up
public int getMinimumValue(ReadablePartial partial) {
    return iJulianField.getMinimumValue(partial);
}