public function test_isSupported_TemporalUnit()
 {
     // TODO $this->assertEquals($this->TEST_DATE_TIME->isUnitSupported(null), false);
     $this->assertEquals($this->TEST_DATE_TIME->isUnitSupported(CU::NANOS()), true);
     $this->assertEquals($this->TEST_DATE_TIME->isUnitSupported(CU::MICROS()), true);
     $this->assertEquals($this->TEST_DATE_TIME->isUnitSupported(CU::MILLIS()), true);
     $this->assertEquals($this->TEST_DATE_TIME->isUnitSupported(CU::SECONDS()), true);
     $this->assertEquals($this->TEST_DATE_TIME->isUnitSupported(CU::MINUTES()), true);
     $this->assertEquals($this->TEST_DATE_TIME->isUnitSupported(CU::HOURS()), true);
     $this->assertEquals($this->TEST_DATE_TIME->isUnitSupported(CU::HALF_DAYS()), true);
     $this->assertEquals($this->TEST_DATE_TIME->isUnitSupported(CU::DAYS()), true);
     $this->assertEquals($this->TEST_DATE_TIME->isUnitSupported(CU::WEEKS()), true);
     $this->assertEquals($this->TEST_DATE_TIME->isUnitSupported(CU::MONTHS()), true);
     $this->assertEquals($this->TEST_DATE_TIME->isUnitSupported(CU::YEARS()), true);
     $this->assertEquals($this->TEST_DATE_TIME->isUnitSupported(CU::DECADES()), true);
     $this->assertEquals($this->TEST_DATE_TIME->isUnitSupported(CU::CENTURIES()), true);
     $this->assertEquals($this->TEST_DATE_TIME->isUnitSupported(CU::MILLENNIA()), true);
     $this->assertEquals($this->TEST_DATE_TIME->isUnitSupported(CU::ERAS()), true);
     $this->assertEquals($this->TEST_DATE_TIME->isUnitSupported(CU::FOREVER()), false);
 }
예제 #2
0
 /**
  * Calculates the amount of time until another date in terms of the specified unit.
  * <p>
  * This calculates the amount of time between two {@code LocalDate}
  * objects in terms of a single {@code TemporalUnit}.
  * The start and end points are {@code this} and the specified date.
  * The result will be negative if the end is before the start.
  * The {@code Temporal} passed to this method is converted to a
  * {@code LocalDate} using {@link #from(TemporalAccessor)}.
  * For example, the amount in days between two dates can be calculated
  * using {@code startDate.until(endDate, DAYS)}.
  * <p>
  * The calculation returns a whole number, representing the number of
  * complete units between the two dates.
  * For example, the amount in months between 2012-06-15 and 2012-08-14
  * will only be one month as it is one day 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 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 LocalDate}, not null
  * @param TemporalUnit $unit the unit to measure the amount in, not null
  * @return int the amount of time between this date and the end date
  * @throws DateTimeException if the amount cannot be calculated, or the end
  *  temporal cannot be converted to a {@code LocalDate}
  * @throws UnsupportedTemporalTypeException if the unit is not supported
  * @throws ArithmeticException if numeric overflow occurs
  */
 public function until(Temporal $endExclusive, TemporalUnit $unit)
 {
     $end = LocalDate::from($endExclusive);
     if ($unit instanceof ChronoUnit) {
         switch ($unit) {
             case ChronoUnit::DAYS():
                 return $this->daysUntil($end);
             case ChronoUnit::WEEKS():
                 return Math::div($this->daysUntil($end), 7);
             case ChronoUnit::MONTHS():
                 return $this->monthsUntil($end);
             case ChronoUnit::YEARS():
                 return Math::div($this->monthsUntil($end), 12);
             case ChronoUnit::DECADES():
                 return Math::div($this->monthsUntil($end), 120);
             case ChronoUnit::CENTURIES():
                 return Math::div($this->monthsUntil($end), 1200);
             case ChronoUnit::MILLENNIA():
                 return Math::div($this->monthsUntil($end), 12000);
             case ChronoUnit::ERAS():
                 return $end->getLong(ChronoField::ERA()) - $this->getLong(ChronoField::ERA());
         }
         throw new UnsupportedTemporalTypeException("Unsupported unit: " . $unit);
     }
     return $unit->between($this, $end);
 }
