/** * 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); }
public function test_tick_ClockDuration_nullClock() { TestHelper::assertNullException($this, function () { Clock::tick(null, Duration::ZERO()); }); }
public function test_getRules() { $offset = ZoneOffset::ofHoursMinutesSeconds(1, 2, 3); $this->assertEquals($offset->getRules()->isFixedOffset(), true); $this->assertEquals($offset->getRules()->getOffset(null), $offset); $this->assertEquals($offset->getRules()->getDaylightSavings(null), Duration::ZERO()); $this->assertEquals($offset->getRules()->getStandardOffset(null), $offset); $this->assertEquals($offset->getRules()->nextTransition(null), null); $this->assertEquals($offset->getRules()->previousTransition(null), null); $this->assertEquals($offset->getRules()->isValidOffset(null, $offset), true); $this->assertEquals($offset->getRules()->isValidOffset(null, ZoneOffset::UTC()), false); $this->assertEquals($offset->getRules()->isValidOffset(null, null), false); $this->assertEquals($offset->getRules()->getOffset(null), $offset); $this->assertEquals($offset->getRules()->getValidOffsets(null), [$offset]); $this->assertEquals($offset->getRules()->getTransition(null), null); $this->assertEquals(count($offset->getRules()->getTransitions()), 0); $this->assertEquals(count($offset->getRules()->getTransitionRules()), 0); }
public function test_NewYork_preTimeZones() { $test = $this->americaNewYork(); $old = $this->createZDT(1800, 1, 1, ZoneOffset::UTC()); $instant = $old->toInstant(); $offset = ZoneOffset::of("-04:56:02"); $this->assertEquals($test->getOffset($instant), $offset); $this->checkOffset($test, $old->toLocalDateTime(), $offset, 1); $this->assertEquals($test->getStandardOffset($instant), $offset); $this->assertEquals($test->getDaylightSavings($instant), Duration::ZERO()); $this->assertEquals($test->isDaylightSavings($instant), false); }
public function test_data_nullInput() { $test = $this->make(self::OFFSET_PONE()); $this->assertEquals($test->getOffset(null), self::OFFSET_PONE()); $this->assertEquals($test->getOffsetDateTime(null), self::OFFSET_PONE()); $this->assertEquals(count($test->getValidOffsets(null)), 1); $this->assertEquals($test->getValidOffsets(null)[0], self::OFFSET_PONE()); $this->assertEquals($test->getTransition(null), null); $this->assertEquals($test->getStandardOffset(null), self::OFFSET_PONE()); $this->assertEquals($test->getDaylightSavings(null), Duration::ZERO()); $this->assertEquals($test->isDaylightSavings(null), false); $this->assertEquals($test->nextTransition(null), null); $this->assertEquals($test->previousTransition(null), null); }
public function test_minus_TemporalAmount_Duration_zero() { $z = $this->TEST_DATE_TIME->minusAmount(Duration::ZERO()); $this->assertEquals($z, $this->TEST_DATE_TIME); }
public function test_zero() { $this->assertEquals(Duration::ZERO()->getSeconds(), 0); $this->assertEquals(Duration::ZERO()->getNano(), 0); }
public function test_minus_Duration_zero() { $t = self::TEST_2008_6_30_11_30_59_000000500()->minusAmount(Duration::ZERO()); $this->assertEquals($t, self::TEST_2008_6_30_11_30_59_000000500()); }
/** * Gets the amount of daylight savings in use for the specified instant in this zone. * <p> * This provides access to historic information on how the amount of daylight * savings has changed over time. * This is the difference between the standard offset and the actual offset. * Typically the amount is zero during winter and one hour during summer. * Time-zones are second-based, so the nanosecond part of the duration will be zero. * <p> * This default implementation calculates the duration from the * {@link #getOffset(java.time.Instant) actual} and * {@link #getStandardOffset(java.time.Instant) standard} offsets. * * @param Instant|null $instant the instant to find the daylight savings for, not null, but null * may be ignored if the rules have a single offset for all instants * @return Duration the difference between the standard and actual offset, not null */ public function getDaylightSavings($instant) { if (empty($this->savingsInstantTransitions)) { return Duration::ZERO(); } $standardOffset = $this->getStandardOffset($instant); $actualOffset = $this->getOffset($instant); return Duration::ofSeconds($actualOffset->getTotalSeconds() - $standardOffset->getTotalSeconds()); }
/** * @expectedException \Celest\DateTimeException */ public function test_factory_from_TemporalAmount_Duration() { Period::from(Duration::ZERO()); }