@Override protected ChronoLocalDate chronoLocalDateOf(final ThaiBuddhistEra era, final int prolepticYear, final int month, final int dayOfMonth) { return ThaiBuddhistDate.of(prolepticYear, month, dayOfMonth); }
@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); }
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()); long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1); long days = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH), 1); return date(y, 1, 1).plus(months, MONTHS).plus(weeks, WEEKS).plus(days, DAYS); ThaiBuddhistDate date = date(y, moy, 1).plus((aw - 1) * 7 + (ad - 1), DAYS); if (resolverStyle == ResolverStyle.STRICT && date.get(MONTH_OF_YEAR) != moy) { throw new DateTimeException("Strict mode rejected date parsed to a different month"); long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1); long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_WEEK), 1); return date(y, 1, 1).plus(months, MONTHS).plus(weeks, WEEKS).plus(days, DAYS); ThaiBuddhistDate date = date(y, moy, 1).plus(aw - 1, WEEKS).with(nextOrSame(DayOfWeek.of(dow))); if (resolverStyle == ResolverStyle.STRICT && date.get(MONTH_OF_YEAR) != moy) { throw new DateTimeException("Strict mode rejected date parsed to a different month"); if (resolverStyle == ResolverStyle.LENIENT) { long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_YEAR), 1); return dateYearDay(y, 1).plusDays(days);
@Override protected ThaiBuddhistDate getReferenceValue(Clock reference) { return ThaiBuddhistDate.now( reference ); }
public static ThaiBuddhistDate from(TemporalAccessor temporal) { return ThaiBuddhistDate.from(temporal); }
@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 with covariant return type public ThaiBuddhistDate date(int prolepticYear, int month, int dayOfMonth) { return new ThaiBuddhistDate(LocalDate.of(prolepticYear - YEARS_DIFFERENCE, month, dayOfMonth)); }
@Override // override for performance public int hashCode() { return getChronology().getId().hashCode() ^ isoDate.hashCode(); }
public static ThaiBuddhistDate now(Clock clock) { return ThaiBuddhistDate.now(clock); }
switch(cal.getCalendarType()) { case "gregory": getDate = i -> i; break; case "buddhist": getDate = i -> ThaiBuddhistDate.from(i); break; case "japanese": getDate = i -> JapaneseDate.from(i) ; break; default: getDate = i -> i; break;
/** * Obtains the current {@code ThaiBuddhistDate} from the specified clock. * <p> * This will query the specified clock to obtain the current date - today. * Using this method allows the use of an alternate clock for testing. * The alternate clock may be introduced using {@linkplain Clock dependency injection}. * * @param clock the clock to use, not null * @return the current date, not null * @throws DateTimeException if the current date cannot be obtained */ public static ThaiBuddhistDate now(Clock clock) { return new ThaiBuddhistDate(LocalDate.now(clock)); }
@Override public ChronoPeriod until(ChronoLocalDate endDate) { Period period = isoDate.until(endDate); return getChronology().period(period.getYears(), period.getMonths(), period.getDays()); }
@Override protected ChronoLocalDate chronoLocalDateOf(final ThaiBuddhistEra era, final int prolepticYear, final int month, final int dayOfMonth) { return ThaiBuddhistDate.of(prolepticYear, month, dayOfMonth); }
@Override protected ThaiBuddhistDate getReferenceValue(Clock reference) { return ThaiBuddhistDate.now( reference ); }
public PastDummyEntity(ZonedDateTime dateTime) { calendar = GregorianCalendar.from( dateTime ); date = calendar.getTime(); instant = dateTime.toInstant(); localDateTime = dateTime.toLocalDateTime(); hijrahDate = HijrahDate.from( dateTime ); japaneseDate = JapaneseDate.from( dateTime ); localDate = LocalDate.from( dateTime ); minguoDate = MinguoDate.from( dateTime ); offsetDateTime = dateTime.toOffsetDateTime(); thaiBuddhistDate = ThaiBuddhistDate.from( dateTime ); year = Year.from( dateTime ); yearMonth = YearMonth.from( dateTime ); zonedDateTime = dateTime; } }
@Override // override with covariant return type public ThaiBuddhistDate date(TemporalAccessor temporal) { if (temporal instanceof ThaiBuddhistDate) { return (ThaiBuddhistDate) temporal; } return new ThaiBuddhistDate(LocalDate.from(temporal)); }
@Override protected ChronoLocalDate chronoLocalDateOf(final ThaiBuddhistEra era, final int prolepticYear, final int month, final int dayOfMonth) { return ThaiBuddhistDate.of(prolepticYear, month, dayOfMonth); }
@Override protected ThaiBuddhistDate getReferenceValue(Clock reference) { return ThaiBuddhistDate.now( reference ); }
public FutureDummyEntity(ZonedDateTime dateTime) { calendar = GregorianCalendar.from( dateTime ); date = calendar.getTime(); instant = dateTime.toInstant(); localDateTime = dateTime.toLocalDateTime(); hijrahDate = HijrahDate.from( dateTime ); japaneseDate = JapaneseDate.from( dateTime ); localDate = LocalDate.from( dateTime ); minguoDate = MinguoDate.from( dateTime ); offsetDateTime = dateTime.toOffsetDateTime(); thaiBuddhistDate = ThaiBuddhistDate.from( dateTime ); year = Year.from( dateTime ); yearMonth = YearMonth.from( dateTime ); zonedDateTime = dateTime; } }