Example #1
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;
 }
 /**
  * @expectedException \InvalidArgumentException
  */
 public function test_tick_ClockDuration_negative1s()
 {
     Clock::tick(Clock::systemUTC(), Duration::ofSeconds(-1));
 }
 public function test_minus_TemporalAmount_Duration()
 {
     $duration = Duration::ofSeconds(4 * 60 * 60 + 5 * 60 + 6);
     $z = ZonedDateTime::ofDateTime(LocalDateTime::of(2008, 6, 1, 12, 30, 59, 500), self::ZONE_0100());
     $expected = ZonedDateTime::ofDateTime(LocalDateTime::of(2008, 6, 1, 8, 25, 53, 500), self::ZONE_0100());
     $this->assertEquals($z->minusAmount($duration), $expected);
 }
 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]];
 }
 public function test_getUnit()
 {
     $test = Duration::ofSeconds(2000, 1000);
     $seconds = $test->get(CU::SECONDS());
     $this->assertEquals($seconds, 2000, "duration->get(SECONDS)");
     $nanos = $test->get(CU::NANOS());
     $this->assertEquals($nanos, 1000, "duration->get(NANOS)");
 }
Example #6
0
 public static function init()
 {
     self::$NANOS = new ChronoUnit("Nanos", Duration::ofNanos(1));
     self::$MICROS = new ChronoUnit("Micros", Duration::ofNanos(1000));
     self::$MILLIS = new ChronoUnit("Millis", Duration::ofNanos(1000000));
     self::$SECONDS = new ChronoUnit("Seconds", Duration::ofSeconds(1));
     self::$MINUTES = new ChronoUnit("Minutes", Duration::ofSeconds(60));
     self::$HOURS = new ChronoUnit("Hours", Duration::ofSeconds(3600));
     self::$HALF_DAYS = new ChronoUnit("HalfDays", Duration::ofSeconds(43200));
     self::$DAYS = new ChronoUnit("Days", Duration::ofSeconds(86400));
     self::$WEEKS = new ChronoUnit("Weeks", Duration::ofSeconds(7 * 86400));
     self::$MONTHS = new ChronoUnit("Months", Duration::ofSeconds(31556952 / 12));
     self::$YEARS = new ChronoUnit("Years", Duration::ofSeconds(31556952));
     self::$DECADES = new ChronoUnit("Decades", Duration::ofSeconds(31556952 * 10));
     self::$CENTURIES = new ChronoUnit("Centuries", Duration::ofSeconds(31556952 * 100));
     self::$MILLENNIA = new ChronoUnit("Millennia", Duration::ofSeconds(31556952 * 1000));
     self::$ERAS = new ChronoUnit("Eras", Duration::ofSeconds(31556952 * 1000000000));
     self::$FOREVER = new ChronoUnit("Forever", Duration::ofSeconds(Long::MAX_VALUE, 999999999));
 }
 public function test_minus_Duration()
 {
     $dur = Duration::ofSeconds(62, 3);
     $t = self::TEST_2008_6_30_11_30_59_000000500()->minusAmount($dur);
     $this->assertEquals($t, OffsetDateTime::of(2008, 6, 30, 11, 29, 57, 497, self::OFFSET_PONE()));
 }
Example #8
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());
 }
 /**
  * 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 #10
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)]];
 }
Example #11
0
 /**
  * @expectedException \Celest\DateTimeException
  */
 public function test_minus_Duration_overflowTooBig()
 {
     $i = Instant::ofEpochSecond(self::MAX_SECOND(), 999999999);
     $i->minusAmount(Duration::ofSeconds(-1, 999999999));
 }