public function adjustInto(Temporal $temporal, $newValue)
 {
     if ($this->isSupportedBy($temporal) === false) {
         throw new UnsupportedTemporalTypeException("Unsupported field: WeekBasedYear");
     }
     $newWby = $this->range()->checkValidIntValue($newValue, IsoFields::WEEK_BASED_YEAR());
     // strict check
     $date = LocalDate::from($temporal);
     $dow = $date->get(ChronoField::DAY_OF_WEEK());
     $week = IsoFields::getWeek($date);
     if ($week == 53 && IsoFields::getWeekRangeInt($newWby) == 52) {
         $week = 52;
     }
     $resolved = LocalDate::of($newWby, 1, 4);
     // 4th is guaranteed to be in week one
     $days = $dow - $resolved->get(ChronoField::DAY_OF_WEEK()) + ($week - 1) * 7;
     $resolved = $resolved->plusDays($days);
     return $temporal->adjust($resolved);
 }
Beispiel #2
0
 public function resolve(FieldValues $fieldValues, TemporalAccessor $partialTemporal, ResolverStyle $resolverStyle)
 {
     $yearLong = $fieldValues->get(ChronoField::YEAR());
     $qoyLong = $fieldValues->get(IsoFields::QUARTER_OF_YEAR());
     if ($yearLong === null || $qoyLong === null) {
         return null;
     }
     $y = ChronoField::YEAR()->checkValidIntValue($yearLong);
     // always validate
     $doq = $fieldValues->get(IsoFields::DAY_OF_QUARTER());
     IsoFields::ensureIso($partialTemporal);
     if ($resolverStyle == ResolverStyle::LENIENT()) {
         $date = LocalDate::of($y, 1, 1)->plusMonths(Math::multiplyExact(Math::subtractExact($qoyLong, 1), 3));
         $doq = Math::subtractExact($doq, 1);
     } else {
         $qoy = IsoFields::QUARTER_OF_YEAR()->range()->checkValidIntValue($qoyLong, IsoFields::QUARTER_OF_YEAR());
         // validated
         $date = LocalDate::of($y, ($qoy - 1) * 3 + 1, 1);
         if ($doq < 1 || $doq > 90) {
             if ($resolverStyle == ResolverStyle::STRICT()) {
                 $this->rangeRefinedBy($date)->checkValidValue($doq, $this);
                 // only allow exact range
             } else {
                 // SMART
                 $this->range()->checkValidValue($doq, $this);
                 // allow 1-92 rolling into next quarter
             }
         }
         $doq--;
     }
     $fieldValues->remove($this);
     $fieldValues->remove(ChronoField::YEAR());
     $fieldValues->remove(IsoFields::QUARTER_OF_YEAR());
     return $date->plusDays($doq);
 }
 /**
  * @group long
  */
 public function test_loop()
 {
     // loop round at least one 400 $year cycle, including before 1970
     $date = LocalDate::of(1960, 1, 5);
     // Tuseday of $week 1 1960
     $year = 1960;
     $wby = 1960;
     $weekLen = 52;
     $week = 1;
     while ($date->getYear() < 2400) {
         $loopDow = $date->getDayOfWeek();
         if ($date->getYear() != $year) {
             $year = $date->getYear();
         }
         if ($loopDow == DayOfWeek::MONDAY()) {
             $week++;
             if ($week == 53 && $weekLen == 52 || $week == 54) {
                 $week = 1;
                 $firstDayOfWeekBasedYear = $date->plusDays(14)->withDayOfYear(1);
                 $firstDay = $firstDayOfWeekBasedYear->getDayOfWeek();
                 $weekLen = $firstDay == DayOfWeek::THURSDAY() || $firstDay == DayOfWeek::WEDNESDAY() && $firstDayOfWeekBasedYear->isLeapYear() ? 53 : 52;
                 $wby++;
             }
         }
         $this->assertEquals(IsoFields::WEEK_OF_WEEK_BASED_YEAR()->rangeRefinedBy($date), ValueRange::of(1, $weekLen), "Failed on " . $date . " " . $date->getDayOfWeek());
         $this->assertEquals(IsoFields::WEEK_OF_WEEK_BASED_YEAR()->getFrom($date), $week, "Failed on " . $date . " " . $date->getDayOfWeek());
         $this->assertEquals($date->get(IsoFields::WEEK_OF_WEEK_BASED_YEAR()), $week, "Failed on " . $date . " " . $date->getDayOfWeek());
         $this->assertEquals(IsoFields::WEEK_BASED_YEAR()->getFrom($date), $wby, "Failed on " . $date . " " . $date->getDayOfWeek());
         $this->assertEquals($date->get(IsoFields::WEEK_BASED_YEAR()), $wby, "Failed on " . $date . " " . $date->getDayOfWeek());
         $date = $date->plusDays(1);
     }
 }
 public static function ISO_WEEK_DATE()
 {
     return self::$ISO_WEEK_DATE = (new DateTimeFormatterBuilder())->parseCaseInsensitive()->appendValue3(IsoFields::WEEK_BASED_YEAR(), 4, 10, SignStyle::EXCEEDS_PAD())->appendLiteral2("-W")->appendValue2(IsoFields::WEEK_OF_WEEK_BASED_YEAR(), 2)->appendLiteral('-')->appendValue2(ChronoField::DAY_OF_WEEK(), 1)->optionalStart()->appendOffsetId()->toFormatter3(ResolverStyle::STRICT(), IsoChronology::INSTANCE());
 }
 function provider_dow()
 {
     return [[ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 1, "Monday"], [ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 2, "Tuesday"], [ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 3, "Wednesday"], [ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 4, "Thursday"], [ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 5, "Friday"], [ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 6, "Saturday"], [ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 7, "Sunday"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 1, "Mon"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 2, "Tue"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 3, "Wed"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 4, "Thu"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 5, "Fri"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 6, "Sat"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 7, "Sun"], [ChronoField::DAY_OF_WEEK(), TextStyle::NARROW(), 1, "M"], [ChronoField::DAY_OF_WEEK(), TextStyle::NARROW(), 2, "T"], [ChronoField::DAY_OF_WEEK(), TextStyle::NARROW(), 3, "W"], [ChronoField::DAY_OF_WEEK(), TextStyle::NARROW(), 4, "T"], [ChronoField::DAY_OF_WEEK(), TextStyle::NARROW(), 5, "F"], [ChronoField::DAY_OF_WEEK(), TextStyle::NARROW(), 6, "S"], [ChronoField::DAY_OF_WEEK(), TextStyle::NARROW(), 7, "S"], [ChronoField::DAY_OF_MONTH(), TextStyle::FULL(), 1, "1"], [ChronoField::DAY_OF_MONTH(), TextStyle::FULL(), 2, "2"], [ChronoField::DAY_OF_MONTH(), TextStyle::FULL(), 3, "3"], [ChronoField::DAY_OF_MONTH(), TextStyle::FULL(), 28, "28"], [ChronoField::DAY_OF_MONTH(), TextStyle::FULL(), 29, "29"], [ChronoField::DAY_OF_MONTH(), TextStyle::FULL(), 30, "30"], [ChronoField::DAY_OF_MONTH(), TextStyle::FULL(), 31, "31"], [ChronoField::DAY_OF_MONTH(), TextStyle::SHORT(), 1, "1"], [ChronoField::DAY_OF_MONTH(), TextStyle::SHORT(), 2, "2"], [ChronoField::DAY_OF_MONTH(), TextStyle::SHORT(), 3, "3"], [ChronoField::DAY_OF_MONTH(), TextStyle::SHORT(), 28, "28"], [ChronoField::DAY_OF_MONTH(), TextStyle::SHORT(), 29, "29"], [ChronoField::DAY_OF_MONTH(), TextStyle::SHORT(), 30, "30"], [ChronoField::DAY_OF_MONTH(), TextStyle::SHORT(), 31, "31"], [ChronoField::MONTH_OF_YEAR(), TextStyle::FULL(), 1, "January"], [ChronoField::MONTH_OF_YEAR(), TextStyle::FULL(), 2, "February"], [ChronoField::MONTH_OF_YEAR(), TextStyle::FULL(), 3, "March"], [ChronoField::MONTH_OF_YEAR(), TextStyle::FULL(), 4, "April"], [ChronoField::MONTH_OF_YEAR(), TextStyle::FULL(), 5, "May"], [ChronoField::MONTH_OF_YEAR(), TextStyle::FULL(), 6, "June"], [ChronoField::MONTH_OF_YEAR(), TextStyle::FULL(), 7, "July"], [ChronoField::MONTH_OF_YEAR(), TextStyle::FULL(), 8, "August"], [ChronoField::MONTH_OF_YEAR(), TextStyle::FULL(), 9, "September"], [ChronoField::MONTH_OF_YEAR(), TextStyle::FULL(), 10, "October"], [ChronoField::MONTH_OF_YEAR(), TextStyle::FULL(), 11, "November"], [ChronoField::MONTH_OF_YEAR(), TextStyle::FULL(), 12, "December"], [ChronoField::MONTH_OF_YEAR(), TextStyle::SHORT(), 1, "Jan"], [ChronoField::MONTH_OF_YEAR(), TextStyle::SHORT(), 2, "Feb"], [ChronoField::MONTH_OF_YEAR(), TextStyle::SHORT(), 3, "Mar"], [ChronoField::MONTH_OF_YEAR(), TextStyle::SHORT(), 4, "Apr"], [ChronoField::MONTH_OF_YEAR(), TextStyle::SHORT(), 5, "May"], [ChronoField::MONTH_OF_YEAR(), TextStyle::SHORT(), 6, "Jun"], [ChronoField::MONTH_OF_YEAR(), TextStyle::SHORT(), 7, "Jul"], [ChronoField::MONTH_OF_YEAR(), TextStyle::SHORT(), 8, "Aug"], [ChronoField::MONTH_OF_YEAR(), TextStyle::SHORT(), 9, "Sep"], [ChronoField::MONTH_OF_YEAR(), TextStyle::SHORT(), 10, "Oct"], [ChronoField::MONTH_OF_YEAR(), TextStyle::SHORT(), 11, "Nov"], [ChronoField::MONTH_OF_YEAR(), TextStyle::SHORT(), 12, "Dec"], [ChronoField::MONTH_OF_YEAR(), TextStyle::NARROW(), 1, "J"], [ChronoField::MONTH_OF_YEAR(), TextStyle::NARROW(), 2, "F"], [ChronoField::MONTH_OF_YEAR(), TextStyle::NARROW(), 3, "M"], [ChronoField::MONTH_OF_YEAR(), TextStyle::NARROW(), 4, "A"], [ChronoField::MONTH_OF_YEAR(), TextStyle::NARROW(), 5, "M"], [ChronoField::MONTH_OF_YEAR(), TextStyle::NARROW(), 6, "J"], [ChronoField::MONTH_OF_YEAR(), TextStyle::NARROW(), 7, "J"], [ChronoField::MONTH_OF_YEAR(), TextStyle::NARROW(), 8, "A"], [ChronoField::MONTH_OF_YEAR(), TextStyle::NARROW(), 9, "S"], [ChronoField::MONTH_OF_YEAR(), TextStyle::NARROW(), 10, "O"], [ChronoField::MONTH_OF_YEAR(), TextStyle::NARROW(), 11, "N"], [ChronoField::MONTH_OF_YEAR(), TextStyle::NARROW(), 12, "D"], [ChronoField::ERA(), TextStyle::FULL(), 0, "Before Christ"], [ChronoField::ERA(), TextStyle::FULL(), 1, "Anno Domini"], [ChronoField::ERA(), TextStyle::SHORT(), 0, "BC"], [ChronoField::ERA(), TextStyle::SHORT(), 1, "AD"], [ChronoField::ERA(), TextStyle::NARROW(), 0, "B"], [ChronoField::ERA(), TextStyle::NARROW(), 1, "A"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::FULL(), 1, "1st quarter"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::FULL(), 2, "2nd quarter"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::FULL(), 3, "3rd quarter"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::FULL(), 4, "4th quarter"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::SHORT(), 1, "Q1"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::SHORT(), 2, "Q2"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::SHORT(), 3, "Q3"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::SHORT(), 4, "Q4"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::NARROW(), 1, "1"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::NARROW(), 2, "2"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::NARROW(), 3, "3"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::NARROW(), 4, "4"]];
 }
 public function test_nullLocaleTemporalFieldDisplayName()
 {
     TestHelper::assertNullException($this, function () {
         // Test the default method in TemporalField using the
         // IsoFields.DAY_OF_QUARTER which does not override getDisplayName
         IsoFields::DAY_OF_QUARTER()->getDisplayName(null);
     });
 }
