src/share/classes/java/time/chrono/ThaiBuddhistDate.java

Print this page

        

*** 70,85 **** import java.time.LocalDate; import java.time.LocalTime; import java.time.Period; import java.time.ZoneId; import java.time.temporal.ChronoField; - import java.time.temporal.TemporalQuery; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjuster; import java.time.temporal.TemporalAmount; import java.time.temporal.TemporalField; import java.time.temporal.TemporalUnit; import java.time.temporal.ValueRange; import java.util.Objects; /** * A date in the Thai Buddhist calendar system. --- 70,86 ---- import java.time.LocalDate; import java.time.LocalTime; import java.time.Period; import java.time.ZoneId; import java.time.temporal.ChronoField; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjuster; import java.time.temporal.TemporalAmount; import java.time.temporal.TemporalField; + import java.time.temporal.TemporalQuery; import java.time.temporal.TemporalUnit; + import java.time.temporal.UnsupportedTemporalTypeException; import java.time.temporal.ValueRange; import java.util.Objects; /** * A date in the Thai Buddhist calendar system.
*** 203,222 **** --- 204,253 ---- Objects.requireNonNull(isoDate, "isoDate"); this.isoDate = isoDate; } //----------------------------------------------------------------------- + /** + * Gets the chronology of this date, which is the Thai Buddhist calendar system. + * <p> + * The {@code Chronology} represents the calendar system in use. + * The era and other fields in {@link ChronoField} are defined by the chronology. + * + * @return the Thai Buddhist chronology, not null + */ @Override public ThaiBuddhistChronology getChronology() { return ThaiBuddhistChronology.INSTANCE; } + /** + * Gets the era applicable at this date. + * <p> + * The Thai Buddhist calendar system has two eras, 'BE' and 'BEFORE_BE', + * defined by {@link ThaiBuddhistEra}. + * + * @return the era applicable at this date, not null + */ + @Override + public ThaiBuddhistEra getEra() { + return (getProlepticYear() >= 1 ? ThaiBuddhistEra.BE : ThaiBuddhistEra.BEFORE_BE); + } + + /** + * Returns the length of the month represented by this date. + * <p> + * This returns the length of the month in days. + * Month lengths match those of the ISO calendar system. + * + * @return the length of the month in days + */ @Override public int lengthOfMonth() { return isoDate.lengthOfMonth(); } + //----------------------------------------------------------------------- @Override public ValueRange range(TemporalField field) { if (field instanceof ChronoField) { if (isSupported(field)) { ChronoField f = (ChronoField) field;
*** 231,249 **** return ValueRange.of(1, max); } } return getChronology().range(f); } ! throw new DateTimeException("Unsupported field: " + field.getName()); } return field.rangeRefinedBy(this); } @Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { switch ((ChronoField) field) { case YEAR_OF_ERA: { int prolepticYear = getProlepticYear(); return (prolepticYear >= 1 ? prolepticYear : 1 - prolepticYear); } case YEAR: --- 262,282 ---- return ValueRange.of(1, max); } } return getChronology().range(f); } ! throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName()); } return field.rangeRefinedBy(this); } @Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { switch ((ChronoField) field) { + case PROLEPTIC_MONTH: + return getProlepticMonth(); case YEAR_OF_ERA: { int prolepticYear = getProlepticYear(); return (prolepticYear >= 1 ? prolepticYear : 1 - prolepticYear); } case YEAR:
*** 254,263 **** --- 287,300 ---- return isoDate.getLong(field); } return field.getFrom(this); } + private long getProlepticMonth() { + return getProlepticYear() * 12L + isoDate.getMonthValue() - 1; + } + private int getProlepticYear() { return isoDate.getYear() + YEARS_DIFFERENCE; } //-----------------------------------------------------------------------
*** 267,281 **** ChronoField f = (ChronoField) field; if (getLong(f) == newValue) { return this; } switch (f) { case YEAR_OF_ERA: case YEAR: case ERA: { ! f.checkValidValue(newValue); ! int nvalue = (int) newValue; switch (f) { case YEAR_OF_ERA: return with(isoDate.withYear((getProlepticYear() >= 1 ? nvalue : 1 - nvalue) - YEARS_DIFFERENCE)); case YEAR: return with(isoDate.withYear(nvalue - YEARS_DIFFERENCE)); --- 304,320 ---- ChronoField f = (ChronoField) field; if (getLong(f) == newValue) { return this; } switch (f) { + case PROLEPTIC_MONTH: + getChronology().range(f).checkValidValue(newValue, f); + return plusMonths(newValue - getProlepticMonth()); case YEAR_OF_ERA: case YEAR: case ERA: { ! int nvalue = getChronology().range(f).checkValidIntValue(newValue, f); switch (f) { case YEAR_OF_ERA: return with(isoDate.withYear((getProlepticYear() >= 1 ? nvalue : 1 - nvalue) - YEARS_DIFFERENCE)); case YEAR: return with(isoDate.withYear(nvalue - YEARS_DIFFERENCE));
*** 284,324 **** } } } return with(isoDate.with(field, newValue)); } ! return (ThaiBuddhistDate) ChronoLocalDate.super.with(field, newValue); } /** * {@inheritDoc} * @throws DateTimeException {@inheritDoc} * @throws ArithmeticException {@inheritDoc} */ @Override public ThaiBuddhistDate with(TemporalAdjuster adjuster) { ! return (ThaiBuddhistDate)super.with(adjuster); } /** * {@inheritDoc} * @throws DateTimeException {@inheritDoc} * @throws ArithmeticException {@inheritDoc} */ @Override public ThaiBuddhistDate plus(TemporalAmount amount) { ! return (ThaiBuddhistDate)super.plus(amount); } /** * {@inheritDoc} * @throws DateTimeException {@inheritDoc} * @throws ArithmeticException {@inheritDoc} */ @Override public ThaiBuddhistDate minus(TemporalAmount amount) { ! return (ThaiBuddhistDate)super.minus(amount); } //----------------------------------------------------------------------- @Override ThaiBuddhistDate plusYears(long years) { --- 323,363 ---- } } } return with(isoDate.with(field, newValue)); } ! return ChronoLocalDate.super.with(field, newValue); } /** * {@inheritDoc} * @throws DateTimeException {@inheritDoc} * @throws ArithmeticException {@inheritDoc} */ @Override public ThaiBuddhistDate with(TemporalAdjuster adjuster) { ! return super.with(adjuster); } /** * {@inheritDoc} * @throws DateTimeException {@inheritDoc} * @throws ArithmeticException {@inheritDoc} */ @Override public ThaiBuddhistDate plus(TemporalAmount amount) { ! return super.plus(amount); } /** * {@inheritDoc} * @throws DateTimeException {@inheritDoc} * @throws ArithmeticException {@inheritDoc} */ @Override public ThaiBuddhistDate minus(TemporalAmount amount) { ! return super.minus(amount); } //----------------------------------------------------------------------- @Override ThaiBuddhistDate plusYears(long years) {
*** 330,384 **** return with(isoDate.plusMonths(months)); } @Override ThaiBuddhistDate plusWeeks(long weeksToAdd) { ! return (ThaiBuddhistDate)super.plusWeeks(weeksToAdd); } @Override ThaiBuddhistDate plusDays(long days) { return with(isoDate.plusDays(days)); } @Override public ThaiBuddhistDate plus(long amountToAdd, TemporalUnit unit) { ! return (ThaiBuddhistDate)super.plus(amountToAdd, unit); } @Override public ThaiBuddhistDate minus(long amountToAdd, TemporalUnit unit) { ! return (ThaiBuddhistDate)super.minus(amountToAdd, unit); } @Override ThaiBuddhistDate minusYears(long yearsToSubtract) { ! return (ThaiBuddhistDate)super.minusYears(yearsToSubtract); } @Override ThaiBuddhistDate minusMonths(long monthsToSubtract) { ! return (ThaiBuddhistDate)super.minusMonths(monthsToSubtract); } @Override ThaiBuddhistDate minusWeeks(long weeksToSubtract) { ! return (ThaiBuddhistDate)super.minusWeeks(weeksToSubtract); } @Override ThaiBuddhistDate minusDays(long daysToSubtract) { ! return (ThaiBuddhistDate)super.minusDays(daysToSubtract); } private ThaiBuddhistDate with(LocalDate newDate) { return (newDate.equals(isoDate) ? this : new ThaiBuddhistDate(newDate)); } @Override // for javadoc and covariant return type public final ChronoLocalDateTime<ThaiBuddhistDate> atTime(LocalTime localTime) { ! return (ChronoLocalDateTime<ThaiBuddhistDate>)super.atTime(localTime); } @Override public Period periodUntil(ChronoLocalDate<?> endDate) { return isoDate.periodUntil(endDate); --- 369,423 ---- return with(isoDate.plusMonths(months)); } @Override ThaiBuddhistDate plusWeeks(long weeksToAdd) { ! return super.plusWeeks(weeksToAdd); } @Override ThaiBuddhistDate plusDays(long days) { return with(isoDate.plusDays(days)); } @Override public ThaiBuddhistDate plus(long amountToAdd, TemporalUnit unit) { ! return super.plus(amountToAdd, unit); } @Override public ThaiBuddhistDate minus(long amountToAdd, TemporalUnit unit) { ! return super.minus(amountToAdd, unit); } @Override ThaiBuddhistDate minusYears(long yearsToSubtract) { ! return super.minusYears(yearsToSubtract); } @Override ThaiBuddhistDate minusMonths(long monthsToSubtract) { ! return super.minusMonths(monthsToSubtract); } @Override ThaiBuddhistDate minusWeeks(long weeksToSubtract) { ! return super.minusWeeks(weeksToSubtract); } @Override ThaiBuddhistDate minusDays(long daysToSubtract) { ! return super.minusDays(daysToSubtract); } private ThaiBuddhistDate with(LocalDate newDate) { return (newDate.equals(isoDate) ? this : new ThaiBuddhistDate(newDate)); } @Override // for javadoc and covariant return type public final ChronoLocalDateTime<ThaiBuddhistDate> atTime(LocalTime localTime) { ! return super.atTime(localTime); } @Override public Period periodUntil(ChronoLocalDate<?> endDate) { return isoDate.periodUntil(endDate);