PlainDate date = PlainDate.of(2014, 7, 26); date = date.with(Weekmodel.ISO.localDayOfWeek().minimized()); System.out.println(date); // output: 2014-07-21
PlainDate dtStart = PlainDate.of(2016, Month.FEBRUARY, 4); int count = 5; Weekday byday = Weekday.FRIDAY; // first int interval = 1; CalendarUnit frequency = CalendarUnit.MONTHS; List<PlainDate> sequence = new ArrayList<>(count); PlainDate wim = dtStart; for (int i = 0; i < count; i++) { wim = wim.with(PlainDate.WEEKDAY_IN_MONTH.setToFirst(byday)); sequence.add(wim); wim = wim.with(PlainDate.DAY_OF_MONTH, 1).plus(interval, frequency); } if (!sequence.isEmpty() && !sequence.get(0).equals(dtStart)) { sequence.remove(0); // Not quite sure - do you need another condition? } System.out.println(sequence); // [2016-03-04, 2016-04-01, 2016-05-06, 2016-06-03]
PlainDate input = SystemClock.inLocalView().today(); // using system timezone Weekday weekday = Weekday.SUNDAY; PlainDate adjusted = input.with(PlainDate.WEEKDAY_IN_MONTH.setToThird(weekday)); boolean isThirdSundayInMonth = input.equals(adjusted);
@Override public PlainDate addTo( PlainDate date, long amount ) { PlainDate shifted = date; if (amount > 0) { for (int i = 0; i < amount; i++) { shifted = shifted.with(model.nextBusinessDay()); } } else if (amount < 0) { for (int i = 0; i > amount; i--) { shifted = shifted.with(model.previousBusinessDay()); } } return shifted; } @Override
private CalendarQuarter( int year, Quarter quarter ) { super(); if ((year < GregorianMath.MIN_YEAR) || (year > GregorianMath.MAX_YEAR)) { throw new IllegalArgumentException("Year out of bounds: " + year); } else if (quarter == null) { throw new NullPointerException("Missing quarter of calendar year."); } this.year = year; this.quarter = quarter; PlainDate date = PlainDate.of(this.year, 1, 1).with(QUARTER_OF_YEAR, quarter); this.start = Boundary.ofClosed(date); this.end = Boundary.ofClosed(date.with(PlainDate.DAY_OF_QUARTER.maximized())); }
/** * <p>Combines this year and month with given day of month to a calendar date. </p> * * @param dayOfMonth day of month in range 1-28/29/30/31 * @return calendar date * @throws IllegalArgumentException if the day-of-month is out of range */ /*[deutsch] * <p>Kombiniert diese Instanz mit dem angegebenen Tag zu einem Kalenderdatum. </p> * * @param dayOfMonth day of month in range 1-28/29/30/31 * @return calendar date * @throws IllegalArgumentException if the day-of-month is out of range */ public PlainDate atDayOfMonth(int dayOfMonth) { if (dayOfMonth == 1) { return this.start.getTemporal(); } return this.start.getTemporal().with(PlainDate.DAY_OF_MONTH, dayOfMonth); }
/** * <p>Combines this calendar quarter with given day of quarter year to a calendar date. </p> * * @param dayOfQuarter day of quarter in range 1-90/91/92 * @return calendar date * @throws IllegalArgumentException if the day-of-quarter is out of range */ /*[deutsch] * <p>Kombiniert dieses Quartal mit dem angegebenen Quartalstag zu einem Kalenderdatum. </p> * * @param dayOfQuarter day of quarter in range 1-90/91/92 * @return calendar date * @throws IllegalArgumentException if the day-of-quarter is out of range */ public PlainDate atDayOfQuarter(int dayOfQuarter) { if (dayOfQuarter == 1) { return this.start.getTemporal(); } return this.start.getTemporal().with(PlainDate.DAY_OF_QUARTER, dayOfQuarter); }
private DailySpliterator( PlainDate start, long startEpoch, long endEpoch ) { super(); this.startEpoch = startEpoch; this.endEpoch = endEpoch; this.current = ( (startEpoch > endEpoch) ? null : start.with(PlainDate.DAY_OF_WEEK, Weekday.valueOf((int) Math.floorMod(startEpoch + 5, 7) + 1))); }
/** * <p>Queries if a given date is the first business day of month. </p> * * @return ChronoCondition * @see net.time4j.engine.ChronoEntity#matches(ChronoCondition) * @see #lastBusinessDayInMonth() */ /*[deutsch] * <p>Ermittelt, ob ein Datum der erste Arbeitstag des Monats ist. </p> * * @return ChronoCondition * @see net.time4j.engine.ChronoEntity#matches(ChronoCondition) * @see #lastBusinessDayInMonth() */ default ChronoCondition<PlainDate> firstBusinessDayInMonth() { return date -> !test(date) && (date.with(previousBusinessDay()).getMonth() != date.getMonth()); }
return date -> !test(date) && (date.with(nextBusinessDay()).getMonth() != date.getMonth());
@Override public PlainTimestamp withValue( PlainTimestamp context, int value, boolean lenient ) { if (value == this.getInt(context)) { return context; } else if (lenient) { // nur auf numerischen Elementen definiert IsoUnit unit = ENGINE.getBaseUnit(this.element); long amount = MathUtils.safeSubtract((long) value, this.getInt(context)); return context.plus(amount, unit); } else if (this.element.isDateElement()) { PlainDate date = context.date.with(this.element, value); return PlainTimestamp.of(date, context.time); } else if (this.element.isTimeElement()) { int min = this.element.getDefaultMinimum().intValue(); int max = this.element.getDefaultMaximum().intValue(); if ((min > value) || (max < value)) { throw new IllegalArgumentException("Out of range: " + value); } PlainTime time = context.time.with(this.element, value); return PlainTimestamp.of(context.date, time); } throw new ChronoException( "Missing rule for: " + this.element.name()); }
return context.plus(amount, unit); } else if (this.element.isDateElement()) { PlainDate date = context.date.with(this.element, value); return PlainTimestamp.of(date, context.time); } else if (this.element.isTimeElement()) {
if (leniency.isLax()) { PlainDate date = PlainDate.of(year, 1, 1); date = date.with(MONTH_AS_NUMBER.setLenient(month)); return date.with(DAY_OF_MONTH.setLenient(dayOfMonth)); } else { return PlainDate.of(year, month, dayOfMonth); if (leniency.isLax()) { PlainDate date = PlainDate.of(year, 1); return date.with(DAY_OF_YEAR.setLenient(dayOfYear)); } else { return PlainDate.of(year, dayOfYear);
if (lenient) { PlainDate date = PlainDate.of(year, 1, 1); date = date.with(MONTH_AS_NUMBER.setLenient(Integer.valueOf(month))); return date.with(DAY_OF_MONTH.setLenient(Integer.valueOf(dom))); } else if ( // Standardszenario validateYear(entity, year) if (lenient) { PlainDate date = PlainDate.of(year, 1); return date.with(DAY_OF_YEAR.setLenient(Integer.valueOf(doy))); } else if ( // Ordinaldatum validateYear(entity, year) return date.with(DAY_OF_YEAR.setLenient(Integer.valueOf(doy))); } else if ( // Quartalsdatum validateYear(entity, year)
this.current = this.current.with(PlainDate.DAY_OF_WEEK, newWD); // trigger day-of-week-optimization return split;
@Override public CalendarMonth createFrom( TemporalAccessor threeten, AttributeQuery attributes ) { if (threeten.query(TemporalQueries.chronology()) == IsoChronology.INSTANCE) { if (threeten.isSupported(ChronoField.YEAR)) { if (threeten.isSupported(ChronoField.MONTH_OF_YEAR)) { Leniency leniency = attributes.get(Attributes.LENIENCY, Leniency.SMART); int year = threeten.get(ChronoField.YEAR); int month = threeten.get(ChronoField.MONTH_OF_YEAR); if (leniency.isLax()) { PlainDate date = PlainDate.of(year, 1, 1); date = date.with(PlainDate.MONTH_AS_NUMBER.setLenient(month)); return CalendarMonth.of(date.getYear(), date.getMonth()); } else { return CalendarMonth.of(year, month); } } } } return null; }