Beispiel #7
0
 /**
  * The unit that represents week-based-years for the purpose of addition and subtraction.
  * <p>
  * This allows a number of week-based-years to be added to, or subtracted from, a date.
  * The unit is equal to either 52 or 53 weeks.
  * The estimated duration of a week-based-year is the same as that of a standard ISO
  * year at {@code 365.2425 Days}.
  * <p>
  * The rules for addition add the number of week-based-years to the existing value
  * for the week-based-year field retaining the week-of-week-based-year
  * and day-of-week, unless the week number it too large for the target year.
  * In that case, the week is set to the last week of the year
  * with the same day-of-week.
  * <p>
  * This unit is an immutable and thread-safe singleton.
  * @return TemporalUnit
  */
 public static function WEEK_BASED_YEARS()
 {
     return IsoFields::WEEK_BASED_YEAR();
 }
 public static function init()
 {
     self::$FIELD_MAP = ['G' => ChronoField::ERA(), 'y' => ChronoField::YEAR_OF_ERA(), 'u' => ChronoField::YEAR(), 'Q' => IsoFields::QUARTER_OF_YEAR(), 'q' => IsoFields::QUARTER_OF_YEAR(), 'M' => ChronoField::MONTH_OF_YEAR(), 'L' => ChronoField::MONTH_OF_YEAR(), 'D' => ChronoField::DAY_OF_YEAR(), 'd' => ChronoField::DAY_OF_MONTH(), 'F' => ChronoField::ALIGNED_DAY_OF_WEEK_IN_MONTH(), 'E' => ChronoField::DAY_OF_WEEK(), 'c' => ChronoField::DAY_OF_WEEK(), 'e' => ChronoField::DAY_OF_WEEK(), 'a' => ChronoField::AMPM_OF_DAY(), 'H' => ChronoField::HOUR_OF_DAY(), 'k' => ChronoField::CLOCK_HOUR_OF_DAY(), 'K' => ChronoField::HOUR_OF_AMPM(), 'h' => ChronoField::CLOCK_HOUR_OF_AMPM(), 'm' => ChronoField::MINUTE_OF_HOUR(), 's' => ChronoField::SECOND_OF_MINUTE(), 'S' => ChronoField::NANO_OF_SECOND(), 'A' => ChronoField::MILLI_OF_DAY(), 'n' => ChronoField::NANO_OF_SECOND(), 'N' => ChronoField::NANO_OF_DAY()];
 }
 /**
  * Gets an iterator of text to field for the specified field, locale and style
  * for the purpose of parsing.
  * <p>
  * The iterator must be returned in order from the longest text to the shortest.
  * <p>
  * The null return value should be used if there is no applicable parsable text, or
  * if the text would be a numeric representation of the value.
  * Text can only be parsed if all the values for that field-style-locale combination are unique.
  *
  * @param TemporalField $field the field to get text for, not null
  * @param TextStyle $style the style to get text for, null for all parsable text
  * @param Locale $locale the locale to get text for, not null
  * @return array the iterator of text to field pairs, in order from longest text to shortest text,
  *  null if the field or style is not parsable
  */
 public function getTextIterator(TemporalField $field, $style, Locale $locale)
 {
     $values = null;
     if ($field == ChronoField::DAY_OF_WEEK()) {
         $values = self::tryFetchStyleValues('dayNames', $style, $locale, function ($i) {
             return $i === 0 ? 7 : $i;
         });
     }
     if ($field == ChronoField::MONTH_OF_YEAR()) {
         $values = self::tryFetchStyleValues('monthNames', $style, $locale, function ($i) {
             return $i + 1;
         });
     }
     if ($field == IsoFields::QUARTER_OF_YEAR()) {
         $values = self::tryFetchStyleValues('quarters', $style, $locale, function ($i) {
             return $i + 1;
         });
     }
     if ($field == ChronoField::AMPM_OF_DAY()) {
         $values = self::tryFetchStyleValues('AmPmMarkers', $style, $locale, function ($i) {
             return $i;
         });
     }
     if ($values === null) {
         return null;
     }
     \uksort($values, function ($a, $b) {
         return strlen($b) - strlen($a);
     });
     return $values;
 }
 function data_resolveThreeNoChange()
 {
     return [[ChronoField::YEAR(), 2012, ChronoField::MONTH_OF_YEAR(), 5, ChronoField::DAY_OF_WEEK(), 5], [ChronoField::YEAR(), 2012, ChronoField::ALIGNED_WEEK_OF_YEAR(), 5, ChronoField::DAY_OF_MONTH(), 5], [ChronoField::YEAR(), 2012, ChronoField::ALIGNED_WEEK_OF_MONTH(), 5, ChronoField::DAY_OF_MONTH(), 5], [ChronoField::YEAR(), 2012, ChronoField::MONTH_OF_YEAR(), 5, ChronoField::DAY_OF_WEEK(), 5], [ChronoField::ERA(), 1, ChronoField::MONTH_OF_YEAR(), 5, ChronoField::DAY_OF_MONTH(), 5], [ChronoField::MONTH_OF_YEAR(), 1, ChronoField::DAY_OF_MONTH(), 5, IsoFields::QUARTER_OF_YEAR(), 3], [ChronoField::HOUR_OF_DAY(), 1, ChronoField::SECOND_OF_MINUTE(), 5, ChronoField::NANO_OF_SECOND(), 5], [ChronoField::MINUTE_OF_HOUR(), 1, ChronoField::SECOND_OF_MINUTE(), 5, ChronoField::NANO_OF_SECOND(), 5]];
 }
 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);
                     }
                 }
             }
         }
     }
 }
 public function test_parse_weekDate_largeYear()
 {
     $parsed = DateTimeFormatter::ISO_WEEK_DATE()->parseUnresolved("+123456-W04-5", new ParsePosition(0));
     $this->assertEquals($parsed->getLong(IsoFields::WEEK_BASED_YEAR()), 123456);
     $this->assertEquals($parsed->getLong(IsoFields::WEEK_OF_WEEK_BASED_YEAR()), 4);
     $this->assertEquals($parsed->getLong(ChronoField::DAY_OF_WEEK()), 5);
 }
 function provider_text()
 {
     return [[ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 1, "Monday"], [ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 2, "Tuesday"], [ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 3, "Wednesday"], [ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 4, "Thursday"], [ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 5, "Friday"], [ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 6, "Saturday"], [ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 7, "Sunday"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 1, "Mon"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 2, "Tue"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 3, "Wed"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 4, "Thu"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 5, "Fri"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 6, "Sat"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 7, "Sun"], [ChronoField::MONTH_OF_YEAR(), TextStyle::FULL(), 1, "January"], [ChronoField::MONTH_OF_YEAR(), TextStyle::FULL(), 12, "December"], [ChronoField::MONTH_OF_YEAR(), TextStyle::SHORT(), 1, "Jan"], [ChronoField::MONTH_OF_YEAR(), TextStyle::SHORT(), 12, "Dec"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::FULL(), 1, "1st quarter"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::FULL(), 2, "2nd quarter"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::FULL(), 3, "3rd quarter"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::FULL(), 4, "4th quarter"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::SHORT(), 1, "Q1"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::SHORT(), 2, "Q2"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::SHORT(), 3, "Q3"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::SHORT(), 4, "Q4"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::NARROW(), 1, "1"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::NARROW(), 2, "2"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::NARROW(), 3, "3"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::NARROW(), 4, "4"]];
 }
 public function resolve(FieldValues $fieldValues, TemporalAccessor $partialTemporal, ResolverStyle $resolverStyle)
 {
     $wbyLong = $fieldValues->get(IsoFields::WEEK_BASED_YEAR());
     $dowLong = $fieldValues->get(ChronoField::DAY_OF_WEEK());
     if ($wbyLong === null || $dowLong === null) {
         return null;
     }
     $wby = IsoFields::WEEK_BASED_YEAR()->range()->checkValidIntValue($wbyLong, IsoFields::WEEK_BASED_YEAR());
     // always validate
     $wowby = $fieldValues->get(IsoFields::WEEK_OF_WEEK_BASED_YEAR());
     IsoFields::ensureIso($partialTemporal);
     $date = LocalDate::of($wby, 1, 4);
     if ($resolverStyle == ResolverStyle::LENIENT()) {
         $dow = $dowLong;
         // unvalidated
         if ($dow > 7) {
             $date = $date->plusWeeks(Math::div($dow - 1, 7));
             $dow = ($dow - 1) % 7 + 1;
         } else {
             if ($dow < 1) {
                 $date = $date->plusWeeks(Math::div(Math::subtractExact($dow, 7), 7));
                 $dow = ($dow + 6) % 7 + 1;
             }
         }
         $date = $date->plusWeeks(Math::subtractExact($wowby, 1))->with(ChronoField::DAY_OF_WEEK(), $dow);
     } else {
         $dow = ChronoField::DAY_OF_WEEK()->checkValidIntValue($dowLong);
         // validated
         if ($wowby < 1 || $wowby > 52) {
             if ($resolverStyle == ResolverStyle::STRICT()) {
                 IsoFields::getWeekRange($date)->checkValidValue($wowby, $this);
                 // only allow exact range
             } else {
                 // SMART
                 $this->range()->checkValidValue($wowby, $this);
                 // allow 1-53 rolling into next year
             }
         }
         $date = $date->plusWeeks($wowby - 1)->with(ChronoField::DAY_OF_WEEK(), $dow);
     }
     $fieldValues->remove($this);
     $fieldValues->remove(IsoFields::WEEK_BASED_YEAR());
     $fieldValues->remove(ChronoField::DAY_OF_WEEK());
     return $date;
 }