예제 #3
0
 function data_periodUntilUnit()
 {
     return [[$this->ym(2000, 1), $this->ym(-1, 12), CU::MONTHS(), -2000 * 12 - 1], [$this->ym(2000, 1), $this->ym(0, 1), CU::MONTHS(), -2000 * 12], [$this->ym(2000, 1), $this->ym(0, 12), CU::MONTHS(), -1999 * 12 - 1], [$this->ym(2000, 1), $this->ym(1, 1), CU::MONTHS(), -1999 * 12], [$this->ym(2000, 1), $this->ym(1999, 12), CU::MONTHS(), -1], [$this->ym(2000, 1), $this->ym(2000, 1), CU::MONTHS(), 0], [$this->ym(2000, 1), $this->ym(2000, 2), CU::MONTHS(), 1], [$this->ym(2000, 1), $this->ym(2000, 3), CU::MONTHS(), 2], [$this->ym(2000, 1), $this->ym(2000, 12), CU::MONTHS(), 11], [$this->ym(2000, 1), $this->ym(2001, 1), CU::MONTHS(), 12], [$this->ym(2000, 1), $this->ym(2246, 5), CU::MONTHS(), 246 * 12 + 4], [$this->ym(2000, 1), $this->ym(-1, 12), CU::YEARS(), -2000], [$this->ym(2000, 1), $this->ym(0, 1), CU::YEARS(), -2000], [$this->ym(2000, 1), $this->ym(0, 12), CU::YEARS(), -1999], [$this->ym(2000, 1), $this->ym(1, 1), CU::YEARS(), -1999], [$this->ym(2000, 1), $this->ym(1998, 12), CU::YEARS(), -1], [$this->ym(2000, 1), $this->ym(1999, 1), CU::YEARS(), -1], [$this->ym(2000, 1), $this->ym(1999, 2), CU::YEARS(), 0], [$this->ym(2000, 1), $this->ym(1999, 12), CU::YEARS(), 0], [$this->ym(2000, 1), $this->ym(2000, 1), CU::YEARS(), 0], [$this->ym(2000, 1), $this->ym(2000, 2), CU::YEARS(), 0], [$this->ym(2000, 1), $this->ym(2000, 12), CU::YEARS(), 0], [$this->ym(2000, 1), $this->ym(2001, 1), CU::YEARS(), 1], [$this->ym(2000, 1), $this->ym(2246, 5), CU::YEARS(), 246], [$this->ym(2000, 5), $this->ym(-1, 5), CU::DECADES(), -200], [$this->ym(2000, 5), $this->ym(0, 4), CU::DECADES(), -200], [$this->ym(2000, 5), $this->ym(0, 5), CU::DECADES(), -200], [$this->ym(2000, 5), $this->ym(0, 6), CU::DECADES(), -199], [$this->ym(2000, 5), $this->ym(1, 5), CU::DECADES(), -199], [$this->ym(2000, 5), $this->ym(1990, 4), CU::DECADES(), -1], [$this->ym(2000, 5), $this->ym(1990, 5), CU::DECADES(), -1], [$this->ym(2000, 5), $this->ym(1990, 6), CU::DECADES(), 0], [$this->ym(2000, 5), $this->ym(2000, 4), CU::DECADES(), 0], [$this->ym(2000, 5), $this->ym(2000, 5), CU::DECADES(), 0], [$this->ym(2000, 5), $this->ym(2000, 6), CU::DECADES(), 0], [$this->ym(2000, 5), $this->ym(2010, 4), CU::DECADES(), 0], [$this->ym(2000, 5), $this->ym(2010, 5), CU::DECADES(), 1], [$this->ym(2000, 5), $this->ym(2010, 6), CU::DECADES(), 1], [$this->ym(2000, 5), $this->ym(-1, 5), CU::CENTURIES(), -20], [$this->ym(2000, 5), $this->ym(0, 4), CU::CENTURIES(), -20], [$this->ym(2000, 5), $this->ym(0, 5), CU::CENTURIES(), -20], [$this->ym(2000, 5), $this->ym(0, 6), CU::CENTURIES(), -19], [$this->ym(2000, 5), $this->ym(1, 5), CU::CENTURIES(), -19], [$this->ym(2000, 5), $this->ym(1900, 4), CU::CENTURIES(), -1], [$this->ym(2000, 5), $this->ym(1900, 5), CU::CENTURIES(), -1], [$this->ym(2000, 5), $this->ym(1900, 6), CU::CENTURIES(), 0], [$this->ym(2000, 5), $this->ym(2000, 4), CU::CENTURIES(), 0], [$this->ym(2000, 5), $this->ym(2000, 5), CU::CENTURIES(), 0], [$this->ym(2000, 5), $this->ym(2000, 6), CU::CENTURIES(), 0], [$this->ym(2000, 5), $this->ym(2100, 4), CU::CENTURIES(), 0], [$this->ym(2000, 5), $this->ym(2100, 5), CU::CENTURIES(), 1], [$this->ym(2000, 5), $this->ym(2100, 6), CU::CENTURIES(), 1], [$this->ym(2000, 5), $this->ym(-1, 5), CU::MILLENNIA(), -2], [$this->ym(2000, 5), $this->ym(0, 4), CU::MILLENNIA(), -2], [$this->ym(2000, 5), $this->ym(0, 5), CU::MILLENNIA(), -2], [$this->ym(2000, 5), $this->ym(0, 6), CU::MILLENNIA(), -1], [$this->ym(2000, 5), $this->ym(1, 5), CU::MILLENNIA(), -1], [$this->ym(2000, 5), $this->ym(1000, 4), CU::MILLENNIA(), -1], [$this->ym(2000, 5), $this->ym(1000, 5), CU::MILLENNIA(), -1], [$this->ym(2000, 5), $this->ym(1000, 6), CU::MILLENNIA(), 0], [$this->ym(2000, 5), $this->ym(2000, 4), CU::MILLENNIA(), 0], [$this->ym(2000, 5), $this->ym(2000, 5), CU::MILLENNIA(), 0], [$this->ym(2000, 5), $this->ym(2000, 6), CU::MILLENNIA(), 0], [$this->ym(2000, 5), $this->ym(3000, 4), CU::MILLENNIA(), 0], [$this->ym(2000, 5), $this->ym(3000, 5), CU::MILLENNIA(), 1], [$this->ym(2000, 5), $this->ym(3000, 5), CU::MILLENNIA(), 1]];
 }
 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]];
 }
