public function test_London_previousTransition_rulesBased() { $test = $this->europeLondon(); $rules = $test->getTransitionRules(); $trans = $test->getTransitions(); $last = $trans[count($trans) - 1]; $this->assertEquals($test->previousTransition($last->getInstant()->plusSeconds(1)), $last); $this->assertEquals($test->previousTransition($last->getInstant()->plusNanos(1)), $last); // Jan 1st of year between transitions and rules $odt = ZonedDateTime::ofInstant($last->getInstant(), $last->getOffsetAfter()); $odt = $odt->withDayOfYear(1)->plusYears(1)->adjust(LocalTime::MIDNIGHT()); $this->assertEquals($test->previousTransition($odt->toInstant()), $last); // later years for ($year = 1998; $year < 2010; $year++) { $a = $rules[0]->createTransition($year); $b = $rules[1]->createTransition($year); $c = $rules[0]->createTransition($year + 1); $this->assertEquals($test->previousTransition($c->getInstant()), $b); $this->assertEquals($test->previousTransition($b->getInstant()->plusSeconds(1)), $b); $this->assertEquals($test->previousTransition($b->getInstant()->plusNanos(1)), $b); $this->assertEquals($test->previousTransition($b->getInstant()), $a); $this->assertEquals($test->previousTransition($a->getInstant()->plusSeconds(1)), $a); $this->assertEquals($test->previousTransition($a->getInstant()->plusNanos(1)), $a); } }
/** * Combines this instant with a time-zone to create a {@code ZonedDateTime}. * <p> * This returns an {@code ZonedDateTime} formed from this instant at the * specified time-zone. An exception will be thrown if the instant is too * large to fit into a zoned date-time. * <p> * This method is equivalent to * {@link ZonedDateTime#ofInstant(Instant, ZoneId) ZonedDateTime.ofInstant(this, zone)}. * * @param ZoneId $zone the zone to combine with, not null * @return ZonedDateTime the zoned date-time formed from this instant and the specified zone, not null * @throws DateTimeException if the result exceeds the supported range */ public function atZone(ZoneId $zone) { return ZonedDateTime::ofInstant($this, $zone); }
public function test_factory_ofInstant_Instant_nullZone() { TestHelper::assertNullException($this, function () { ZonedDateTime::ofInstant(Instant::EPOCH(), null); }); }
/** * Obtains an ISO zoned date-time in this chronology from an {@code Instant}. * <p> * This is equivalent to {@link ZonedDateTime#ofInstant(Instant, ZoneId)}. * * @param Instant $instant the instant to create the date-time from, not null * @param ZoneId $zone the time-zone, not null * @return ZonedDateTime the zoned date-time, not null * @throws DateTimeException if the result exceeds the supported range */ public function zonedDateTime(Instant $instant, ZoneId $zone) { return ZonedDateTime::ofInstant($instant, $zone); }