예제 #1
0
 /**
  * Calculates the amount of time until another time in terms of the specified unit.
  * <p>
  * This calculates the amount of time between two {@code LocalTime}
  * objects in terms of a single {@code TemporalUnit}.
  * The start and end points are {@code this} and the specified time.
  * The result will be negative if the end is before the start.
  * The {@code Temporal} passed to this method is converted to a
  * {@code LocalTime} using {@link #from(TemporalAccessor)}.
  * For example, the amount in hours between two times can be calculated
  * using {@code startTime.until(endTime, HOURS)}.
  * <p>
  * The calculation returns a whole number, representing the number of
  * complete units between the two times.
  * For example, the amount in hours between 11:30 and 13:29 will only
  * be one hour as it is one minute short of two hours.
  * <p>
  * There are two equivalent ways of using this method.
  * The first is to invoke this method.
  * The second is to use {@link TemporalUnit#between(Temporal, Temporal)}:
  * <pre>
  *   // these two lines are equivalent
  *   amount = start.until(end, MINUTES);
  *   amount = MINUTES.between(start, end);
  * </pre>
  * The choice should be made based on which makes the code more readable.
  * <p>
  * The calculation is implemented in this method for {@link ChronoUnit}.
  * The units {@code NANOS}, {@code MICROS}, {@code MILLIS}, {@code SECONDS},
  * {@code MINUTES}, {@code HOURS} and {@code HALF_DAYS} are supported.
  * Other {@code ChronoUnit} values will throw an exception.
  * <p>
  * If the unit is not a {@code ChronoUnit}, then the result of this method
  * is obtained by invoking {@code TemporalUnit.between(Temporal, Temporal)}
  * passing {@code this} as the first argument and the converted input temporal
  * as the second argument.
  * <p>
  * This instance is immutable and unaffected by this method call.
  *
  * @param Temporal $endExclusive the end time, exclusive, which is converted to a {@code LocalTime}, not null
  * @param $unit $unit the unit to measure the amount in, not null
  * @return int the amount of time between this time and the end time
  * @throws DateTimeException if the amount cannot be calculated, or the end
  *  temporal cannot be converted to a {@code LocalTime}
  * @throws UnsupportedTemporalTypeException if the unit is not supported
  * @throws ArithmeticException if numeric overflow occurs
  */
 public function until(Temporal $endExclusive, TemporalUnit $unit)
 {
     $end = self::from($endExclusive);
     if ($unit instanceof ChronoUnit) {
         $nanosUntil = $end->toNanoOfDay() - $this->toNanoOfDay();
         // no overflow
         switch ($unit) {
             case ChronoUnit::NANOS():
                 return $nanosUntil;
             case ChronoUnit::MICROS():
                 return Math::div($nanosUntil, 1000);
             case ChronoUnit::MILLIS():
                 return Math::div($nanosUntil, 1000000);
             case ChronoUnit::SECONDS():
                 return Math::div($nanosUntil, self::NANOS_PER_SECOND);
             case ChronoUnit::MINUTES():
                 return Math::div($nanosUntil, self::NANOS_PER_MINUTE);
             case ChronoUnit::HOURS():
                 return Math::div($nanosUntil, self::NANOS_PER_HOUR);
             case ChronoUnit::HALF_DAYS():
                 return Math::div($nanosUntil, 12 * self::NANOS_PER_HOUR);
         }
         throw new UnsupportedTemporalTypeException("Unsupported unit: " . $unit);
     }
     return $unit->between($this, $end);
 }