예제 #5
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()]];
 }
예제 #6
0
 public function until(Temporal $endExclusive, TemporalUnit $unit)
 {
     $end = $this->getChronology()->dateFrom($endExclusive);
     if ($unit instanceof ChronoUnit) {
         switch ($unit) {
             case CU::DAYS():
                 return $this->daysUntil($end);
             case CU::WEEKS():
                 return $this->daysUntil($end) / 7;
             case CU::MONTHS():
                 return $this->monthsUntil($end);
             case CU::YEARS():
                 return $this->monthsUntil($end) / 12;
             case CU::DECADES():
                 return $this->monthsUntil($end) / 120;
             case CU::CENTURIES():
                 return $this->monthsUntil($end) / 1200;
             case CU::MILLENNIA():
                 return $this->monthsUntil($end) / 12000;
             case CU::ERAS():
                 return $end->getLong(CF::ERA()) - $this->getLong(CF::ERA());
         }
         throw new UnsupportedTemporalTypeException("Unsupported unit: " . $unit);
     }
     return $unit->between($this, $end);
 }
예제 #7
0
 /**
  * Calculates the amount of time until another year in terms of the specified unit.
  * <p>
  * This calculates the amount of time between two {@code Year}
  * objects in terms of a single {@code TemporalUnit}.
  * The start and end points are {@code this} and the specified year.
  * The result will be negative if the end is before the start.
  * The {@code Temporal} passed to this method is converted to a
  * {@code Year} using {@link #from(TemporalAccessor)}.
  * For example, the amount in decades between two year can be calculated
  * using {@code startYear.until(endYear, DECADES)}.
  * <p>
  * The calculation returns a whole number, representing the number of
  * complete units between the two years.
  * For example, the amount in decades between 2012 and 2031
  * will only be one decade as it is one year short of two decades.
  * <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, YEARS);
  *   amount = YEARS.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 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 Year}, not null
  * @param TemporalUnit $unit the unit to measure the amount in, not null
  * @return int the amount of time between this year and the end year
  * @throws DateTimeException if the amount cannot be calculated, or the end
  *  temporal cannot be converted to a {@code Year}
  * @throws UnsupportedTemporalTypeException if the unit is not supported
  * @throws ArithmeticException if numeric overflow occurs
  */
 public function until(Temporal $endExclusive, TemporalUnit $unit)
 {
     $end = Year::from($endExclusive);
     if ($unit instanceof ChronoUnit) {
         $yearsUntil = $end->year - $this->year;
         // no overflow
         switch ($unit) {
             case ChronoUnit::YEARS():
                 return $yearsUntil;
             case ChronoUnit::DECADES():
                 return Math::div($yearsUntil, 10);
             case ChronoUnit::CENTURIES():
                 return Math::div($yearsUntil, 100);
             case ChronoUnit::MILLENNIA():
                 return Math::div($yearsUntil, 1000);
             case ChronoUnit::ERAS():
                 return $end->getLong(ChronoField::ERA()) - $this->getLong(ChronoField::ERA());
         }
         throw new UnsupportedTemporalTypeException("Unsupported unit: " . $unit);
     }
     return $unit->between($this, $end);
 }
 public function test_isSupported_TemporalUnit()
 {
     //$this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->isSupported((TemporalUnit) null), false); TODO
     $this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->isUnitSupported(CU::NANOS()), true);
     $this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->isUnitSupported(CU::MICROS()), true);
     $this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->isUnitSupported(CU::MILLIS()), true);
     $this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->isUnitSupported(CU::SECONDS()), true);
     $this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->isUnitSupported(CU::MINUTES()), true);
     $this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->isUnitSupported(CU::HOURS()), true);
     $this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->isUnitSupported(CU::HALF_DAYS()), true);
     $this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->isUnitSupported(CU::DAYS()), true);
     $this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->isUnitSupported(CU::WEEKS()), true);
     $this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->isUnitSupported(CU::MONTHS()), true);
     $this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->isUnitSupported(CU::YEARS()), true);
     $this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->isUnitSupported(CU::DECADES()), true);
     $this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->isUnitSupported(CU::CENTURIES()), true);
     $this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->isUnitSupported(CU::MILLENNIA()), true);
     $this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->isUnitSupported(CU::ERAS()), true);
     $this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->isUnitSupported(CU::FOREVER()), false);
 }
