/** * <p>Converts given gregorian date to a calendar week. </p> * * @param date gregorian calendar date (for example {@code PlainDate} * @return CalendarWeek * @throws IllegalArgumentException if given date is invalid * @since 3.28/4.24 */ /*[deutsch] * <p>Konvertiert das angegebene gregorianische Datum zu einer Kalenderwoche. </p> * * @param date gregorian calendar date (for example {@code PlainDate} * @return CalendarWeek * @throws IllegalArgumentException if given date is invalid * @since 3.28/4.24 */ public static CalendarWeek from(GregorianDate date) { PlainDate iso = PlainDate.from(date); // includes validation return CalendarWeek.of(iso.getInt(PlainDate.YEAR_OF_WEEKDATE), iso.getInt(Weekmodel.ISO.weekOfYear())); }
year1 = start.getInt(PlainDate.YEAR_OF_WEEKDATE); year2 = end.getInt(PlainDate.YEAR_OF_WEEKDATE); if (year1 == year2) { if (start.getInt(Weekmodel.ISO.weekOfYear()) == end.getInt(Weekmodel.ISO.weekOfYear())) { endPrinter = REDUCED_E; } else { year1 = start.getInt(PlainDate.YEAR_OF_WEEKDATE); year2 = end.getInt(PlainDate.YEAR_OF_WEEKDATE); if (year1 == year2) { if (start.getInt(Weekmodel.ISO.weekOfYear()) == end.getInt(Weekmodel.ISO.weekOfYear())) { endPrinter = REDUCED_E; } else {
/** * <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); }
/** * <p>Subtracts given weeks from this calendar week. </p> * * @param weeks the count of weeks to be subtracted * @return result of subtraction */ /*[deutsch] * <p>Subtrahiert die angegebenen Wochen von dieser Kalenderwoche. </p> * * @param weeks the count of weeks to be subtracted * @return result of subtraction */ public CalendarWeek minus(Weeks weeks) { if (weeks.isEmpty()) { return this; } PlainDate date = this.start.getTemporal().minus(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 int getInt(PlainTimestamp context) { if (this.element.isDateElement()) { return context.date.getInt(this.element); } else if (this.element.isTimeElement()) { return context.time.getInt(this.element); } throw new ChronoException( "Missing rule for: " + this.element.name()); }
@Override public CalendarWeek 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 CalendarWeek.of(date.getInt(YEAR_OF_WEEKDATE), date.getInt(WEEK_OF_YEAR)); }