예제 #2
0
 public static function init()
 {
     self::$NANO_OF_SECOND = new ChronoField(0, "NanoOfSecond", ChronoUnit::NANOS(), ChronoUnit::SECONDS(), ValueRange::of(0, 999999999));
     self::$NANO_OF_DAY = new ChronoField(1, "NanoOfDay", ChronoUnit::NANOS(), ChronoUnit::DAYS(), ValueRange::of(0, 86400 * 1000000000 - 1));
     self::$MICRO_OF_SECOND = new ChronoField(2, "MicroOfSecond", ChronoUnit::MICROS(), ChronoUnit::SECONDS(), ValueRange::of(0, 999999));
     self::$MICRO_OF_DAY = new ChronoField(3, "MicroOfDay", ChronoUnit::MICROS(), ChronoUnit::DAYS(), ValueRange::of(0, 86400 * 1000000 - 1));
     self::$MILLI_OF_SECOND = new ChronoField(4, "MilliOfSecond", ChronoUnit::MILLIS(), ChronoUnit::SECONDS(), ValueRange::of(0, 999));
     self::$MILLI_OF_DAY = new ChronoField(5, "MilliOfDay", ChronoUnit::MILLIS(), ChronoUnit::DAYS(), ValueRange::of(0, 86400 * 1000 - 1));
     self::$SECOND_OF_MINUTE = new ChronoField(6, "SecondOfMinute", ChronoUnit::SECONDS(), ChronoUnit::MINUTES(), ValueRange::of(0, 59), "second");
     self::$SECOND_OF_DAY = new ChronoField(7, "SecondOfDay", ChronoUnit::SECONDS(), ChronoUnit::DAYS(), ValueRange::of(0, 86400 - 1));
     self::$MINUTE_OF_HOUR = new ChronoField(8, "MinuteOfHour", ChronoUnit::MINUTES(), ChronoUnit::HOURS(), ValueRange::of(0, 59), "minute");
     self::$MINUTE_OF_DAY = new ChronoField(9, "MinuteOfDay", ChronoUnit::MINUTES(), ChronoUnit::DAYS(), ValueRange::of(0, 24 * 60 - 1));
     self::$HOUR_OF_AMPM = new ChronoField(10, "HourOfAmPm", ChronoUnit::HOURS(), ChronoUnit::HALF_DAYS(), ValueRange::of(0, 11));
     self::$CLOCK_HOUR_OF_AMPM = new ChronoField(11, "ClockHourOfAmPm", ChronoUnit::HOURS(), ChronoUnit::HALF_DAYS(), ValueRange::of(1, 12));
     self::$HOUR_OF_DAY = new ChronoField(12, "HourOfDay", ChronoUnit::HOURS(), ChronoUnit::DAYS(), ValueRange::of(0, 23), "hour");
     self::$CLOCK_HOUR_OF_DAY = new ChronoField(13, "ClockHourOfDay", ChronoUnit::HOURS(), ChronoUnit::DAYS(), ValueRange::of(1, 24));
     self::$AMPM_OF_DAY = new ChronoField(14, "AmPmOfDay", ChronoUnit::HALF_DAYS(), ChronoUnit::DAYS(), ValueRange::of(0, 1), "dayperiod");
     self::$DAY_OF_WEEK = new ChronoField(15, "DayOfWeek", ChronoUnit::DAYS(), ChronoUnit::WEEKS(), ValueRange::of(1, 7), "weekday");
     self::$ALIGNED_DAY_OF_WEEK_IN_MONTH = new ChronoField(16, "AlignedDayOfWeekInMonth", ChronoUnit::DAYS(), ChronoUnit::WEEKS(), ValueRange::of(1, 7));
     self::$ALIGNED_DAY_OF_WEEK_IN_YEAR = new ChronoField(17, "AlignedDayOfWeekInYear", ChronoUnit::DAYS(), ChronoUnit::WEEKS(), ValueRange::of(1, 7));
     self::$DAY_OF_MONTH = new ChronoField(18, "DayOfMonth", ChronoUnit::DAYS(), ChronoUnit::MONTHS(), ValueRange::ofVariable(1, 28, 31), "day");
     self::$DAY_OF_YEAR = new ChronoField(19, "DayOfYear", ChronoUnit::DAYS(), ChronoUnit::YEARS(), ValueRange::ofVariable(1, 365, 366));
     self::$EPOCH_DAY = new ChronoField(20, "EpochDay", ChronoUnit::DAYS(), ChronoUnit::FOREVER(), ValueRange::of(Year::MIN_VALUE * 365.25, Year::MAX_VALUE * 365.25));
     self::$ALIGNED_WEEK_OF_MONTH = new ChronoField(21, "AlignedWeekOfMonth", ChronoUnit::WEEKS(), ChronoUnit::MONTHS(), ValueRange::ofVariable(1, 4, 5));
     self::$ALIGNED_WEEK_OF_YEAR = new ChronoField(22, "AlignedWeekOfYear", ChronoUnit::WEEKS(), ChronoUnit::YEARS(), ValueRange::of(1, 53));
     self::$MONTH_OF_YEAR = new ChronoField(23, "MonthOfYear", ChronoUnit::MONTHS(), ChronoUnit::YEARS(), ValueRange::of(1, 12), "month");
     self::$PROLEPTIC_MONTH = new ChronoField(24, "ProlepticMonth", ChronoUnit::MONTHS(), ChronoUnit::FOREVER(), ValueRange::of(Year::MIN_VALUE * 12, Year::MAX_VALUE * 12 + 11));
     self::$YEAR_OF_ERA = new ChronoField(25, "YearOfEra", ChronoUnit::YEARS(), ChronoUnit::FOREVER(), ValueRange::ofVariable(1, Year::MAX_VALUE, Year::MAX_VALUE + 1));
     self::$YEAR = new ChronoField(26, "Year", ChronoUnit::YEARS(), ChronoUnit::FOREVER(), ValueRange::of(Year::MIN_VALUE, Year::MAX_VALUE), "year");
     self::$ERA = new ChronoField(27, "Era", ChronoUnit::ERAS(), ChronoUnit::FOREVER(), ValueRange::of(0, 1), "era");
     self::$INSTANT_SECONDS = new ChronoField(28, "InstantSeconds", ChronoUnit::SECONDS(), ChronoUnit::FOREVER(), ValueRange::of(Long::MIN_VALUE, Long::MAX_VALUE));
     self::$OFFSET_SECONDS = new ChronoField(29, "OffsetSeconds", ChronoUnit::SECONDS(), ChronoUnit::FOREVER(), ValueRange::of(-18 * 3600, 18 * 3600));
 }
예제 #3
0
 /**
  * Calculates the amount of time until another instant in terms of the specified unit.
  * <p>
  * This calculates the amount of time between two {@code Instant}
  * objects in terms of a single {@code TemporalUnit}.
  * The start and end points are {@code this} and the specified instant.
  * The result will be negative if the end is before the start.
  * The calculation returns a whole number, representing the number of
  * complete units between the two instants.
  * The {@code Temporal} passed to this method is converted to a
  * {@code Instant} using {@link #from(TemporalAccessor)}.
  * For example, the amount in days between two dates can be calculated
  * using {@code startInstant.until(endInstant, SECONDS)}.
  * <p>
  * There are two equivalent ways of using this method.
  * The first is to invoke this method.
  * The second is to use {@link TemporalUnit#between(Temporal, Temporal)}:
  * <pre>
  *   // these two lines are equivalent
  *   amount = start.until(end, SECONDS);
  *   amount = SECONDS.between(start, end);
  * </pre>
  * The choice should be made based on which makes the code more readable.
  * <p>
  * The calculation is implemented in this method for {@link ChronoUnit}.
  * The units {@code NANOS}, {@code MICROS}, {@code MILLIS}, {@code SECONDS},
  * {@code MINUTES}, {@code HOURS}, {@code HALF_DAYS} and {@code DAYS}
  * are supported. Other {@code ChronoUnit} values will throw an exception.
  * <p>
  * If the unit is not a {@code ChronoUnit}, then the result of this method
  * is obtained by invoking {@code TemporalUnit.between(Temporal, Temporal)}
  * passing {@code this} as the first argument and the converted input temporal
  * as the second argument.
  * <p>
  * This instance is immutable and unaffected by this method call.
  *
  * @param Temporal $endExclusive the end date, exclusive, which is converted to an Instant {@code Instant}, not null
  * @param TemporalUnit $unit the unit to measure the amount in, not null
  * @return int the amount of time between this instant and the end instant
  * @throws DateTimeException if the amount cannot be calculated, or the end
  *  temporal cannot be converted to an Instant {@code Instant}
  * @throws UnsupportedTemporalTypeException if the unit is not supported
  * @throws ArithmeticException if numeric overflow occurs
  */
 public function until(Temporal $endExclusive, TemporalUnit $unit)
 {
     $end = Instant::from($endExclusive);
     if ($unit instanceof ChronoUnit) {
         $f = $unit;
         switch ($f) {
             case ChronoUnit::NANOS():
                 return $this->nanosUntil($end);
             case ChronoUnit::MICROS():
                 return Math::div($this->nanosUntil($end), 1000);
             case ChronoUnit::MILLIS():
                 return Math::subtractExact($end->toEpochMilli(), $this->toEpochMilli());
             case ChronoUnit::SECONDS():
                 return $this->secondsUntil($end);
             case ChronoUnit::MINUTES():
                 return Math::div($this->secondsUntil($end), LocalTime::SECONDS_PER_MINUTE);
             case ChronoUnit::HOURS():
                 return Math::div($this->secondsUntil($end), LocalTime::SECONDS_PER_HOUR);
             case ChronoUnit::HALF_DAYS():
                 return Math::div($this->secondsUntil($end), 12 * LocalTime::SECONDS_PER_HOUR);
             case ChronoUnit::DAYS():
                 return Math::div($this->secondsUntil($end), LocalTime::SECONDS_PER_DAY);
         }
         throw new UnsupportedTemporalTypeException("Unsupported unit: " . $unit);
     }
     return $unit->between($this, $end);
 }
 /**
  * @dataProvider data_plusTime
  */
 public function test_until_minutes(ZonedDateTime $base, $expected, ZonedDateTime $end)
 {
     $this->assertEquals($base->until($end, CU::MINUTES()), $expected * 60);
 }
