/**
  * @inheritdoc
  */
 public function isUnitSupported(TemporalUnit $unit)
 {
     if ($unit instanceof ChronoUnit) {
         return $unit != ChronoUnit::FOREVER();
     }
     return $unit != null && $unit->isSupportedBy($this);
 }
Example #2
0
 /**
  * Rata Die field.
  * <p>
  * Rata Die counts whole days continuously starting day 1 at midnight at the beginning of 0001-01-01 (ISO).
  * The field always refers to the local date-time, ignoring the offset or zone.
  * <p>
  * For date-times, 'RATA_DIE.getFrom()' assumes the same value from
  * midnight until just before the next midnight.
  * When 'RATA_DIE.adjustInto()' is applied to a date-time, the time of day portion remains unaltered.
  * 'RATA_DIE.adjustInto()' and 'RATA_DIE.getFrom()' only apply to {@code Temporal} objects
  * that can be converted into {@link ChronoField#EPOCH_DAY}.
  * An {@link UnsupportedTemporalTypeException} is thrown for any other type of object.
  * <p>
  * In the resolving phase of parsing, a date can be created from a Rata Die field.
  * In {@linkplain ResolverStyle#STRICT strict mode} and {@linkplain ResolverStyle#SMART smart mode}
  * the Rata Die value is validated against the range of valid values.
  * In {@linkplain ResolverStyle#LENIENT lenient mode} no validation occurs.
  * @return TemporalField
  */
 public static function RATA_DIE()
 {
     if (self::$RATA_DIE === null) {
         self::$RATA_DIE = new JulianField("RataDie", CU::DAYS(), CU::FOREVER(), 719163);
     }
     return self::$RATA_DIE;
 }
Example #3
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));
 }
 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);
 }
 public function test_isSupported_TemporalUnit()
 {
     //$this->assertEquals(self::TEST_200707_15_12_30_40_987654321()->isUnitSupported(null), false); TODO
     $this->assertEquals(self::TEST_200707_15_12_30_40_987654321()->isUnitSupported(CU::NANOS()), true);
     $this->assertEquals(self::TEST_200707_15_12_30_40_987654321()->isUnitSupported(CU::MICROS()), true);
     $this->assertEquals(self::TEST_200707_15_12_30_40_987654321()->isUnitSupported(CU::MILLIS()), true);
     $this->assertEquals(self::TEST_200707_15_12_30_40_987654321()->isUnitSupported(CU::SECONDS()), true);
     $this->assertEquals(self::TEST_200707_15_12_30_40_987654321()->isUnitSupported(CU::MINUTES()), true);
     $this->assertEquals(self::TEST_200707_15_12_30_40_987654321()->isUnitSupported(CU::HOURS()), true);
     $this->assertEquals(self::TEST_200707_15_12_30_40_987654321()->isUnitSupported(CU::HALF_DAYS()), true);
     $this->assertEquals(self::TEST_200707_15_12_30_40_987654321()->isUnitSupported(CU::DAYS()), true);
     $this->assertEquals(self::TEST_200707_15_12_30_40_987654321()->isUnitSupported(CU::WEEKS()), true);
     $this->assertEquals(self::TEST_200707_15_12_30_40_987654321()->isUnitSupported(CU::MONTHS()), true);
     $this->assertEquals(self::TEST_200707_15_12_30_40_987654321()->isUnitSupported(CU::YEARS()), true);
     $this->assertEquals(self::TEST_200707_15_12_30_40_987654321()->isUnitSupported(CU::DECADES()), true);
     $this->assertEquals(self::TEST_200707_15_12_30_40_987654321()->isUnitSupported(CU::CENTURIES()), true);
     $this->assertEquals(self::TEST_200707_15_12_30_40_987654321()->isUnitSupported(CU::MILLENNIA()), true);
     $this->assertEquals(self::TEST_200707_15_12_30_40_987654321()->isUnitSupported(CU::ERAS()), true);
     $this->assertEquals(self::TEST_200707_15_12_30_40_987654321()->isUnitSupported(CU::FOREVER()), false);
 }
 /**
  * @expectedException \Celest\DateTimeException
  */
 public function test_until_invalidTemporalUnit()
 {
     $odt1 = OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE());
     $odt2 = OffsetDateTime::of(2010, 6, 30, 2, 1, 1, 0, self::OFFSET_PONE());
     $odt1->until($odt2, CU::FOREVER());
 }
 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()]];
 }
 private function __construct($amount, TemporalUnit $unit)
 {
     if ($unit == CU::FOREVER()) {
         throw new DateTimeException("Cannot create a period of the Forever unit");
     }
     $this->amount = $amount;
     $this->unit = $unit;
 }
