/** * Converts this to a transition rule. * * @param ZoneOffset $standardOffset the active standard offset, not null * @param int $savingsBeforeSecs the active savings before the transition in seconds * @return ZoneOffsetTransitionRule the transition, not null */ function toTransitionRule(ZoneOffset $standardOffset, $savingsBeforeSecs) { // optimize stored format if ($this->dayOfMonthIndicator < 0) { if ($this->month != Month::FEBRUARY()) { $this->dayOfMonthIndicator = $this->month->maxLength() - 6; } } if ($this->timeEndOfDay && $this->dayOfMonthIndicator > 0 && ($this->dayOfMonthIndicator === 28 && $this->month == Month::FEBRUARY()) == false) { $date = LocalDate::ofMonth(2004, $this->month, $this->dayOfMonthIndicator)->plusDays(1); // leap-year $this->month = $date->getMonth(); $this->dayOfMonthIndicator = $date->getDayOfMonth(); if ($this->dayOfWeek !== null) { $this->dayOfWeek = $this->dayOfWeek->plus(1); } $this->timeEndOfDay = false; } // build rule $trans = $this->toTransition($standardOffset, $savingsBeforeSecs); return ZoneOffsetTransitionRule::of($this->month, $this->dayOfMonthIndicator, $this->dayOfWeek, $this->time, $this->timeEndOfDay, $this->timeDefinition, $standardOffset, $trans->getOffsetBefore(), $trans->getOffsetAfter()); }
/** * Returns a copy of this {@code MonthDay} with the month-of-year altered. * <p> * This returns a month-day with the specified month. * If the day-of-month is invalid for the specified month, the day will * be adjusted to the last valid day-of-month. * <p> * This instance is immutable and unaffected by this method call. * * @param Month $month the month-of-year to set in the returned month-day, not null * @return MonthDay a {@code MonthDay} based on this month-day with the requested month, not null */ public function with(Month $month) { if ($month->getValue() == $this->month) { return $this; } $day = Math::min($this->day, $month->maxLength()); return new MonthDay($month->getValue(), $day); }