public function equals($obj) { if ($obj instanceof OffsetClock) { return $this->baseClock->equals($obj->baseClock) && $this->offset->equals($obj->offset); } return false; }
/** * Obtains a clock that returns instants from the specified clock with the * specified duration added * <p> * This clock wraps another clock, returning instants that are later by the * specified duration. If the duration is negative, the instants will be * earlier than the current date and time. * The main use case for this is to simulate running in the future or in the past. * <p> * A duration of zero would have no offsetting effect. * Passing zero will return the underlying clock. * <p> * The returned implementation is immutable, thread-safe and {@code Serializable} * providing that the base clock is. * * @param Clock $baseClock the base clock to add the duration to, not null * @param Duration $offsetDuration the duration to add, not null * @return Clock clock based on the base clock with the duration added, not null */ public static function offset(Clock $baseClock, Duration $offsetDuration) { if ($offsetDuration->equals(Duration::ZERO())) { return $baseClock; } return new OffsetClock($baseClock, $offsetDuration); }