public StateBuilder() { calendarMode = CalendarMode.MONTHS; firstDayOfWeek = LocalDate.now().with(WeekFields.of(Locale.getDefault()).dayOfWeek(), 1).getDayOfWeek(); }
@Override public MinguoDate 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 + YEARS_DIFFERENCE : (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); }
/** * Getting the first day of a week for a specific date based on a specific week day as first * day. */ private CalendarDay getFirstDayOfWeek(@NonNull final CalendarDay day) { final LocalDate temp = day.getDate().with(WeekFields.of(firstDayOfWeek, 1).dayOfWeek(), 1L); return CalendarDay.from(temp); } }
@Override public MinguoDate 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 + YEARS_DIFFERENCE : (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); }
@Override public int indexOf(final CalendarDay day) { final WeekFields weekFields = WeekFields.of(firstDayOfWeek, 1); final LocalDate temp = day.getDate().with(weekFields.dayOfWeek(), 1L); return (int) ChronoUnit.WEEKS.between(min.getDate(), temp); }
@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); }
protected LocalDate resetAndGetWorkingCalendar() { final TemporalField firstDayOfWeek = WeekFields.of(this.firstDayOfWeek, 1).dayOfWeek(); final LocalDate temp = getFirstViewDay().getDate().with(firstDayOfWeek, 1); int dow = temp.getDayOfWeek().getValue(); int delta = getFirstDayOfWeek().getValue() - dow; //If the delta is positive, we want to remove a week boolean removeRow = showOtherMonths(showOtherDates) ? delta >= 0 : delta > 0; if (removeRow) { delta -= DEFAULT_DAYS_IN_WEEK; } return temp.plusDays(delta); }
@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); }
private LocalDate toLocalDate() { LocalDate date; if (dayOfMonthIndicator < 0) { int monthLen = month.length(IsoChronology.INSTANCE.isLeapYear(year)); date = LocalDate.of(year, month, monthLen + 1 + dayOfMonthIndicator); if (dayOfWeek != null) { date = date.with(previousOrSame(dayOfWeek)); } } else { date = LocalDate.of(year, month, dayOfMonthIndicator); if (dayOfWeek != null) { date = date.with(nextOrSame(dayOfWeek)); } } return date; }
private LocalDate toLocalDate() { LocalDate date; if (dayOfMonthIndicator < 0) { int monthLen = month.length(IsoChronology.INSTANCE.isLeapYear(year)); date = LocalDate.of(year, month, monthLen + 1 + dayOfMonthIndicator); if (dayOfWeek != null) { date = date.with(previousOrSame(dayOfWeek)); } } else { date = LocalDate.of(year, month, dayOfMonthIndicator); if (dayOfWeek != null) { date = date.with(nextOrSame(dayOfWeek)); } } return date; }
dow = (dow % 7) + 7; date = LocalDate.of(wby, 1, 4).plusWeeks(wowby - 1).plusWeeks(weeks).with(DAY_OF_WEEK, dow); } else { int dow = DAY_OF_WEEK.checkValidIntValue(dowLong); range().checkValidValue(wowby, this); // leniently check from 1 to 53 date = LocalDate.of(wby, 1, 4).plusWeeks(wowby - 1).with(DAY_OF_WEEK, dow);
private LocalDateTime toDateTime(int year) { adjustToFowards(year); LocalDate date; if (dayOfMonth == -1) { dayOfMonth = month.length(Year.isLeap(year)); date = LocalDate.of(year, month, dayOfMonth); if (dayOfWeek != null) { date = date.with(TemporalAdjusters.previousOrSame(dayOfWeek)); } } else { date = LocalDate.of(year, month, dayOfMonth); if (dayOfWeek != null) { date = date.with(TemporalAdjusters.nextOrSame(dayOfWeek)); } } date = deduplicate(date.plusDays(adjustDays)); return LocalDateTime.of(date, time); } }
private LocalDateTime toDateTime(int year) { adjustToFowards(year); LocalDate date; if (dayOfMonth == -1) { dayOfMonth = month.length(Year.isLeap(year)); date = LocalDate.of(year, month, dayOfMonth); if (dayOfWeek != null) { date = date.with(TemporalAdjusters.previousOrSame(dayOfWeek)); } } else { date = LocalDate.of(year, month, dayOfMonth); if (dayOfWeek != null) { date = date.with(TemporalAdjusters.nextOrSame(dayOfWeek)); } } date = deduplicate(date.plusDays(adjustDays)); return LocalDateTime.of(date, time); } }
/** * Creates a transition instance for the specified year. * <p> * Calculations are performed using the ISO-8601 chronology. * * @param year the year to create a transition for, not null * @return the transition instance, not null */ public ZoneOffsetTransition createTransition(int year) { LocalDate date; if (dom < 0) { date = LocalDate.of(year, month, month.length(IsoChronology.INSTANCE.isLeapYear(year)) + 1 + dom); if (dow != null) { date = date.with(previousOrSame(dow)); } } else { date = LocalDate.of(year, month, dom); if (dow != null) { date = date.with(nextOrSame(dow)); } } LocalDateTime localDT = LocalDateTime.of(date.plusDays(adjustDays), time); LocalDateTime transition = timeDefinition.createDateTime(localDT, standardOffset, offsetBefore); return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter); }
/** * Creates a transition instance for the specified year. * <p> * Calculations are performed using the ISO-8601 chronology. * * @param year the year to create a transition for, not null * @return the transition instance, not null */ public ZoneOffsetTransition createTransition(int year) { LocalDate date; if (dom < 0) { date = LocalDate.of(year, month, month.length(IsoChronology.INSTANCE.isLeapYear(year)) + 1 + dom); if (dow != null) { date = date.with(previousOrSame(dow)); } } else { date = LocalDate.of(year, month, dom); if (dow != null) { date = date.with(nextOrSame(dow)); } } LocalDateTime localDT = LocalDateTime.of(date.plusDays(adjustDays), time); LocalDateTime transition = timeDefinition.createDateTime(localDT, standardOffset, offsetBefore); return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter); }
return with(date, time.with(field, newValue)); } else { return with(date.with(field, newValue), time);
@Override public JapaneseDate with(TemporalField field, long newValue) { if (field instanceof ChronoField) { ChronoField f = (ChronoField) field; if (getLong(f) == newValue) { // validates unsupported fields return this; } switch (f) { case DAY_OF_YEAR: case YEAR_OF_ERA: case ERA: { int nvalue = getChronology().range(f).checkValidIntValue(newValue, f); switch (f) { case DAY_OF_YEAR: return with(isoDate.plusDays(nvalue - getDayOfYear())); case YEAR_OF_ERA: return this.withYear(nvalue); case ERA: { return this.withYear(JapaneseEra.of(nvalue), yearOfEra); } } } } return with(isoDate.with(field, newValue)); } return field.adjustInto(this, newValue); }
@Override public JapaneseDate with(TemporalField field, long newValue) { if (field instanceof ChronoField) { ChronoField f = (ChronoField) field; if (getLong(f) == newValue) { // validates unsupported fields return this; } switch (f) { case DAY_OF_YEAR: case YEAR_OF_ERA: case ERA: { int nvalue = getChronology().range(f).checkValidIntValue(newValue, f); switch (f) { case DAY_OF_YEAR: return with(isoDate.plusDays(nvalue - getDayOfYear())); case YEAR_OF_ERA: return this.withYear(nvalue); case ERA: { return this.withYear(JapaneseEra.of(nvalue), yearOfEra); } } } } return with(isoDate.with(field, newValue)); } return field.adjustInto(this, newValue); }
case CENTURIES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100)); case MILLENNIA: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000)); case ERAS: return with(ERA, Jdk8Methods.safeAdd(getLong(ERA), amountToAdd));
case CENTURIES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100)); case MILLENNIA: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000)); case ERAS: return with(ERA, Jdk8Methods.safeAdd(getLong(ERA), amountToAdd));