/** * Obtains a {@code ThaiBuddhistDate} representing a date in the Thai Buddhist calendar * system from the proleptic-year, month-of-year and day-of-month fields. * <p> * This returns a {@code ThaiBuddhistDate} with the specified fields. * The day must be valid for the year and month, otherwise an exception will be thrown. * * @param prolepticYear the Thai Buddhist proleptic-year * @param month the Thai Buddhist month-of-year, from 1 to 12 * @param dayOfMonth the Thai Buddhist day-of-month, from 1 to 31 * @return the date in Thai Buddhist calendar system, not null * @throws DateTimeException if the value of any field is out of range, * or if the day-of-month is invalid for the month-year */ public static ThaiBuddhistDate of(int prolepticYear, int month, int dayOfMonth) { return ThaiBuddhistChronology.INSTANCE.date(prolepticYear, month, dayOfMonth); }
public static ThaiBuddhistDate dateNow(ThaiBuddhistChronology instance, ZoneId zone) { return instance.dateNow(MockClock.system(zone)); }
@Override public ThaiBuddhistDate resolveDate(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) { if (fieldValues.containsKey(EPOCH_DAY)) { return dateEpochDay(fieldValues.remove(EPOCH_DAY)); updateResolveMap(fieldValues, MONTH_OF_YEAR, Jdk8Methods.floorMod(prolepticMonth, 12) + 1); updateResolveMap(fieldValues, YEAR, Jdk8Methods.floorDiv(prolepticMonth, 12)); updateResolveMap(fieldValues, YEAR, (year > 0 ? yoeLong: Jdk8Methods.safeSubtract(1, yoeLong))); } else { updateResolveMap(fieldValues, YEAR, (year == null || year > 0 ? yoeLong: Jdk8Methods.safeSubtract(1, yoeLong))); updateResolveMap(fieldValues, YEAR, yoeLong); } else if (era.longValue() == 0L) { updateResolveMap(fieldValues, YEAR, Jdk8Methods.safeSubtract(1, yoeLong)); } else { throw new DateTimeException("Invalid value for era: " + era); long months = Jdk8Methods.safeSubtract(fieldValues.remove(MONTH_OF_YEAR), 1); long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_MONTH), 1); return date(y, 1, 1).plusMonths(months).plusDays(days); } else { int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR); int dom = range(DAY_OF_MONTH).checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH); if (resolverStyle == ResolverStyle.SMART && dom > 28) { dom = Math.min(dom, date(y, moy, 1).lengthOfMonth()); return date(y, moy, dom);
@Override public ValueRange range(TemporalField field) { if (field instanceof ChronoField) { if (isSupported(field)) { ChronoField f = (ChronoField) field; switch (f) { case DAY_OF_MONTH: case DAY_OF_YEAR: case ALIGNED_WEEK_OF_MONTH: return isoDate.range(field); case YEAR_OF_ERA: { ValueRange range = YEAR.range(); long max = (getProlepticYear() <= 0 ? -(range.getMinimum() + YEARS_DIFFERENCE) + 1 : range.getMaximum() + YEARS_DIFFERENCE); return ValueRange.of(1, max); } } return getChronology().range(f); } throw new UnsupportedTemporalTypeException("Unsupported field: " + field); } return field.rangeRefinedBy(this); }
@Override // override for performance public int hashCode() { return getChronology().getId().hashCode() ^ isoDate.hashCode(); }
@Override public ChronoPeriod until(ChronoLocalDate endDate) { Period period = isoDate.until(endDate); return getChronology().period(period.getYears(), period.getMonths(), period.getDays()); }
@Override public ThaiBuddhistDate with(TemporalField field, long newValue) { if (field instanceof ChronoField) { 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)); case ERA: return with(isoDate.withYear((1 - getProlepticYear()) - YEARS_DIFFERENCE)); } } } return with(isoDate.with(field, newValue)); } return field.adjustInto(this, newValue); }
/** * Obtains a {@code ThaiBuddhistDate} from a temporal object. * <p> * This obtains a date in the Thai Buddhist calendar system based on the specified temporal. * A {@code TemporalAccessor} represents an arbitrary set of date and time information, * which this factory converts to an instance of {@code ThaiBuddhistDate}. * <p> * The conversion typically uses the {@link ChronoField#EPOCH_DAY EPOCH_DAY} * field, which is standardized across calendar systems. * <p> * This method matches the signature of the functional interface {@link TemporalQuery} * allowing it to be used as a query via method reference, {@code ThaiBuddhistDate::from}. * * @param temporal the temporal object to convert, not null * @return the date in Thai Buddhist calendar system, not null * @throws DateTimeException if unable to convert to a {@code ThaiBuddhistDate} */ public static ThaiBuddhistDate from(TemporalAccessor temporal) { return ThaiBuddhistChronology.INSTANCE.date(temporal); }
public static ThaiBuddhistDate dateNow(ThaiBuddhistChronology instance) { return instance.dateNow(MockClock.systemDefaultZone()); }
static ChronoLocalDate readExternal(DataInput in) throws IOException { int year = in.readInt(); int month = in.readByte(); int dayOfMonth = in.readByte(); return ThaiBuddhistChronology.INSTANCE.date(year, month, dayOfMonth); }