@Override public boolean tryAdvance(Consumer<? super PlainDate> action) { if (this.current == null) { return false; } action.accept(this.current); if (this.startEpoch == this.endEpoch) { this.current = null; } else { this.current = this.current.plus(1, CalendarUnit.DAYS); } this.startEpoch++; return true; }
@Override public void forEachRemaining(Consumer<? super PlainDate> action) { if (this.current == null) { return; } PlainDate date = this.current; for (long index = this.startEpoch, n = this.endEpoch; index <= n; index++) { action.accept(date); if (index < n) { date = date.plus(1, CalendarUnit.DAYS); } } this.current = null; this.startEpoch = this.endEpoch + 1; }
@Override public PlainDate next() { if (this.count >= 7) { throw new NoSuchElementException(); } else { PlainDate result = CalendarWeek.this.start.getTemporal().plus(this.count, CalendarUnit.DAYS); this.count++; return result; } }
@Override public PlainDate next() { if (this.current == null) { throw new NoSuchElementException(); } else { PlainDate result = this.current; PlainDate next = result.plus(1, CalendarUnit.DAYS); this.current = ((next.getYear() == CalendarYear.this.year) ? next : null); return result; } }
@Override public PlainDate plusPeriod( PlainDate timepoint, String period, ParseLog plog, AttributeQuery attributes ) { try { return timepoint.plus(Duration.parseCalendarPeriod(period)); } catch (ParseException ex) { return null; } }
PlainDate ls = PlainDate.of(2015, 6, 30); Moment start = ls.atStartOfDay().atUTC(); Moment end = ls.plus(1, CalendarUnit.DAYS).atStartOfDay().atUTC(); System.out.println(SI.SECONDS.between(start, end)); // 86401
private PlainTimestamp( PlainDate date, PlainTime time ) { super(); if (time.getHour() == 24) { // T24 normalisieren this.date = date.plus(1, DAYS); this.time = PlainTime.MIN; } else if (date == null) { throw new NullPointerException("Missing date."); } else { this.date = date; this.time = time; } }
/** * <p>Determines the same or next business day. </p> * * @return new date operator * @see #nextBusinessDay() * @see #previousBusinessDay() * @see #previousOrSameBusinessDay() */ /*[deutsch] * <p>Bestimmt den gleichen oder nächsten Arbeitstag. </p> * * @return new date operator * @see #nextBusinessDay() * @see #previousBusinessDay() * @see #previousOrSameBusinessDay() */ default ChronoOperator<PlainDate> nextOrSameBusinessDay() { return date -> { while (HolidayModel.this.test(date)) { date = date.plus(1, CalendarUnit.DAYS); } return date; }; }
@Override public PlainDate next() { if (this.current == null) { throw new NoSuchElementException(); } else { PlainDate result = this.current; PlainDate next = result.plus(1, CalendarUnit.DAYS); this.current = ((next.getMonth() == result.getMonth()) ? next : null); return result; } }
@Override public PlainDate next() { if (this.current == null) { throw new NoSuchElementException(); } else { PlainDate result = this.current; PlainDate next = result.plus(1, CalendarUnit.DAYS); this.current = ((next.isAfter(CalendarQuarter.this.end.getTemporal())) ? null : next); return result; } }
@Override public PlainDate withValue( PlainDate context, V value, boolean lenient ) { if (value == null) { throw new IllegalArgumentException("Missing element value."); } switch (this.index) { case EnumElement.MONTH: return context.withMonth(Month.class.cast(value).getValue()); case EnumElement.DAY_OF_WEEK: return context.withDayOfWeek(Weekday.class.cast(value)); case EnumElement.QUARTER_OF_YEAR: int q1 = ((context.month - 1) / 3) + 1; int q2 = Quarter.class.cast(value).getValue(); return context.plus((q2 - q1), CalendarUnit.QUARTERS); default: throw new UnsupportedOperationException(this.name); } }
private PlainTimestamp handleMidnight24(PlainTimestamp entity) { PlainDate date = entity.getCalendarDate(); switch (this.mode) { case ElementOperator.OP_NAV_NEXT: case ElementOperator.OP_NAV_NEXT_OR_SAME: return date.plus(1, CalendarUnit.DAYS).atStartOfDay(); case ElementOperator.OP_NAV_PREVIOUS: case ElementOperator.OP_NAV_PREVIOUS_OR_SAME: return date.atStartOfDay(); default: throw new AssertionError("Unknown: " + this.mode); } }
@Override public PlainTimestamp addTo( PlainTimestamp timepoint, long amount ) { PlainDate d; PlainTime t; if (this.calendarUnit != null) { d = timepoint.date.plus(amount, this.calendarUnit); t = timepoint.time; } else { DayCycles cycles = timepoint.time.roll(amount, this.clockUnit); d = timepoint.date.plus(cycles.getDayOverflow(), DAYS); t = cycles.getWallTime(); } return PlainTimestamp.of(d, t); }
private CalendarWeek( int year, int week ) { super(); int wmax = maximumOfWeek(year); if ((year < GregorianMath.MIN_YEAR) || (year > GregorianMath.MAX_YEAR)) { throw new IllegalArgumentException("Year out of bounds: " + year); } else if ((week < 1) || (week > wmax)) { throw new IllegalArgumentException("Week-of-year out of bounds: " + week); } this.year = year; this.week = week; this.lastWeek = wmax; PlainDate date = PlainDate.of(this.year, week, Weekday.MONDAY); this.start = Boundary.ofClosed(date); this.end = Boundary.ofClosed(date.plus(6, CalendarUnit.DAYS)); }
@Override public PlainDate getDate(int year) { int month = this.getMonthValue(); int ref = GregorianMath.getDayOfWeek(year, month, this.dayOfMonth); PlainDate result = PlainDate.of(year, month, this.dayOfMonth); if (ref == this.dayOfWeek) { return result; } int delta = (ref - this.dayOfWeek); int sgn = -1; if (this.after) { delta = -delta; sgn = 1; } if (delta < 0) { delta += 7; } return result.plus(delta * sgn, DAYS); }
@Override protected DateInterval nextInterval() { PlainDate next; Boundary<PlainDate> s; Boundary<PlainDate> e; if (RecurrentDateIntervals.this.isBackwards()) { next = this.current.minus(RecurrentDateIntervals.this.duration); s = Boundary.ofClosed(next.plus(1, DAYS)); e = Boundary.ofClosed(this.current); } else { next = this.current.plus(RecurrentDateIntervals.this.duration); s = Boundary.ofClosed(this.current); e = Boundary.ofClosed(next.minus(1, DAYS)); } this.current = next; return DateIntervalFactory.INSTANCE.between(s, e); } };
@Override public PlainDate getDate(int year) { int month = this.getMonth().getValue(); int dayOfMonth = GregorianMath.getLengthOfMonth(year, month) + 1 + this.domIndicator; int ref = GregorianMath.getDayOfWeek(year, month, dayOfMonth); PlainDate result = PlainDate.of(year, month, dayOfMonth); if (ref == this.dayOfWeek) { return result; } int delta = (this.dayOfWeek - ref); if (delta > 0) { delta -= 7; } return result.plus(delta, DAYS); }
private FullValueOperator(int type) { super(PlainTime.COMPONENT, type); this.tsop = entity -> { PlainTime time = doApply(entity.getWallTime()); if (time.getHour() == 24) { return PlainTimestamp.of( entity.getCalendarDate().plus(1, DAYS), PlainTime.midnightAtStartOfDay()); } else { return entity.with(time); } }; }
/** * <p>Adds given weeks to this calendar week. </p> * * @param weeks the count of weeks to be added * @return result of addition */ /*[deutsch] * <p>Addiert die angegebenen Wochen zu dieser Kalenderwoche. </p> * * @param weeks the count of weeks to be added * @return result of addition */ public CalendarWeek plus(Weeks weeks) { if (weeks.isEmpty()) { return this; } PlainDate date = this.start.getTemporal().plus(weeks.getAmount(), CalendarUnit.WEEKS); int y = date.getInt(YEAR_OF_WEEKDATE); int w = date.getInt(WEEK_OF_YEAR); return CalendarWeek.of(y, w); }
@Override public boolean isBefore(ChronoInterval<PlainDate> other) { if (other.getStart().isInfinite()) { return false; } PlainDate endA = this.getEnd().getTemporal(); PlainDate startB = other.getStart().getTemporal(); if (other.getStart().isOpen()) { if (startB.equals(PlainDate.axis().getMaximum())) { return true; } startB = startB.plus(1, CalendarUnit.DAYS); } return endA.isBefore(startB); }