예제 #5
0
 public function test_isSupported_TemporalUnit()
 {
     // TODO $this->assertEquals(self::TEST_2008_06()->isUnitSupported(null), false);
     $this->assertEquals(self::TEST_2008_06()->isUnitSupported(CU::NANOS()), false);
     $this->assertEquals(self::TEST_2008_06()->isUnitSupported(CU::MICROS()), false);
     $this->assertEquals(self::TEST_2008_06()->isUnitSupported(CU::MILLIS()), false);
     $this->assertEquals(self::TEST_2008_06()->isUnitSupported(CU::SECONDS()), false);
     $this->assertEquals(self::TEST_2008_06()->isUnitSupported(CU::MINUTES()), false);
     $this->assertEquals(self::TEST_2008_06()->isUnitSupported(CU::HOURS()), false);
     $this->assertEquals(self::TEST_2008_06()->isUnitSupported(CU::HALF_DAYS()), false);
     $this->assertEquals(self::TEST_2008_06()->isUnitSupported(CU::DAYS()), false);
     $this->assertEquals(self::TEST_2008_06()->isUnitSupported(CU::WEEKS()), false);
     $this->assertEquals(self::TEST_2008_06()->isUnitSupported(CU::MONTHS()), true);
     $this->assertEquals(self::TEST_2008_06()->isUnitSupported(CU::YEARS()), true);
     $this->assertEquals(self::TEST_2008_06()->isUnitSupported(CU::DECADES()), true);
     $this->assertEquals(self::TEST_2008_06()->isUnitSupported(CU::CENTURIES()), true);
     $this->assertEquals(self::TEST_2008_06()->isUnitSupported(CU::MILLENNIA()), true);
     $this->assertEquals(self::TEST_2008_06()->isUnitSupported(CU::ERAS()), true);
     $this->assertEquals(self::TEST_2008_06()->isUnitSupported(CU::FOREVER()), false);
 }
 function data_periodUntilUnit()
 {
     return [[$this->dtNoon(2000, 1, 1), $this->dtNoon(2000, 1, 1), CU::DAYS(), 0], [$this->dtNoon(2000, 1, 1), $this->dtNoon(2000, 1, 1), CU::WEEKS(), 0], [$this->dtNoon(2000, 1, 1), $this->dtNoon(2000, 1, 1), CU::MONTHS(), 0], [$this->dtNoon(2000, 1, 1), $this->dtNoon(2000, 1, 1), CU::YEARS(), 0], [$this->dtNoon(2000, 1, 1), $this->dtNoon(2000, 1, 1), CU::DECADES(), 0], [$this->dtNoon(2000, 1, 1), $this->dtNoon(2000, 1, 1), CU::CENTURIES(), 0], [$this->dtNoon(2000, 1, 1), $this->dtNoon(2000, 1, 1), CU::MILLENNIA(), 0], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2000, 2, 14), CU::DAYS(), 30], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2000, 2, 15), CU::DAYS(), 31], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2000, 2, 16), CU::DAYS(), 32], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2000, 2, 17), CU::WEEKS(), 4], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2000, 2, 18), CU::WEEKS(), 4], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2000, 2, 19), CU::WEEKS(), 5], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2000, 2, 20), CU::WEEKS(), 5], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2000, 2, 14), CU::MONTHS(), 0], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2000, 2, 15), CU::MONTHS(), 1], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2000, 2, 16), CU::MONTHS(), 1], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2000, 3, 14), CU::MONTHS(), 1], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2000, 3, 15), CU::MONTHS(), 2], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2000, 3, 16), CU::MONTHS(), 2], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2001, 1, 14), CU::YEARS(), 0], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2001, 1, 15), CU::YEARS(), 1], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2001, 1, 16), CU::YEARS(), 1], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2004, 1, 14), CU::YEARS(), 3], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2004, 1, 15), CU::YEARS(), 4], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2004, 1, 16), CU::YEARS(), 4], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2010, 1, 14), CU::DECADES(), 0], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2010, 1, 15), CU::DECADES(), 1], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2100, 1, 14), CU::CENTURIES(), 0], [$this->dtNoon(2000, 1, 15), $this->dtNoon(2100, 1, 15), CU::CENTURIES(), 1], [$this->dtNoon(2000, 1, 15), $this->dtNoon(3000, 1, 14), CU::MILLENNIA(), 0], [$this->dtNoon(2000, 1, 15), $this->dtNoon(3000, 1, 15), CU::MILLENNIA(), 1], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(0, 0, 0, 0), CU::NANOS(), 0], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(0, 0, 0, 0), CU::MICROS(), 0], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(0, 0, 0, 0), CU::MILLIS(), 0], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(0, 0, 0, 0), CU::SECONDS(), 0], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(0, 0, 0, 0), CU::MINUTES(), 0], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(0, 0, 0, 0), CU::HOURS(), 0], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(0, 0, 0, 0), CU::HALF_DAYS(), 0], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(2, 0, 0, 0), CU::NANOS(), 2 * 3600 * 1000000000], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(2, 0, 0, 0), CU::MICROS(), 2 * 3600 * 1000000], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(2, 0, 0, 0), CU::MILLIS(), 2 * 3600 * 1000], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(2, 0, 0, 0), CU::SECONDS(), 2 * 3600], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(2, 0, 0, 0), CU::MINUTES(), 2 * 60], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(2, 0, 0, 0), CU::HOURS(), 2], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(2, 0, 0, 0), CU::HALF_DAYS(), 0], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(14, 0, 0, 0), CU::NANOS(), 14 * 3600 * 1000000000], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(14, 0, 0, 0), CU::MICROS(), 14 * 3600 * 1000000], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(14, 0, 0, 0), CU::MILLIS(), 14 * 3600 * 1000], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(14, 0, 0, 0), CU::SECONDS(), 14 * 3600], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(14, 0, 0, 0), CU::MINUTES(), 14 * 60], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(14, 0, 0, 0), CU::HOURS(), 14], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(14, 0, 0, 0), CU::HALF_DAYS(), 1], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(2, 30, 40, 1500), CU::NANOS(), (2 * 3600 + 30 * 60 + 40) * 1000000000 + 1500], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(2, 30, 40, 1500), CU::MICROS(), (2 * 3600 + 30 * 60 + 40) * 1000000 + 1], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(2, 30, 40, 1500), CU::MILLIS(), (2 * 3600 + 30 * 60 + 40) * 1000], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(2, 30, 40, 1500), CU::SECONDS(), 2 * 3600 + 30 * 60 + 40], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(2, 30, 40, 1500), CU::MINUTES(), 2 * 60 + 30], [$this->dtEpoch(0, 0, 0, 0), $this->dtEpoch(2, 30, 40, 1500), CU::HOURS(), 2], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 15, 12, 30, 40, 499), CU::NANOS(), -1], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 15, 12, 30, 40, 500), CU::NANOS(), 0], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 15, 12, 30, 40, 501), CU::NANOS(), 1], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 15, 12, 30, 39, 500), CU::SECONDS(), -1], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 15, 12, 30, 39, 501), CU::SECONDS(), 0], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 15, 12, 30, 40, 499), CU::SECONDS(), 0], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 15, 12, 30, 40, 500), CU::SECONDS(), 0], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 15, 12, 30, 40, 501), CU::SECONDS(), 0], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 15, 12, 30, 41, 499), CU::SECONDS(), 0], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 15, 12, 30, 41, 500), CU::SECONDS(), 1], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 40, 499), CU::NANOS(), -1 + 86400000000000], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 40, 500), CU::NANOS(), 0 + 86400000000000], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 40, 501), CU::NANOS(), 1 + 86400000000000], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 39, 499), CU::SECONDS(), -2 + 86400], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 39, 500), CU::SECONDS(), -1 + 86400], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 39, 501), CU::SECONDS(), -1 + 86400], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 40, 499), CU::SECONDS(), -1 + 86400], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 40, 500), CU::SECONDS(), 0 + 86400], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 40, 501), CU::SECONDS(), 0 + 86400], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 41, 499), CU::SECONDS(), 0 + 86400], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 41, 500), CU::SECONDS(), 1 + 86400], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 29, 40, 499), CU::MINUTES(), -2 + 24 * 60], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 29, 40, 500), CU::MINUTES(), -1 + 24 * 60], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 29, 40, 501), CU::MINUTES(), -1 + 24 * 60], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 40, 499), CU::MINUTES(), -1 + 24 * 60], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 40, 500), CU::MINUTES(), 0 + 24 * 60], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 40, 501), CU::MINUTES(), 0 + 24 * 60], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 31, 40, 499), CU::MINUTES(), 0 + 24 * 60], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 31, 40, 500), CU::MINUTES(), 1 + 24 * 60], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 11, 30, 40, 499), CU::HOURS(), -2 + 24], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 11, 30, 40, 500), CU::HOURS(), -1 + 24], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 11, 30, 40, 501), CU::HOURS(), -1 + 24], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 40, 499), CU::HOURS(), -1 + 24], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 40, 500), CU::HOURS(), 0 + 24], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 40, 501), CU::HOURS(), 0 + 24], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 13, 30, 40, 499), CU::HOURS(), 0 + 24], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 13, 30, 40, 500), CU::HOURS(), 1 + 24], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 13, 12, 30, 40, 499), CU::DAYS(), -2], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 13, 12, 30, 40, 500), CU::DAYS(), -2], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 13, 12, 30, 40, 501), CU::DAYS(), -1], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 14, 12, 30, 40, 499), CU::DAYS(), -1], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 14, 12, 30, 40, 500), CU::DAYS(), -1], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 14, 12, 30, 40, 501), CU::DAYS(), 0], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 15, 12, 30, 40, 499), CU::DAYS(), 0], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 15, 12, 30, 40, 500), CU::DAYS(), 0], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 15, 12, 30, 40, 501), CU::DAYS(), 0], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 40, 499), CU::DAYS(), 0], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 40, 500), CU::DAYS(), 1], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 16, 12, 30, 40, 501), CU::DAYS(), 1], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 17, 12, 30, 40, 499), CU::DAYS(), 1], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 17, 12, 30, 40, 500), CU::DAYS(), 2], [$this->dt(2000, 1, 15, 12, 30, 40, 500), $this->dt(2000, 1, 17, 12, 30, 40, 501), CU::DAYS(), 2]];
 }
 function data_untilUnit()
 {
     return [[OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()), OffsetDateTime::of(2010, 6, 30, 13, 1, 1, 0, self::OFFSET_PONE()), CU::HALF_DAYS(), 1], [OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()), OffsetDateTime::of(2010, 6, 30, 2, 1, 1, 0, self::OFFSET_PONE()), CU::HOURS(), 1], [OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()), OffsetDateTime::of(2010, 6, 30, 2, 1, 1, 0, self::OFFSET_PONE()), CU::MINUTES(), 60], [OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()), OffsetDateTime::of(2010, 6, 30, 2, 1, 1, 0, self::OFFSET_PONE()), CU::SECONDS(), 3600], [OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()), OffsetDateTime::of(2010, 6, 30, 2, 1, 1, 0, self::OFFSET_PONE()), CU::MILLIS(), 3600 * 1000], [OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()), OffsetDateTime::of(2010, 6, 30, 2, 1, 1, 0, self::OFFSET_PONE()), CU::MICROS(), 3600 * 1000 * 1000], [OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()), OffsetDateTime::of(2010, 6, 30, 2, 1, 1, 0, self::OFFSET_PONE()), CU::NANOS(), 3600 * 1000 * 1000 * 1000], [OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()), OffsetDateTime::of(2010, 6, 30, 14, 1, 1, 0, self::OFFSET_PTWO()), CU::HALF_DAYS(), 1], [OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()), OffsetDateTime::of(2010, 6, 30, 3, 1, 1, 0, self::OFFSET_PTWO()), CU::HOURS(), 1], [OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()), OffsetDateTime::of(2010, 6, 30, 3, 1, 1, 0, self::OFFSET_PTWO()), CU::MINUTES(), 60], [OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()), OffsetDateTime::of(2010, 6, 30, 3, 1, 1, 0, self::OFFSET_PTWO()), CU::SECONDS(), 3600], [OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()), OffsetDateTime::of(2010, 6, 30, 3, 1, 1, 0, self::OFFSET_PTWO()), CU::MILLIS(), 3600 * 1000], [OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()), OffsetDateTime::of(2010, 6, 30, 3, 1, 1, 0, self::OFFSET_PTWO()), CU::MICROS(), 3600 * 1000 * 1000], [OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()), OffsetDateTime::of(2010, 6, 30, 3, 1, 1, 0, self::OFFSET_PTWO()), CU::NANOS(), 3600 * 1000 * 1000 * 1000], [OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()), OffsetDateTime::of(2010, 7, 1, 1, 1, 0, 999999999, self::OFFSET_PONE()), CU::DAYS(), 0], [OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()), OffsetDateTime::of(2010, 7, 1, 1, 1, 1, 0, self::OFFSET_PONE()), CU::DAYS(), 1], [OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()), OffsetDateTime::of(2010, 8, 29, 1, 1, 1, 0, self::OFFSET_PONE()), CU::MONTHS(), 1], [OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()), OffsetDateTime::of(2010, 8, 30, 1, 1, 1, 0, self::OFFSET_PONE()), CU::MONTHS(), 2], [OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()), OffsetDateTime::of(2010, 8, 31, 1, 1, 1, 0, self::OFFSET_PONE()), CU::MONTHS(), 2]];
 }
