Example #1
0
 public function equals($obj)
 {
     if ($obj instanceof OffsetClock) {
         return $this->baseClock->equals($obj->baseClock) && $this->offset->equals($obj->offset);
     }
     return false;
 }
Example #2
0
 /**
  * Unit that represents the concept of a quarter-year.
  * @return IsoUnit
  */
 public static function QUARTER_YEARS()
 {
     if (self::$QUARTER_YEARS === null) {
         self::$QUARTER_YEARS = new IsoUnit("QuarterYears", Duration::ofSeconds(31556952 / 4));
     }
     return self::$QUARTER_YEARS;
 }
Example #3
0
 public function __toString()
 {
     return "TickClock[" . $this->baseClock . "," . Duration::ofNanos($this->tickNanos) . "]";
 }
 function data_minus_TemporalAmount()
 {
     return [[YearMonth::of(1, 1), Period::ofYears(1), YearMonth::of(0, 1), null], [YearMonth::of(1, 1), Period::ofYears(-12), YearMonth::of(13, 1), null], [YearMonth::of(1, 1), Period::ofYears(0), YearMonth::of(1, 1), null], [YearMonth::of(999999999, 12), Period::ofYears(0), YearMonth::of(999999999, 12), null], [YearMonth::of(-999999999, 1), Period::ofYears(0), YearMonth::of(-999999999, 1), null], [YearMonth::of(0, 1), Period::ofYears(999999999), YearMonth::of(-999999999, 1), null], [YearMonth::of(0, 12), Period::ofYears(-999999999), YearMonth::of(999999999, 12), null], [YearMonth::of(1, 1), Period::ofMonths(1), YearMonth::of(0, 12), null], [YearMonth::of(1, 1), Period::ofMonths(-12), YearMonth::of(2, 1), null], [YearMonth::of(1, 1), Period::ofMonths(121), YearMonth::of(-10, 12), null], [YearMonth::of(1, 1), Period::ofMonths(0), YearMonth::of(1, 1), null], [YearMonth::of(999999999, 12), Period::ofMonths(0), YearMonth::of(999999999, 12), null], [YearMonth::of(-999999999, 1), Period::ofMonths(0), YearMonth::of(-999999999, 1), null], [YearMonth::of(-999999999, 2), Period::ofMonths(1), YearMonth::of(-999999999, 1), null], [YearMonth::of(999999999, 11), Period::ofMonths(-1), YearMonth::of(999999999, 12), null], [YearMonth::of(1, 1), Period::ofYears(1)->withMonths(2), YearMonth::of(-1, 11), null], [YearMonth::of(1, 1), Period::ofYears(-12)->withMonths(-1), YearMonth::of(13, 2), null], [YearMonth::of(1, 1), Period::ofMonths(2)->withYears(1), YearMonth::of(-1, 11), null], [YearMonth::of(1, 1), Period::ofMonths(-1)->withYears(-12), YearMonth::of(13, 2), null], [YearMonth::of(1, 1), Period::ofDays(365), null, DateTimeException::class], [YearMonth::of(1, 1), Duration::ofDays(365), null, DateTimeException::class], [YearMonth::of(1, 1), Duration::ofHours(365 * 24), null, DateTimeException::class], [YearMonth::of(1, 1), Duration::ofMinutes(365 * 24 * 60), null, DateTimeException::class], [YearMonth::of(1, 1), Duration::ofSeconds(365 * 24 * 3600), null, DateTimeException::class], [YearMonth::of(1, 1), Duration::ofNanos(365 * 24 * 3600 * 1000000000), null, DateTimeException::class]];
 }
Example #5
0
 /**
  * Returns a copy of this duration with the specified duration subtracted.
  * <p>
  * This instance is immutable and unaffected by this method call.
  *
  * @param duration Duration the duration to subtract, positive or negative, not null
  * @return Duration a {@code Duration} based on this duration with the specified duration subtracted, not null
  * @throws ArithmeticException if numeric overflow occurs
  */
 public function minusAmount(Duration $duration)
 {
     $secsToSubtract = $duration->getSeconds();
     $nanosToSubtract = $duration->getNano();
     if ($secsToSubtract == Long::MIN_VALUE) {
         return $this->_plus(Long::MAX_VALUE, -$nanosToSubtract)->_plus(1, 0);
     }
     return $this->_plus(-$secsToSubtract, -$nanosToSubtract);
 }
 /**
  * @expectedException \Celest\DateTimeException
  * @dataProvider provider_factory_of_badTemporalUnit
  */
 public function test_bad_getUnit($amount, TemporalUnit $unit)
 {
     $t = Duration::of($amount, $unit);
     $t->get($unit);
 }
Example #7
0
 /**
  * @expectedException \Celest\DateTimeException
  */
 public function test_minus_Duration_overflowTooBig()
 {
     $i = Instant::ofEpochSecond(self::MAX_SECOND(), 999999999);
     $i->minusAmount(Duration::ofSeconds(-1, 999999999));
 }
 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_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);
 }