Beispiel #15
0
 public function isSupportedBy(TemporalAccessor $temporal)
 {
     return $temporal->isSupported(ChronoField::MONTH_OF_YEAR()) && IsoFields::isIso($temporal);
 }
 public function test_format_withChronology_nonChronoFieldMapLink()
 {
     $temporal = new format_withChronology_nonChronoFieldMapLink();
     $test = (new DateTimeFormatterBuilder())->appendValue2(IsoFields::WEEK_BASED_YEAR(), 4)->toFormatter2(Locale::ENGLISH())->withChronology(IsoChronology::INSTANCE());
     $result = $test->format($temporal);
     $this->assertEquals($result, "2345");
 }
Beispiel #17
0
 public function between(Temporal $temporal1Inclusive, Temporal $temporal2Exclusive)
 {
     if (get_class($temporal1Inclusive) !== get_class($temporal2Exclusive)) {
         return $temporal1Inclusive->until($temporal2Exclusive, $this);
     }
     switch ($this) {
         case self::WEEK_BASED_YEARS():
             return Math::subtractExact($temporal2Exclusive->getLong(IsoFields::WEEK_BASED_YEAR()), $temporal1Inclusive->getLong(IsoFields::WEEK_BASED_YEAR()));
         case self::QUARTER_YEARS():
             return Math::div($temporal1Inclusive->until($temporal2Exclusive, ChronoUnit::MONTHS()), 3);
         default:
             throw new IllegalStateException("Unreachable");
     }
 }