예제 #8
0
 function provider_factory_of_badTemporalUnit()
 {
     return [[0, CU::MICROS()], [0, CU::MILLIS()], [0, CU::MINUTES()], [0, CU::HOURS()], [0, CU::HALF_DAYS()], [0, CU::DAYS()], [0, CU::MONTHS()], [0, CU::YEARS()], [0, CU::DECADES()], [0, CU::CENTURIES()], [0, CU::MILLENNIA()]];
 }
예제 #9
0
 /**
  * Calculates the amount of time until another date-time in terms of the specified unit.
  * <p>
  * This calculates the amount of time between two {@code LocalDateTime}
  * objects in terms of a single {@code TemporalUnit}.
  * The start and end points are {@code this} and the specified date-time.
  * The result will be negative if the end is before the start.
  * The {@code Temporal} passed to this method is converted to a
  * {@code LocalDateTime} using {@link #from(TemporalAccessor)}.
  * For example, the amount in days between two date-times can be calculated
  * using {@code startDateTime.until(endDateTime, DAYS)}.
  * <p>
  * The calculation returns a whole number, representing the number of
  * complete units between the two date-times.
  * For example, the amount in months between 2012-06-15T00:00 and 2012-08-14T23:59
  * will only be one month as it is one minute short of two months.
  * <p>
  * There are two equivalent ways of using this method.
  * The first is to invoke this method.
  * The second is to use {@link TemporalUnit#between(Temporal, Temporal)}:
  * <pre>
  *   // these two lines are equivalent
  *   amount = start.until(end, MONTHS);
  *   amount = MONTHS.between(start, end);
  * </pre>
  * The choice should be made based on which makes the code more readable.
  * <p>
  * The calculation is implemented in this method for {@link ChronoUnit}.
  * The units {@code NANOS}, {@code MICROS}, {@code MILLIS}, {@code SECONDS},
  * {@code MINUTES}, {@code HOURS} and {@code HALF_DAYS}, {@code DAYS},
  * {@code WEEKS}, {@code MONTHS}, {@code YEARS}, {@code DECADES},
  * {@code CENTURIES}, {@code MILLENNIA} and {@code ERAS} are supported.
  * Other {@code ChronoUnit} values will throw an exception.
  * <p>
  * If the unit is not a {@code ChronoUnit}, then the result of this method
  * is obtained by invoking {@code TemporalUnit.between(Temporal, Temporal)}
  * passing {@code this} as the first argument and the converted input temporal
  * as the second argument.
  * <p>
  * This instance is immutable and unaffected by this method call.
  *
  * @param Temporal $endExclusive the end date, exclusive, which is converted to a {@code LocalDateTime}, not null
  * @param TemporalUnit $unit the unit to measure the amount in, not null
  * @return int the amount of time between this date-time and the end date-time
  * @throws DateTimeException if the amount cannot be calculated, or the end
  *  temporal cannot be converted to a {@code LocalDateTime}
  * @throws UnsupportedTemporalTypeException if the unit is not supported
  * @throws ArithmeticException if numeric overflow occurs
  */
 public function until(Temporal $endExclusive, TemporalUnit $unit)
 {
     $end = LocalDateTime::from($endExclusive);
     if ($unit instanceof ChronoUnit) {
         if ($unit->isTimeBased()) {
             $amount = $this->date->daysUntil($end->date);
             if ($amount === 0) {
                 return $this->time->until($end->time, $unit);
             }
             $timePart = $end->time->toNanoOfDay() - $this->time->toNanoOfDay();
             if ($amount > 0) {
                 $amount--;
                 // safe
                 $timePart += LocalTime::NANOS_PER_DAY;
                 // safe
             } else {
                 $amount++;
                 // safe
                 $timePart -= LocalTime::NANOS_PER_DAY;
                 // safe
             }
             switch ($unit) {
                 case ChronoUnit::NANOS():
                     $amount = Math::multiplyExact($amount, LocalTime::NANOS_PER_DAY);
                     break;
                 case ChronoUnit::MICROS():
                     $amount = Math::multiplyExact($amount, LocalTime::MICROS_PER_DAY);
                     $timePart = Math::div($timePart, 1000);
                     break;
                 case ChronoUnit::MILLIS():
                     $amount = Math::multiplyExact($amount, LocalTime::MILLIS_PER_DAY);
                     $timePart = Math::div($timePart, 1000000);
                     break;
                 case ChronoUnit::SECONDS():
                     $amount = Math::multiplyExact($amount, LocalTime::SECONDS_PER_DAY);
                     $timePart = Math::div($timePart, LocalTime::NANOS_PER_SECOND);
                     break;
                 case ChronoUnit::MINUTES():
                     $amount = Math::multiplyExact($amount, LocalTime::MINUTES_PER_DAY);
                     $timePart = Math::div($timePart, LocalTime::NANOS_PER_MINUTE);
                     break;
                 case ChronoUnit::HOURS():
                     $amount = Math::multiplyExact($amount, LocalTime::HOURS_PER_DAY);
                     $timePart = Math::div($timePart, LocalTime::NANOS_PER_HOUR);
                     break;
                 case ChronoUnit::HALF_DAYS():
                     $amount = Math::multiplyExact($amount, 2);
                     $timePart = Math::div($timePart, LocalTime::NANOS_PER_HOUR * 12);
                     break;
             }
             return Math::addExact($amount, $timePart);
         }
         $endDate = $end->date;
         if ($endDate->isAfter($this->date) && $end->time->isBefore($this->time)) {
             $endDate = $endDate->minusDays(1);
         } else {
             if ($endDate->isBefore($this->date) && $end->time->isAfter($this->time)) {
                 $endDate = $endDate->plusDays(1);
             }
         }
         return $this->date->until($endDate, $unit);
     }
     return $unit->between($this, $end);
 }