예제 #9
0
 function data_periodUntilUnit()
 {
     return [[$this->date(2000, 1, 1), $this->date(2000, 1, 1), CU::DAYS(), 0], [$this->date(2000, 1, 1), $this->date(2000, 1, 1), CU::WEEKS(), 0], [$this->date(2000, 1, 1), $this->date(2000, 1, 1), CU::MONTHS(), 0], [$this->date(2000, 1, 1), $this->date(2000, 1, 1), CU::YEARS(), 0], [$this->date(2000, 1, 1), $this->date(2000, 1, 1), CU::DECADES(), 0], [$this->date(2000, 1, 1), $this->date(2000, 1, 1), CU::CENTURIES(), 0], [$this->date(2000, 1, 1), $this->date(2000, 1, 1), CU::MILLENNIA(), 0], [$this->date(2000, 1, 15), $this->date(2000, 2, 14), CU::DAYS(), 30], [$this->date(2000, 1, 15), $this->date(2000, 2, 15), CU::DAYS(), 31], [$this->date(2000, 1, 15), $this->date(2000, 2, 16), CU::DAYS(), 32], [$this->date(2000, 1, 15), $this->date(2000, 2, 17), CU::WEEKS(), 4], [$this->date(2000, 1, 15), $this->date(2000, 2, 18), CU::WEEKS(), 4], [$this->date(2000, 1, 15), $this->date(2000, 2, 19), CU::WEEKS(), 5], [$this->date(2000, 1, 15), $this->date(2000, 2, 20), CU::WEEKS(), 5], [$this->date(2000, 1, 15), $this->date(2000, 2, 14), CU::MONTHS(), 0], [$this->date(2000, 1, 15), $this->date(2000, 2, 15), CU::MONTHS(), 1], [$this->date(2000, 1, 15), $this->date(2000, 2, 16), CU::MONTHS(), 1], [$this->date(2000, 1, 15), $this->date(2000, 3, 14), CU::MONTHS(), 1], [$this->date(2000, 1, 15), $this->date(2000, 3, 15), CU::MONTHS(), 2], [$this->date(2000, 1, 15), $this->date(2000, 3, 16), CU::MONTHS(), 2], [$this->date(2000, 1, 15), $this->date(2001, 1, 14), CU::YEARS(), 0], [$this->date(2000, 1, 15), $this->date(2001, 1, 15), CU::YEARS(), 1], [$this->date(2000, 1, 15), $this->date(2001, 1, 16), CU::YEARS(), 1], [$this->date(2000, 1, 15), $this->date(2004, 1, 14), CU::YEARS(), 3], [$this->date(2000, 1, 15), $this->date(2004, 1, 15), CU::YEARS(), 4], [$this->date(2000, 1, 15), $this->date(2004, 1, 16), CU::YEARS(), 4], [$this->date(2000, 1, 15), $this->date(2010, 1, 14), CU::DECADES(), 0], [$this->date(2000, 1, 15), $this->date(2010, 1, 15), CU::DECADES(), 1], [$this->date(2000, 1, 15), $this->date(2100, 1, 14), CU::CENTURIES(), 0], [$this->date(2000, 1, 15), $this->date(2100, 1, 15), CU::CENTURIES(), 1], [$this->date(2000, 1, 15), $this->date(3000, 1, 14), CU::MILLENNIA(), 0], [$this->date(2000, 1, 15), $this->date(3000, 1, 15), CU::MILLENNIA(), 1]];
 }
