public void printTo(Appendable appendable, ReadablePartial partial, Locale locale) throws IOException { // removed check whether field is supported, as input field is typically // secondOfDay which is unsupported by TimeOfDay long millis = partial.getChronology().set(partial, 0L); printTo(appendable, millis, partial.getChronology()); }
public void printTo(Appendable appendable, ReadablePartial partial, Locale locale) throws IOException { // removed check whether field is supported, as input field is typically // secondOfDay which is unsupported by TimeOfDay long millis = partial.getChronology().set(partial, 0L); printTo(appendable, millis, partial.getChronology()); }
/** * Gets the chronology, which is taken from the ReadableInstant. * <p> * If the passed in chronology is non-null, it is used. * Otherwise the chronology from the instant is used. * * @param object the ReadablePartial to convert, must not be null * @param chrono the chronology to use, null means use that from object * @return the chronology, never null */ public Chronology getChronology(Object object, Chronology chrono) { if (chrono == null) { chrono = ((ReadablePartial) object).getChronology(); chrono = DateTimeUtils.getChronology(chrono); } return chrono; }
/** * Gets the chronology, which is taken from the ReadableInstant. * <p> * If the passed in chronology is non-null, it is used. * Otherwise the chronology from the instant is used. * * @param object the ReadablePartial to convert, must not be null * @param chrono the chronology to use, null means use that from object * @return the chronology, never null */ public Chronology getChronology(Object object, Chronology chrono) { if (chrono == null) { chrono = ((ReadablePartial) object).getChronology(); chrono = DateTimeUtils.getChronology(chrono); } return chrono; }
/** * Gets a suitable hashcode for the object. * * @return the hashcode * @since 1.3 */ public int hashCode() { int hash = 19; hash = 13 * hash + get(); hash = 13 * hash + getFieldType().hashCode(); hash = 13 * hash + getReadablePartial().getChronology().hashCode(); return hash; }
/** * Gets a suitable hashcode for the object. * * @return the hashcode * @since 1.3 */ public int hashCode() { int hash = 19; hash = 13 * hash + get(); hash = 13 * hash + getFieldType().hashCode(); hash = 13 * hash + getReadablePartial().getChronology().hashCode(); return hash; }
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"; } }
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"; } }
/** * Compares this property to another. * * @param object the object to compare to * @return true if equal */ public boolean equals(Object object) { if (this == object) { return true; } if (object instanceof AbstractPartialFieldProperty == false) { return false; } AbstractPartialFieldProperty other = (AbstractPartialFieldProperty) object; return get() == other.get() && getFieldType() == other.getFieldType() && FieldUtils.equals(getReadablePartial().getChronology(), other.getReadablePartial().getChronology()); }
/** * Compares this property to another. * * @param object the object to compare to * @return true if equal */ public boolean equals(Object object) { if (this == object) { return true; } if (object instanceof AbstractPartialFieldProperty == false) { return false; } AbstractPartialFieldProperty other = (AbstractPartialFieldProperty) object; return get() == other.get() && getFieldType() == other.getFieldType() && FieldUtils.equals(getReadablePartial().getChronology(), other.getReadablePartial().getChronology()); }
/** * Constructs a Partial by copying all the fields and types from * another partial. * <p> * This is most useful when copying from a YearMonthDay or TimeOfDay. */ public Partial(ReadablePartial partial) { super(); if (partial == null) { throw new IllegalArgumentException("The partial must not be null"); } iChronology = DateTimeUtils.getChronology(partial.getChronology()).withUTC(); iTypes = new DateTimeFieldType[partial.size()]; iValues = new int[partial.size()]; for (int i = 0; i < partial.size(); i++) { iTypes[i] = partial.getFieldType(i); iValues[i] = partial.getValue(i); } }
/** * Constructs a Partial by copying all the fields and types from * another partial. * <p> * This is most useful when copying from a YearMonthDay or TimeOfDay. */ public Partial(ReadablePartial partial) { super(); if (partial == null) { throw new IllegalArgumentException("The partial must not be null"); } iChronology = DateTimeUtils.getChronology(partial.getChronology()).withUTC(); iTypes = new DateTimeFieldType[partial.size()]; iValues = new int[partial.size()]; for (int i = 0; i < partial.size(); i++) { iTypes[i] = partial.getFieldType(i); iValues[i] = partial.getValue(i); } }
/** * Creates a <code>Seconds</code> representing the number of whole seconds * between the two specified partial datetimes. * <p> * The two partials must contain the same fields, for example you can specify * two <code>LocalTime</code> objects. * * @param start the start partial date, must not be null * @param end the end partial date, must not be null * @return the period in seconds * @throws IllegalArgumentException if the partials are null or invalid */ public static Seconds secondsBetween(ReadablePartial start, ReadablePartial end) { if (start instanceof LocalTime && end instanceof LocalTime) { Chronology chrono = DateTimeUtils.getChronology(start.getChronology()); int seconds = chrono.seconds().getDifference( ((LocalTime) end).getLocalMillis(), ((LocalTime) start).getLocalMillis()); return Seconds.seconds(seconds); } int amount = BaseSingleFieldPeriod.between(start, end, ZERO); return Seconds.seconds(amount); }
/** * Creates a <code>Years</code> representing the number of whole years * 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, must not be null * @param end the end partial date, must not be null * @return the period in years * @throws IllegalArgumentException if the partials are null or invalid */ public static Years yearsBetween(ReadablePartial start, ReadablePartial end) { if (start instanceof LocalDate && end instanceof LocalDate) { Chronology chrono = DateTimeUtils.getChronology(start.getChronology()); int years = chrono.years().getDifference( ((LocalDate) end).getLocalMillis(), ((LocalDate) start).getLocalMillis()); return Years.years(years); } int amount = BaseSingleFieldPeriod.between(start, end, ZERO); return Years.years(amount); }
/** * Creates a <code>Days</code> representing the number of whole days * 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, must not be null * @param end the end partial date, must not be null * @return the period in days * @throws IllegalArgumentException if the partials are null or invalid */ public static Days daysBetween(ReadablePartial start, ReadablePartial end) { if (start instanceof LocalDate && end instanceof LocalDate) { Chronology chrono = DateTimeUtils.getChronology(start.getChronology()); int days = chrono.days().getDifference( ((LocalDate) end).getLocalMillis(), ((LocalDate) start).getLocalMillis()); return Days.days(days); } int amount = BaseSingleFieldPeriod.between(start, end, ZERO); return Days.days(amount); }
/** * Creates a <code>Minutes</code> representing the number of whole minutes * between the two specified partial datetimes. * <p> * The two partials must contain the same fields, for example you can specify * two <code>LocalTime</code> objects. * * @param start the start partial date, must not be null * @param end the end partial date, must not be null * @return the period in minutes * @throws IllegalArgumentException if the partials are null or invalid */ public static Minutes minutesBetween(ReadablePartial start, ReadablePartial end) { if (start instanceof LocalTime && end instanceof LocalTime) { Chronology chrono = DateTimeUtils.getChronology(start.getChronology()); int minutes = chrono.minutes().getDifference( ((LocalTime) end).getLocalMillis(), ((LocalTime) start).getLocalMillis()); return Minutes.minutes(minutes); } int amount = BaseSingleFieldPeriod.between(start, end, ZERO); return Minutes.minutes(amount); }
/** * Creates a <code>Hours</code> representing the number of whole hours * between the two specified partial datetimes. * <p> * The two partials must contain the same fields, for example you can specify * two <code>LocalTime</code> objects. * * @param start the start partial date, must not be null * @param end the end partial date, must not be null * @return the period in hours * @throws IllegalArgumentException if the partials are null or invalid */ public static Hours hoursBetween(ReadablePartial start, ReadablePartial end) { if (start instanceof LocalTime && end instanceof LocalTime) { Chronology chrono = DateTimeUtils.getChronology(start.getChronology()); int hours = chrono.hours().getDifference( ((LocalTime) end).getLocalMillis(), ((LocalTime) start).getLocalMillis()); return Hours.hours(hours); } int amount = BaseSingleFieldPeriod.between(start, end, ZERO); return Hours.hours(amount); }
/** * Creates a <code>Weeks</code> representing the number of whole weeks * 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, must not be null * @param end the end partial date, must not be null * @return the period in weeks * @throws IllegalArgumentException if the partials are null or invalid */ public static Weeks weeksBetween(ReadablePartial start, ReadablePartial end) { if (start instanceof LocalDate && end instanceof LocalDate) { Chronology chrono = DateTimeUtils.getChronology(start.getChronology()); int weeks = chrono.weeks().getDifference( ((LocalDate) end).getLocalMillis(), ((LocalDate) start).getLocalMillis()); return Weeks.weeks(weeks); } int amount = BaseSingleFieldPeriod.between(start, end, ZERO); return Weeks.weeks(amount); }
/** * Creates a <code>Minutes</code> representing the number of whole minutes * between the two specified partial datetimes. * <p> * The two partials must contain the same fields, for example you can specify * two <code>LocalTime</code> objects. * * @param start the start partial date, must not be null * @param end the end partial date, must not be null * @return the period in minutes * @throws IllegalArgumentException if the partials are null or invalid */ public static Minutes minutesBetween(ReadablePartial start, ReadablePartial end) { if (start instanceof LocalTime && end instanceof LocalTime) { Chronology chrono = DateTimeUtils.getChronology(start.getChronology()); int minutes = chrono.minutes().getDifference( ((LocalTime) end).getLocalMillis(), ((LocalTime) start).getLocalMillis()); return Minutes.minutes(minutes); } int amount = BaseSingleFieldPeriod.between(start, end, ZERO); return Minutes.minutes(amount); }
/** * Compares this ReadablePartial with another returning true if the chronology, * field types and values are equal. * * @param partial an object to check against * @return true if fields and values are equal */ public boolean equals(Object partial) { if (this == partial) { return true; } if (partial instanceof ReadablePartial == false) { return false; } ReadablePartial other = (ReadablePartial) partial; if (size() != other.size()) { return false; } for (int i = 0, isize = size(); i < isize; i++) { if (getValue(i) != other.getValue(i) || getFieldType(i) != other.getFieldType(i)) { return false; } } return FieldUtils.equals(getChronology(), other.getChronology()); }