/** * Adds a multi-year transition rule to the current window. * <p> * This adds a rule such that the offset, expressed as a daylight savings amount, * changes at the specified date-time for each year in the range. * * @param int $startYear the start year of the rule, from MIN_VALUE to MAX_VALUE * @param int $endYear the end year of the rule, from MIN_VALUE to MAX_VALUE * @param Month $month the month of the transition, not null * @param int $dayOfMonthIndicator the day-of-month of the transition, adjusted by dayOfWeek, * from 1 to 31 adjusted later, or -1 to -28 adjusted earlier from the last day of the month * @param DayOfWeek|null $dayOfWeek the day-of-week to adjust to, null if day-of-month should not be adjusted * @param LocalTime $time the time that the transition occurs as defined by timeDefintion, not null * @param bool $timeEndOfDay whether midnight is at the end of day * @param TimeDefinition $timeDefinition the definition of how to convert local to actual time, not null * @param int $savingAmountSecs the amount of saving from the standard offset after the transition in seconds * @return ZoneRulesBuilder $this, for chaining * @throws DateTimeException if a date-time field is out of range * @throws IllegalArgumentException if the day of month indicator is invalid * @throws IllegalArgumentException if the end of day midnight flag does not match the time * @throws \LogicException if no window has yet been added * @throws \LogicException if the window already has fixed savings * @throws \LogicException if the window has reached the maximum capacity of 2000 rules */ public function addRuleToWindow9($startYear, $endYear, Month $month, $dayOfMonthIndicator, $dayOfWeek, LocalTime $time, $timeEndOfDay, TimeDefinition $timeDefinition, $savingAmountSecs) { ChronoField::YEAR()->checkValidValue($startYear); ChronoField::YEAR()->checkValidValue($endYear); if ($dayOfMonthIndicator < -28 || $dayOfMonthIndicator > 31 || $dayOfMonthIndicator === 0) { throw new IllegalArgumentException("Day of month indicator must be between -28 and 31 inclusive excluding zero"); } if ($timeEndOfDay && $time->equals(LocalTime::MIDNIGHT()) == false) { throw new IllegalArgumentException("Time must be midnight when end of day flag is true"); } if (empty($this->windowList)) { throw new \LogicException("Must add a window before adding a rule"); } $window = $this->windowList[count($this->windowList) - 1]; $window->addRule($startYear, $endYear, $month, $dayOfMonthIndicator, $dayOfWeek, $time, $timeEndOfDay, $timeDefinition, $savingAmountSecs); return $this; }
/** * Checks if this object equals another. * <p> * The entire state of the object is compared. * * @param mixed $otherRule the other object to compare to, null returns false * @return bool true if equal */ public function equals($otherRule) { if ($otherRule === $this) { return true; } if ($otherRule instanceof ZoneOffsetTransitionRule) { $other = $otherRule; return $this->month == $other->month && $this->dom == $other->dom && $this->dow == $other->dow && $this->timeDefinition == $other->timeDefinition && $this->time->equals($other->time) && $this->timeEndOfDay == $other->timeEndOfDay && $this->standardOffset->equals($other->standardOffset) && $this->offsetBefore->equals($other->offsetBefore) && $this->offsetAfter->equals($other->offsetAfter); } return false; }
/** * Checks if this date-time is equal to another date-time. * <p> * Compares this {@code LocalDateTime} with another ensuring that the date-time is the same. * Only objects of type {@code LocalDateTime} are compared, other types return false. * * @param mixed $obj the object to check, null returns false * @return true if this is equal to the other date-time */ public function equals($obj) { if ($this === $obj) { return true; } if ($obj instanceof LocalDateTime) { $other = $obj; return $this->date->equals($other->date) && $this->time->equals($other->time); } return false; }
private function updateCheckConflict(LocalTime $timeToSet, Period $periodToSet) { if ($this->time != null) { if ($this->time->equals($timeToSet) == false) { throw new DateTimeException("Conflict found: Fields resolved to different times: " . $this->time . " " . $timeToSet); } if ($this->excessDays->isZero() == false && $periodToSet->isZero() == false && $this->excessDays->equals($periodToSet) == false) { throw new DateTimeException("Conflict found: Fields resolved to different excess periods: " . $this->excessDays . " " . $periodToSet); } else { $this->excessDays = $periodToSet; } } else { $this->time = $timeToSet; $this->excessDays = $periodToSet; } }
/** * Checks if this time is equal to another time. * <p> * The comparison is based on the local-time and the offset. * To compare for the same instant on the time-line, use {@link #isEqual(OffsetTime)}. * <p> * Only objects of type {@code OffsetTime} are compared, other types return false. * To compare the underlying local time of two {@code TemporalAccessor} instances, * use {@link ChronoField#NANO_OF_DAY} as a comparator. * * @param mixed $obj the object to check, null returns false * @return true if this is equal to the other time */ public function equals($obj) { if ($this === $obj) { return true; } if ($obj instanceof OffsetTime) { /** @var OffsetTime $other */ $other = $obj; return $this->time->equals($other->time) && $this->offset->equals($other->offset); } return false; }