예제 #10
0
 function data_fieldUnit()
 {
     return [[CF::YEAR(), CU::YEARS(), CU::FOREVER()], [CF::MONTH_OF_YEAR(), CU::MONTHS(), CU::YEARS()], [CF::DAY_OF_MONTH(), CU::DAYS(), CU::MONTHS()], [CF::DAY_OF_WEEK(), CU::DAYS(), CU::WEEKS()], [CF::DAY_OF_YEAR(), CU::DAYS(), CU::YEARS()], [CF::HOUR_OF_DAY(), CU::HOURS(), CU::DAYS()], [CF::MINUTE_OF_DAY(), CU::MINUTES(), CU::DAYS()], [CF::MINUTE_OF_HOUR(), CU::MINUTES(), CU::HOURS()], [CF::SECOND_OF_DAY(), CU::SECONDS(), CU::DAYS()], [CF::SECOND_OF_MINUTE(), CU::SECONDS(), CU::MINUTES()], [CF::MILLI_OF_DAY(), CU::MILLIS(), CU::DAYS()], [CF::MILLI_OF_SECOND(), CU::MILLIS(), CU::SECONDS()], [CF::MICRO_OF_SECOND(), CU::MICROS(), CU::SECONDS()], [CF::MICRO_OF_DAY(), CU::MICROS(), CU::DAYS()], [CF::NANO_OF_SECOND(), CU::NANOS(), CU::SECONDS()], [CF::NANO_OF_DAY(), CU::NANOS(), CU::DAYS()]];
 }
 public function until(Temporal $endExclusive, TemporalUnit $unit)
 {
     $end = $this->getChronology()->localDateTime($endExclusive);
     if ($unit instanceof ChronoUnit) {
         if ($unit->isTimeBased()) {
             $amount = $end->getLong(ChronoField::EPOCH_DAY()) - $this->date->getLong(ChronoField::EPOCH_DAY());
             switch ($unit) {
                 case ChronoUnit::NANOS():
                     $amount = Math::multiplyExact($amount, self::NANOS_PER_DAY);
                     break;
                 case ChronoUnit::MICROS():
                     $amount = Math::multiplyExact($amount, self::MICROS_PER_DAY);
                     break;
                 case ChronoUnit::MILLIS():
                     $amount = Math::multiplyExact($amount, self::MILLIS_PER_DAY);
                     break;
                 case ChronoUnit::SECONDS():
                     $amount = Math::multiplyExact($amount, self::SECONDS_PER_DAY);
                     break;
                 case ChronoUnit::MINUTES():
                     $amount = Math::multiplyExact($amount, self::MINUTES_PER_DAY);
                     break;
                 case ChronoUnit::HOURS():
                     $amount = Math::multiplyExact($amount, self::HOURS_PER_DAY);
                     break;
                 case ChronoUnit::HALF_DAYS():
                     $amount = Math::multiplyExact($amount, 2);
                     break;
             }
             return Math::addExact($amount, $this->time->until($end->toLocalTime(), $unit));
         }
         $endDate = $end->toLocalDate();
         if ($end->toLocalTime()->isBefore($this->time)) {
             $endDate = $endDate->minus(1, ChronoUnit::DAYS());
         }
         return $this->date->until($endDate, $unit);
     }
     return $unit->between($this, $end);
 }
