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 range(ChronoField $field) { switch ($field) { case CF::PROLEPTIC_MONTH(): $range = CF::PROLEPTIC_MONTH()->range(); return ValueRange::of($range->getMinimum() + self::YEARS_DIFFERENCE * 12, $range->getMaximum() + self::YEARS_DIFFERENCE * 12); case CF::YEAR_OF_ERA(): $range = CF::YEAR()->range(); return ValueRange::ofVariable(1, -($range->getMinimum() + self::YEARS_DIFFERENCE) + 1, $range->getMaximum() + self::YEARS_DIFFERENCE); case CF::YEAR(): $range = CF::YEAR()->range(); return ValueRange::of($range->getMinimum() + self::YEARS_DIFFERENCE, $range->getMaximum() + self::YEARS_DIFFERENCE); } return $field->range(); }
public function range() { return ValueRange::ofVariable(1, 52, 53); }
public function test_range() { $this->assertEquals(CF::MONTH_OF_YEAR()->range(), ValueRange::of(1, 12)); $this->assertEquals(CF::MONTH_OF_YEAR()->rangeRefinedBy(LocalDate::of(2000, 2, 29)), ValueRange::of(1, 12)); $this->assertEquals(CF::DAY_OF_MONTH()->range(), ValueRange::ofVariable(1, 28, 31)); $this->assertEquals(CF::DAY_OF_MONTH()->rangeRefinedBy(LocalDate::of(2000, 2, 29)), ValueRange::of(1, 29)); }
public function range() { return ValueRange::ofVariable(1, 90, 92); }
/** * Gets the range of valid values for the specified field. * <p> * The range object expresses the minimum and maximum valid values for a field. * This month-day is used to enhance the accuracy of the returned range. * If it is not possible to return the range, because the field is not supported * or for some other reason, an exception is thrown. * <p> * If the field is a {@link ChronoField} then the query is implemented here. * The {@link #isSupported(TemporalField) supported fields} will return * appropriate range instances. * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. * <p> * If the field is not a {@code ChronoField}, then the result of this method * is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessor)} * passing {@code this} as the argument. * Whether the range can be obtained is determined by the field. * * @param TemporalField $field the field to query the range for, not null * @return ValueRange the range of valid values for the field, not null * @throws DateTimeException if the range for the field cannot be obtained * @throws UnsupportedTemporalTypeException if the field is not supported */ public function range(TemporalField $field) { if ($field == ChronoField::MONTH_OF_YEAR()) { return $field->range(); } else { if ($field == ChronoField::DAY_OF_MONTH()) { return ValueRange::ofVariable(1, $this->getMonth()->minLength(), $this->getMonth()->maxLength()); } } return parent::range($field); }
private static function WEEK_OF_WEEK_BASED_YEAR_RANGE() { if (self::$WEEK_OF_WEEK_BASED_YEAR_RANGE === null) { self::$WEEK_OF_WEEK_BASED_YEAR_RANGE = ValueRange::ofVariable(1, 52, 53); } return self::$WEEK_OF_WEEK_BASED_YEAR_RANGE; }