Example #10
0
 /**
  * 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());
 }
Example #11
0
 /**
  * @expectedException \Celest\DateTimeException
  */
 public function test_factory_from_TemporalAmount_Duration()
 {
     Period::from(Duration::ZERO());
 }
 /**
  * Gets the duration of the transition.
  * <p>
  * In most cases, the transition duration is one hour, however this is not always the case.
  * The duration will be positive for a gap and negative for an overlap.
  * Time-zones are second-based, so the nanosecond part of the duration will be zero.
  *
  * @return Duration the duration of the transition, positive for gaps, negative for overlaps
  */
 public function getDuration()
 {
     return Duration::ofSeconds($this->getDurationSeconds());
 }
Example #13
0
 function data_minusInvalidUnit()
 {
     return [[Period::of(0, 1, 0)], [Period::of(0, 0, 1)], [Period::of(0, 1, 1)], [Period::of(1, 1, 1)], [Duration::ofDays(1)], [Duration::ofHours(1)], [Duration::ofMinutes(1)], [Duration::ofSeconds(1)]];
 }
 public function test_getters_overlap()
 {
     $before = LocalDateTime::of(2010, 10, 31, 1, 0);
     $after = LocalDateTime::of(2010, 10, 31, 0, 0);
     $test = ZoneOffsetTransition::of($before, self::OFFSET_0300(), self::OFFSET_0200());
     $this->assertEquals($test->isGap(), false);
     $this->assertEquals($test->isOverlap(), true);
     $this->assertEquals($test->getDateTimeBefore(), $before);
     $this->assertEquals($test->getDateTimeAfter(), $after);
     $this->assertEquals($test->getInstant(), $before->toInstant(self::OFFSET_0300()));
     $this->assertEquals($test->getOffsetBefore(), self::OFFSET_0300());
     $this->assertEquals($test->getOffsetAfter(), self::OFFSET_0200());
     $this->assertEquals($test->getDuration(), Duration::of(-1, ChronoUnit::HOURS()));
 }
 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_Apia_jumpForwardOverInternationalDateLine_P12_to_M12()
 {
     // transition occurred at 1879-07-04T00:00+12:33:04
     $test = $this->pacificApia();
     $instantBefore = LocalDate::of(1879, 7, 2)->atStartOfDayWithZone(ZoneOffset::UTC())->toInstant();
     $trans = $test->nextTransition($instantBefore);
     $this->assertEquals($trans->getDateTimeBefore(), LocalDateTime::of(1879, 7, 5, 0, 0));
     $this->assertEquals($trans->getDateTimeAfter(), LocalDateTime::of(1879, 7, 4, 0, 0));
     $this->assertEquals($trans->isGap(), false);
     $this->assertEquals($trans->isOverlap(), true);
     $this->assertEquals($trans->isValidOffset(ZoneOffset::ofHoursMinutesSeconds(+12, 33, 4)), true);
     $this->assertEquals($trans->isValidOffset(ZoneOffset::ofHoursMinutesSeconds(-11, -26, -56)), true);
     $this->assertEquals($trans->getDuration(), Duration::ofHours(-24));
     $this->assertEquals($trans->getInstant(), LocalDateTime::of(1879, 7, 4, 0, 0)->toInstant(ZoneOffset::ofHoursMinutesSeconds(-11, -26, -56)));
     $zdt = ZonedDateTime::of(1879, 7, 4, 23, 0, 0, 0, ZoneId::of("Pacific/Apia"));
     $this->assertEquals($zdt->plusHours(2)->toLocalDateTime(), LocalDateTime::of(1879, 7, 4, 1, 0, 0));
 }
Example #17
0
 public function getDuration()
 {
     return Duration::ofMinutes(90);
 }
 public function test__equals()
 {
     $a = Clock::tick(Clock::system(self::PARIS()), Duration::ofMillis(500));
     $b = Clock::tick(Clock::system(self::PARIS()), Duration::ofMillis(500));
     $this->assertEquals($a->equals($a), true);
     $this->assertEquals($a->equals($b), true);
     $this->assertEquals($b->equals($a), true);
     $this->assertEquals($b->equals($b), true);
     $c = Clock::tick(Clock::system(self::MOSCOW()), Duration::ofMillis(500));
     $this->assertEquals($a->equals($c), false);
     $d = Clock::tick(Clock::system(self::PARIS()), Duration::ofMillis(499));
     $this->assertEquals($a->equals($d), false);
     $this->assertEquals($a->equals(null), false);
     $this->assertEquals($a->equals("other type"), false);
     $this->assertEquals($a->equals(Clock::systemUTC()), false);
 }
 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());
 }
Example #20
0
 /**
  * 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);
 }
Example #21
0
 private function compareTo(ChronoUnit $other)
 {
     return $this->duration->compareTo($other->duration);
 }