예제 #12
0
 function data_periodUntilUnit()
 {
     return [[$this->time(0, 0, 0, 0), $this->time(0, 0, 0, 0), CU::NANOS(), 0], [$this->time(0, 0, 0, 0), $this->time(0, 0, 0, 0), CU::MICROS(), 0], [$this->time(0, 0, 0, 0), $this->time(0, 0, 0, 0), CU::MILLIS(), 0], [$this->time(0, 0, 0, 0), $this->time(0, 0, 0, 0), CU::SECONDS(), 0], [$this->time(0, 0, 0, 0), $this->time(0, 0, 0, 0), CU::MINUTES(), 0], [$this->time(0, 0, 0, 0), $this->time(0, 0, 0, 0), CU::HOURS(), 0], [$this->time(0, 0, 0, 0), $this->time(0, 0, 0, 0), CU::HALF_DAYS(), 0], [$this->time(0, 0, 0, 0), $this->time(2, 0, 0, 0), CU::NANOS(), 2 * 3600 * 1000000000], [$this->time(0, 0, 0, 0), $this->time(2, 0, 0, 0), CU::MICROS(), 2 * 3600 * 1000000], [$this->time(0, 0, 0, 0), $this->time(2, 0, 0, 0), CU::MILLIS(), 2 * 3600 * 1000], [$this->time(0, 0, 0, 0), $this->time(2, 0, 0, 0), CU::SECONDS(), 2 * 3600], [$this->time(0, 0, 0, 0), $this->time(2, 0, 0, 0), CU::MINUTES(), 2 * 60], [$this->time(0, 0, 0, 0), $this->time(2, 0, 0, 0), CU::HOURS(), 2], [$this->time(0, 0, 0, 0), $this->time(2, 0, 0, 0), CU::HALF_DAYS(), 0], [$this->time(0, 0, 0, 0), $this->time(14, 0, 0, 0), CU::NANOS(), 14 * 3600 * 1000000000], [$this->time(0, 0, 0, 0), $this->time(14, 0, 0, 0), CU::MICROS(), 14 * 3600 * 1000000], [$this->time(0, 0, 0, 0), $this->time(14, 0, 0, 0), CU::MILLIS(), 14 * 3600 * 1000], [$this->time(0, 0, 0, 0), $this->time(14, 0, 0, 0), CU::SECONDS(), 14 * 3600], [$this->time(0, 0, 0, 0), $this->time(14, 0, 0, 0), CU::MINUTES(), 14 * 60], [$this->time(0, 0, 0, 0), $this->time(14, 0, 0, 0), CU::HOURS(), 14], [$this->time(0, 0, 0, 0), $this->time(14, 0, 0, 0), CU::HALF_DAYS(), 1], [$this->time(0, 0, 0, 0), $this->time(2, 30, 40, 1500), CU::NANOS(), (2 * 3600 + 30 * 60 + 40) * 1000000000 + 1500], [$this->time(0, 0, 0, 0), $this->time(2, 30, 40, 1500), CU::MICROS(), (2 * 3600 + 30 * 60 + 40) * 1000000 + 1], [$this->time(0, 0, 0, 0), $this->time(2, 30, 40, 1500), CU::MILLIS(), (2 * 3600 + 30 * 60 + 40) * 1000], [$this->time(0, 0, 0, 0), $this->time(2, 30, 40, 1500), CU::SECONDS(), 2 * 3600 + 30 * 60 + 40], [$this->time(0, 0, 0, 0), $this->time(2, 30, 40, 1500), CU::MINUTES(), 2 * 60 + 30], [$this->time(0, 0, 0, 0), $this->time(2, 30, 40, 1500), CU::HOURS(), 2]];
 }