Example #9
0
 public function getRangeUnit()
 {
     return ChronoUnit::FOREVER();
 }
 public function rangeRefinedBy(TemporalAccessor $temporal)
 {
     if ($this->rangeUnit == ChronoUnit::WEEKS()) {
         // day-of-week
         return $this->range;
     } else {
         if ($this->rangeUnit == ChronoUnit::MONTHS()) {
             // week-of-month
             return $this->rangeByWeek($temporal, CF::DAY_OF_MONTH());
         } else {
             if ($this->rangeUnit == ChronoUnit::YEARS()) {
                 // week-of-year
                 return $this->rangeByWeek($temporal, CF::DAY_OF_YEAR());
             } else {
                 if ($this->rangeUnit == IsoFields::WEEK_BASED_YEARS()) {
                     return $this->rangeWeekOfWeekBasedYear($temporal);
                 } else {
                     if ($this->rangeUnit == ChronoUnit::FOREVER()) {
                         return CF::YEAR()->range();
                     } else {
                         throw new IllegalStateException("unreachable, rangeUnit: " . $this->rangeUnit . ", this: " . $this);
                     }
                 }
             }
         }
     }
 }
Example #11
0
 public function test_isSupported_TemporalUnit()
 {
     // TODO check
     //$this->assertEquals(self::$TEST_2008->isUnitSupported(null), false);
     $this->assertEquals(self::$TEST_2008->isUnitSupported(ChronoUnit::NANOS()), false);
     $this->assertEquals(self::$TEST_2008->isUnitSupported(ChronoUnit::MICROS()), false);
     $this->assertEquals(self::$TEST_2008->isUnitSupported(ChronoUnit::MILLIS()), false);
     $this->assertEquals(self::$TEST_2008->isUnitSupported(ChronoUnit::SECONDS()), false);
     $this->assertEquals(self::$TEST_2008->isUnitSupported(ChronoUnit::MINUTES()), false);
     $this->assertEquals(self::$TEST_2008->isUnitSupported(ChronoUnit::HOURS()), false);
     $this->assertEquals(self::$TEST_2008->isUnitSupported(ChronoUnit::HALF_DAYS()), false);
     $this->assertEquals(self::$TEST_2008->isUnitSupported(ChronoUnit::DAYS()), false);
     $this->assertEquals(self::$TEST_2008->isUnitSupported(ChronoUnit::WEEKS()), false);
     $this->assertEquals(self::$TEST_2008->isUnitSupported(ChronoUnit::MONTHS()), false);
     $this->assertEquals(self::$TEST_2008->isUnitSupported(ChronoUnit::YEARS()), true);
     $this->assertEquals(self::$TEST_2008->isUnitSupported(ChronoUnit::DECADES()), true);
     $this->assertEquals(self::$TEST_2008->isUnitSupported(ChronoUnit::CENTURIES()), true);
     $this->assertEquals(self::$TEST_2008->isUnitSupported(ChronoUnit::MILLENNIA()), true);
     $this->assertEquals(self::$TEST_2008->isUnitSupported(ChronoUnit::ERAS()), true);
     $this->assertEquals(self::$TEST_2008->isUnitSupported(ChronoUnit::FOREVER()), false);
 }