예제 #10
0
 function data_badTemporalUnit()
 {
     return [[CU::MICROS()], [CU::MILLIS()], [CU::HALF_DAYS()], [CU::DECADES()], [CU::CENTURIES()], [CU::MILLENNIA()]];
 }
예제 #11
0
 function data_periodUntilUnit()
 {
     return [[Year::of(2000), Year::of(-1), ChronoUnit::YEARS(), -2001], [Year::of(2000), Year::of(0), ChronoUnit::YEARS(), -2000], [Year::of(2000), Year::of(1), ChronoUnit::YEARS(), -1999], [Year::of(2000), Year::of(1998), ChronoUnit::YEARS(), -2], [Year::of(2000), Year::of(1999), ChronoUnit::YEARS(), -1], [Year::of(2000), Year::of(2000), ChronoUnit::YEARS(), 0], [Year::of(2000), Year::of(2001), ChronoUnit::YEARS(), 1], [Year::of(2000), Year::of(2002), ChronoUnit::YEARS(), 2], [Year::of(2000), Year::of(2246), ChronoUnit::YEARS(), 246], [Year::of(2000), Year::of(-1), ChronoUnit::DECADES(), -200], [Year::of(2000), Year::of(0), ChronoUnit::DECADES(), -200], [Year::of(2000), Year::of(1), ChronoUnit::DECADES(), -199], [Year::of(2000), Year::of(1989), ChronoUnit::DECADES(), -1], [Year::of(2000), Year::of(1990), ChronoUnit::DECADES(), -1], [Year::of(2000), Year::of(1991), ChronoUnit::DECADES(), 0], [Year::of(2000), Year::of(2000), ChronoUnit::DECADES(), 0], [Year::of(2000), Year::of(2009), ChronoUnit::DECADES(), 0], [Year::of(2000), Year::of(2010), ChronoUnit::DECADES(), 1], [Year::of(2000), Year::of(2011), ChronoUnit::DECADES(), 1], [Year::of(2000), Year::of(-1), ChronoUnit::CENTURIES(), -20], [Year::of(2000), Year::of(0), ChronoUnit::CENTURIES(), -20], [Year::of(2000), Year::of(1), ChronoUnit::CENTURIES(), -19], [Year::of(2000), Year::of(1899), ChronoUnit::CENTURIES(), -1], [Year::of(2000), Year::of(1900), ChronoUnit::CENTURIES(), -1], [Year::of(2000), Year::of(1901), ChronoUnit::CENTURIES(), 0], [Year::of(2000), Year::of(2000), ChronoUnit::CENTURIES(), 0], [Year::of(2000), Year::of(2099), ChronoUnit::CENTURIES(), 0], [Year::of(2000), Year::of(2100), ChronoUnit::CENTURIES(), 1], [Year::of(2000), Year::of(2101), ChronoUnit::CENTURIES(), 1], [Year::of(2000), Year::of(-1), ChronoUnit::MILLENNIA(), -2], [Year::of(2000), Year::of(0), ChronoUnit::MILLENNIA(), -2], [Year::of(2000), Year::of(1), ChronoUnit::MILLENNIA(), -1], [Year::of(2000), Year::of(999), ChronoUnit::MILLENNIA(), -1], [Year::of(2000), Year::of(1000), ChronoUnit::MILLENNIA(), -1], [Year::of(2000), Year::of(1001), ChronoUnit::MILLENNIA(), 0], [Year::of(2000), Year::of(2000), ChronoUnit::MILLENNIA(), 0], [Year::of(2000), Year::of(2999), ChronoUnit::MILLENNIA(), 0], [Year::of(2000), Year::of(3000), ChronoUnit::MILLENNIA(), 1], [Year::of(2000), Year::of(3001), ChronoUnit::MILLENNIA(), 1]];
 }