예제 #13
0
 function data_untilUnit()
 {
     return [[OffsetTime::of(1, 1, 1, 0, self::OFFSET_PONE()), OffsetTime::of(13, 1, 1, 0, self::OFFSET_PONE()), CU::HALF_DAYS(), 1], [OffsetTime::of(1, 1, 1, 0, self::OFFSET_PONE()), OffsetTime::of(2, 1, 1, 0, self::OFFSET_PONE()), CU::HOURS(), 1], [OffsetTime::of(1, 1, 1, 0, self::OFFSET_PONE()), OffsetTime::of(2, 1, 1, 0, self::OFFSET_PONE()), CU::MINUTES(), 60], [OffsetTime::of(1, 1, 1, 0, self::OFFSET_PONE()), OffsetTime::of(2, 1, 1, 0, self::OFFSET_PONE()), CU::SECONDS(), 3600], [OffsetTime::of(1, 1, 1, 0, self::OFFSET_PONE()), OffsetTime::of(2, 1, 1, 0, self::OFFSET_PONE()), CU::MILLIS(), 3600 * 1000], [OffsetTime::of(1, 1, 1, 0, self::OFFSET_PONE()), OffsetTime::of(2, 1, 1, 0, self::OFFSET_PONE()), CU::MICROS(), 3600 * 1000 * 1000], [OffsetTime::of(1, 1, 1, 0, self::OFFSET_PONE()), OffsetTime::of(2, 1, 1, 0, self::OFFSET_PONE()), CU::NANOS(), 3600 * 1000 * 1000 * 1000], [OffsetTime::of(1, 1, 1, 0, self::OFFSET_PONE()), OffsetTime::of(14, 1, 1, 0, self::OFFSET_PTWO()), CU::HALF_DAYS(), 1], [OffsetTime::of(1, 1, 1, 0, self::OFFSET_PONE()), OffsetTime::of(3, 1, 1, 0, self::OFFSET_PTWO()), CU::HOURS(), 1], [OffsetTime::of(1, 1, 1, 0, self::OFFSET_PONE()), OffsetTime::of(3, 1, 1, 0, self::OFFSET_PTWO()), CU::MINUTES(), 60], [OffsetTime::of(1, 1, 1, 0, self::OFFSET_PONE()), OffsetTime::of(3, 1, 1, 0, self::OFFSET_PTWO()), CU::SECONDS(), 3600], [OffsetTime::of(1, 1, 1, 0, self::OFFSET_PONE()), OffsetTime::of(3, 1, 1, 0, self::OFFSET_PTWO()), CU::MILLIS(), 3600 * 1000], [OffsetTime::of(1, 1, 1, 0, self::OFFSET_PONE()), OffsetTime::of(3, 1, 1, 0, self::OFFSET_PTWO()), CU::MICROS(), 3600 * 1000 * 1000], [OffsetTime::of(1, 1, 1, 0, self::OFFSET_PONE()), OffsetTime::of(3, 1, 1, 0, self::OFFSET_PTWO()), CU::NANOS(), 3600 * 1000 * 1000 * 1000]];
 }
예제 #14
0
 /**
  * Calculates the amount of time until another time in terms of the specified unit.
  * <p>
  * This calculates the amount of time between two {@code OffsetTime}
  * objects in terms of a single {@code TemporalUnit}.
  * The start and end points are {@code this} and the specified time.
  * The result will be negative if the end is before the start.
  * For example, the amount in hours between two times can be calculated
  * using {@code startTime.until(endTime, HOURS)}.
  * <p>
  * The {@code Temporal} passed to this method is converted to a
  * {@code OffsetTime} using {@link #from(TemporalAccessor)}.
  * If the offset differs between the two times, then the specified
  * end time is normalized to have the same offset as this time.
  * <p>
  * The calculation returns a whole number, representing the number of
  * complete units between the two times.
  * For example, the amount in hours between 11:30Z and 13:29Z will only
  * be one hour as it is one minute short of two hours.
  * <p>
  * There are two equivalent ways of using this method.
  * The first is to invoke this method.
  * The second is to use {@link TemporalUnit#between(Temporal, Temporal)}:
  * <pre>
  *   // these two lines are equivalent
  *   amount = start.until(end, MINUTES);
  *   amount = MINUTES.between(start, end);
  * </pre>
  * The choice should be made based on which makes the code more readable.
  * <p>
  * The calculation is implemented in this method for {@link ChronoUnit}.
  * The units {@code NANOS}, {@code MICROS}, {@code MILLIS}, {@code SECONDS},
  * {@code MINUTES}, {@code HOURS} and {@code HALF_DAYS} are supported.
  * Other {@code ChronoUnit} values will throw an exception.
  * <p>
  * If the unit is not a {@code ChronoUnit}, then the result of this method
  * is obtained by invoking {@code TemporalUnit.between(Temporal, Temporal)}
  * passing {@code this} as the first argument and the converted input temporal
  * as the second argument.
  * <p>
  * This instance is immutable and unaffected by this method call.
  *
  * @param Temporal $endExclusive the end time, exclusive, which is converted to an {@code OffsetTime}, not null
  * @param TemporalUnit $unit the unit to measure the amount in, not null
  * @return int the amount of time between this time and the end time
  * @throws DateTimeException if the amount cannot be calculated, or the end
  *  temporal cannot be converted to an {@code OffsetTime}
  * @throws UnsupportedTemporalTypeException if the unit is not supported
  * @throws ArithmeticException if numeric overflow occurs
  */
 public function until(Temporal $endExclusive, TemporalUnit $unit)
 {
     $end = OffsetTime::from($endExclusive);
     if ($unit instanceof ChronoUnit) {
         $nanosUntil = $end->toEpochNano() - $this->toEpochNano();
         // no overflow
         switch ($unit) {
             case ChronoUnit::NANOS():
                 return $nanosUntil;
             case ChronoUnit::MICROS():
                 return $nanosUntil / 1000;
             case ChronoUnit::MILLIS():
                 return $nanosUntil / 1000000;
             case ChronoUnit::SECONDS():
                 return $nanosUntil / LocalTime::NANOS_PER_SECOND;
             case ChronoUnit::MINUTES():
                 return $nanosUntil / LocalTime::NANOS_PER_MINUTE;
             case ChronoUnit::HOURS():
                 return $nanosUntil / LocalTime::NANOS_PER_HOUR;
             case ChronoUnit::HALF_DAYS():
                 return $nanosUntil / (12 * LocalTime::NANOS_PER_HOUR);
         }
         throw new UnsupportedTemporalTypeException("Unsupported unit: " . $unit);
     }
     return $unit->between($this, $end);
 }
