@Override public int getMonth() { return this.date.getMonth(); }
@Override public LocalDate from(PlainDate date) { return LocalDate.of(date.getYear(), date.getMonth(), date.getDayOfMonth()); }
/** * <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()); }
@Override public boolean contains(PlainDate temporal) { return ((temporal.getYear() == this.year) && (temporal.getMonth() == this.month.getValue())); }
header |= date.getMonth(); out.writeByte(header);
/** * <p>Converts given gregorian date to a calendar month. </p> * * @param date gregorian calendar date (for example {@code PlainDate} * @return CalendarMonth * @throws IllegalArgumentException if given date is invalid * @since 3.28/4.24 */ /*[deutsch] * <p>Konvertiert das angegebene gregorianische Datum zu einem Kalendermonat. </p> * * @param date gregorian calendar date (for example {@code PlainDate} * @return CalendarMonth * @throws IllegalArgumentException if given date is invalid * @since 3.28/4.24 */ public static CalendarMonth from(GregorianDate date) { PlainDate iso = PlainDate.from(date); // includes validation return CalendarMonth.of(iso.getYear(), iso.getMonth()); }
private int getLengthOfYM(PlainDate date) { if (this.owner.isYearRelated()) { return (GregorianMath.isLeapYear(date.getYear()) ? 366 : 365); } else { return GregorianMath.getLengthOfMonth( date.getYear(), date.getMonth() ); } }
private int getLengthOfYM( PlainDate date, int shift // -1 = Vorjahr/-monat, 0 = aktuell, +1 = Folgejahr/-monat ) { if (this.owner.isYearRelated()) { return ( GregorianMath.isLeapYear(date.getYear() + shift) ? 366 : 365 ); } else { int year = date.getYear(); int month = date.getMonth() + shift; if (month == 0) { month = 12; year--; } else if (month == 13) { month = 1; year++; } return GregorianMath.getLengthOfMonth(year, month); } }
private Weekday getWeekdayStart( PlainDate date, int shift // -1 = Vorjahr/-monat, 0 = aktuell, +1 = Folgejahr/-monat ) { if (this.owner.isYearRelated()) { return Weekday.valueOf( GregorianMath.getDayOfWeek(date.getYear() + shift, 1, 1)); } else { int year = date.getYear(); int month = date.getMonth() + shift; if (month == 0) { month = 12; year--; } else if (month == 13) { month = 1; year++; } else if (month == 14) { month = 2; year++; } return Weekday.valueOf( GregorianMath.getDayOfWeek(year, month, 1)); } }
@Override public CalendarMonth createFrom( TimeSource<?> clock, AttributeQuery attributes ) { Timezone zone; if (attributes.contains(Attributes.TIMEZONE_ID)) { zone = Timezone.of(attributes.get(Attributes.TIMEZONE_ID)); } else if (attributes.get(Attributes.LENIENCY, Leniency.SMART).isLax()) { zone = Timezone.ofSystem(); } else { return null; } PlainDate date = Moment.from(clock.currentTime()).toZonalTimestamp(zone.getID()).toDate(); return CalendarMonth.of(date.getYear(), Month.valueOf(date.getMonth())); }
PlainDate date = PlainDate.of(dateEpoch, EpochDays.UTC); int year = date.getYear(); int month = date.getMonth(); final int dom = date.getDayOfMonth(); final boolean allowHalfMonths = (this.estimateSize() < 180) && (dom <= 15);
@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; }
private <T extends ChronoEntity<T>> T doApply(T entity) { if (entity.contains(PlainDate.CALENDAR_DATE)) { PlainDate date = entity.get(PlainDate.CALENDAR_DATE); Weekday current = date.get(PlainDate.DAY_OF_WEEK); int delta = this.dayOfWeek.getValue() - current.getValue(); int dom = date.getDayOfMonth() + delta; long days; if (this.ordinal == LAST) { days = (5L - (Math.floorDiv(dom - 1, 7) + 1)) * 7 + delta; int max = GregorianMath.getLengthOfMonth(date.getYear(), date.getMonth()); if (date.getDayOfMonth() + days > max) { days -= 7; } } else { days = (this.ordinal - (Math.floorDiv(dom - 1, 7) + 1)) * 7 + delta; } date = date.plus(days, CalendarUnit.DAYS); return entity.with(PlainDate.CALENDAR_DATE, date); } else { throw new ChronoException( "Rule not found for ordinal day of week in month: " + entity); } }
private PlainDate doApply(PlainDate date) { int month = date.getMonth();