예제 #15
0
 function data_periodUntilUnit()
 {
     return [[5, 650, -1, 650, CU::SECONDS(), -6], [5, 650, 0, 650, CU::SECONDS(), -5], [5, 650, 3, 650, CU::SECONDS(), -2], [5, 650, 4, 650, CU::SECONDS(), -1], [5, 650, 5, 650, CU::SECONDS(), 0], [5, 650, 6, 650, CU::SECONDS(), 1], [5, 650, 7, 650, CU::SECONDS(), 2], [5, 650, -1, 0, CU::SECONDS(), -6], [5, 650, 0, 0, CU::SECONDS(), -5], [5, 650, 3, 0, CU::SECONDS(), -2], [5, 650, 4, 0, CU::SECONDS(), -1], [5, 650, 5, 0, CU::SECONDS(), 0], [5, 650, 6, 0, CU::SECONDS(), 0], [5, 650, 7, 0, CU::SECONDS(), 1], [5, 650, -1, 950, CU::SECONDS(), -5], [5, 650, 0, 950, CU::SECONDS(), -4], [5, 650, 3, 950, CU::SECONDS(), -1], [5, 650, 4, 950, CU::SECONDS(), 0], [5, 650, 5, 950, CU::SECONDS(), 0], [5, 650, 6, 950, CU::SECONDS(), 1], [5, 650, 7, 950, CU::SECONDS(), 2], [5, 650, -1, 50, CU::SECONDS(), -6], [5, 650, 0, 50, CU::SECONDS(), -5], [5, 650, 4, 50, CU::SECONDS(), -1], [5, 650, 5, 50, CU::SECONDS(), 0], [5, 650, 6, 50, CU::SECONDS(), 0], [5, 650, 7, 50, CU::SECONDS(), 1], [5, 650, 8, 50, CU::SECONDS(), 2], [5, 650000000, -1, 650000000, CU::NANOS(), -6000000000], [5, 650000000, 0, 650000000, CU::NANOS(), -5000000000], [5, 650000000, 3, 650000000, CU::NANOS(), -2000000000], [5, 650000000, 4, 650000000, CU::NANOS(), -1000000000], [5, 650000000, 5, 650000000, CU::NANOS(), 0], [5, 650000000, 6, 650000000, CU::NANOS(), 1000000000], [5, 650000000, 7, 650000000, CU::NANOS(), 2000000000], [5, 650000000, -1, 0, CU::NANOS(), -6650000000], [5, 650000000, 0, 0, CU::NANOS(), -5650000000], [5, 650000000, 3, 0, CU::NANOS(), -2650000000], [5, 650000000, 4, 0, CU::NANOS(), -1650000000], [5, 650000000, 5, 0, CU::NANOS(), -650000000], [5, 650000000, 6, 0, CU::NANOS(), 350000000], [5, 650000000, 7, 0, CU::NANOS(), 1350000000], [5, 650000000, -1, 950000000, CU::NANOS(), -5700000000], [5, 650000000, 0, 950000000, CU::NANOS(), -4700000000], [5, 650000000, 3, 950000000, CU::NANOS(), -1700000000], [5, 650000000, 4, 950000000, CU::NANOS(), -700000000], [5, 650000000, 5, 950000000, CU::NANOS(), 300000000], [5, 650000000, 6, 950000000, CU::NANOS(), 1300000000], [5, 650000000, 7, 950000000, CU::NANOS(), 2300000000], [5, 650000000, -1, 50000000, CU::NANOS(), -6600000000], [5, 650000000, 0, 50000000, CU::NANOS(), -5600000000], [5, 650000000, 4, 50000000, CU::NANOS(), -1600000000], [5, 650000000, 5, 50000000, CU::NANOS(), -600000000], [5, 650000000, 6, 50000000, CU::NANOS(), 400000000], [5, 650000000, 7, 50000000, CU::NANOS(), 1400000000], [5, 650000000, 8, 50000000, CU::NANOS(), 2400000000], [0, 0, -60, 0, CU::MINUTES(), -1], [0, 0, -1, 999999999, CU::MINUTES(), 0], [0, 0, 59, 0, CU::MINUTES(), 0], [0, 0, 59, 999999999, CU::MINUTES(), 0], [0, 0, 60, 0, CU::MINUTES(), 1], [0, 0, 61, 0, CU::MINUTES(), 1], [0, 0, -3600, 0, CU::HOURS(), -1], [0, 0, -1, 999999999, CU::HOURS(), 0], [0, 0, 3599, 0, CU::HOURS(), 0], [0, 0, 3599, 999999999, CU::HOURS(), 0], [0, 0, 3600, 0, CU::HOURS(), 1], [0, 0, 3601, 0, CU::HOURS(), 1], [0, 0, -86400, 0, CU::DAYS(), -1], [0, 0, -1, 999999999, CU::DAYS(), 0], [0, 0, 86399, 0, CU::DAYS(), 0], [0, 0, 86399, 999999999, CU::DAYS(), 0], [0, 0, 86400, 0, CU::DAYS(), 1], [0, 0, 86401, 0, CU::DAYS(), 1]];
 }