function data_normalized() { return [[ChronoField::YEAR(), 2127, ChronoField::YEAR(), 2127], [ChronoField::MONTH_OF_YEAR(), 12, ChronoField::MONTH_OF_YEAR(), 12], [ChronoField::DAY_OF_YEAR(), 127, ChronoField::DAY_OF_YEAR(), 127], [ChronoField::DAY_OF_MONTH(), 23, ChronoField::DAY_OF_MONTH(), 23], [ChronoField::DAY_OF_WEEK(), 127, ChronoField::DAY_OF_WEEK(), 127], [ChronoField::ALIGNED_WEEK_OF_YEAR(), 23, ChronoField::ALIGNED_WEEK_OF_YEAR(), 23], [ChronoField::ALIGNED_DAY_OF_WEEK_IN_YEAR(), 4, ChronoField::ALIGNED_DAY_OF_WEEK_IN_YEAR(), 4], [ChronoField::ALIGNED_WEEK_OF_MONTH(), 4, ChronoField::ALIGNED_WEEK_OF_MONTH(), 4], [ChronoField::ALIGNED_DAY_OF_WEEK_IN_MONTH(), 3, ChronoField::ALIGNED_DAY_OF_WEEK_IN_MONTH(), 3], [ChronoField::PROLEPTIC_MONTH(), 27, ChronoField::PROLEPTIC_MONTH(), null], [ChronoField::PROLEPTIC_MONTH(), 27, ChronoField::YEAR(), 2], [ChronoField::PROLEPTIC_MONTH(), 27, ChronoField::MONTH_OF_YEAR(), 4]]; }
function data_withFieldLong() { return [[self::TEST_LOCAL_2008_06_30_11_30_59_500()->atZone(self::ZONE_PARIS()), CF::YEAR(), 2009, $this->dateTimeZoned(2009, 6, 30, 11, 30, 59, 500, self::OFFSET_0200(), self::ZONE_PARIS())], [self::TEST_LOCAL_2008_06_30_11_30_59_500()->atZone(self::ZONE_PARIS()), CF::MONTH_OF_YEAR(), 7, $this->dateTimeZoned(2008, 7, 30, 11, 30, 59, 500, self::OFFSET_0200(), self::ZONE_PARIS())], [self::TEST_LOCAL_2008_06_30_11_30_59_500()->atZone(self::ZONE_PARIS()), CF::DAY_OF_MONTH(), 15, $this->dateTimeZoned(2008, 6, 15, 11, 30, 59, 500, self::OFFSET_0200(), self::ZONE_PARIS())], [self::TEST_LOCAL_2008_06_30_11_30_59_500()->atZone(self::ZONE_PARIS()), CF::HOUR_OF_DAY(), 14, $this->dateTimeZoned(2008, 6, 30, 14, 30, 59, 500, self::OFFSET_0200(), self::ZONE_PARIS())], [self::TEST_PARIS_OVERLAP_2008_10_26_02_30()->atZone(self::ZONE_PARIS())->withEarlierOffsetAtOverlap(), CF::HOUR_OF_DAY(), 0, $this->dateTimeZoned(2008, 10, 26, 0, 30, 0, 0, self::OFFSET_0200(), self::ZONE_PARIS())], [self::TEST_PARIS_OVERLAP_2008_10_26_02_30()->atZone(self::ZONE_PARIS())->withLaterOffsetAtOverlap(), CF::HOUR_OF_DAY(), 0, $this->dateTimeZoned(2008, 10, 26, 0, 30, 0, 0, self::OFFSET_0200(), self::ZONE_PARIS())], [self::TEST_PARIS_OVERLAP_2008_10_26_02_30()->atZone(self::ZONE_PARIS())->withEarlierOffsetAtOverlap(), CF::MINUTE_OF_HOUR(), 20, $this->dateTimeZoned(2008, 10, 26, 2, 20, 0, 0, self::OFFSET_0200(), self::ZONE_PARIS())], [self::TEST_PARIS_OVERLAP_2008_10_26_02_30()->atZone(self::ZONE_PARIS())->withLaterOffsetAtOverlap(), CF::MINUTE_OF_HOUR(), 20, $this->dateTimeZoned(2008, 10, 26, 2, 20, 0, 0, self::OFFSET_0100(), self::ZONE_PARIS())], [self::TEST_PARIS_OVERLAP_2008_10_26_02_30()->atZone(self::ZONE_PARIS())->withEarlierOffsetAtOverlap(), CF::HOUR_OF_DAY(), 3, $this->dateTimeZoned(2008, 10, 26, 3, 30, 0, 0, self::OFFSET_0100(), self::ZONE_PARIS())], [self::TEST_PARIS_OVERLAP_2008_10_26_02_30()->atZone(self::ZONE_PARIS())->withLaterOffsetAtOverlap(), CF::HOUR_OF_DAY(), 3, $this->dateTimeZoned(2008, 10, 26, 3, 30, 0, 0, self::OFFSET_0100(), self::ZONE_PARIS())], [self::TEST_LOCAL_2008_06_30_11_30_59_500()->atZone(self::ZONE_PARIS()), CF::OFFSET_SECONDS(), 7200, $this->dateTimeZoned(2008, 6, 30, 11, 30, 59, 500, self::OFFSET_0200(), self::ZONE_PARIS())], [self::TEST_LOCAL_2008_06_30_11_30_59_500()->atZone(self::ZONE_PARIS()), CF::OFFSET_SECONDS(), 3600, $this->dateTimeZoned(2008, 6, 30, 11, 30, 59, 500, self::OFFSET_0200(), self::ZONE_PARIS())], [self::TEST_PARIS_OVERLAP_2008_10_26_02_30()->atZone(self::ZONE_PARIS())->withEarlierOffsetAtOverlap(), CF::OFFSET_SECONDS(), 3600, $this->dateTimeZoned(2008, 10, 26, 2, 30, 0, 0, self::OFFSET_0100(), self::ZONE_PARIS())], [self::TEST_PARIS_OVERLAP_2008_10_26_02_30()->atZone(self::ZONE_PARIS())->withLaterOffsetAtOverlap(), CF::OFFSET_SECONDS(), 3600, $this->dateTimeZoned(2008, 10, 26, 2, 30, 0, 0, self::OFFSET_0100(), self::ZONE_PARIS())], [self::TEST_PARIS_OVERLAP_2008_10_26_02_30()->atZone(self::ZONE_PARIS())->withEarlierOffsetAtOverlap(), CF::OFFSET_SECONDS(), 7200, $this->dateTimeZoned(2008, 10, 26, 2, 30, 0, 0, self::OFFSET_0200(), self::ZONE_PARIS())], [self::TEST_PARIS_OVERLAP_2008_10_26_02_30()->atZone(self::ZONE_PARIS())->withLaterOffsetAtOverlap(), CF::OFFSET_SECONDS(), 7200, $this->dateTimeZoned(2008, 10, 26, 2, 30, 0, 0, self::OFFSET_0200(), self::ZONE_PARIS())]]; }
/** * @dataProvider provider_pad */ public function test_pad_EXCEEDS_PAD($minPad, $maxPad, $value, $result) { try { $this->getFormatterWidth(ChronoField::DAY_OF_MONTH(), $minPad, $maxPad, SignStyle::EXCEEDS_PAD())->formatTo(new MockFieldValue(ChronoField::DAY_OF_MONTH(), $value), $buf); if ($result == null) { $this->fail("Expected exception"); return; // unreachable } if (strlen($result) > $minPad || $value < 0) { $result = $value < 0 ? "-" . $result : "+" . $result; } $this->assertEquals($buf, $result); } catch (DateTimeException $ex) { if ($result !== null) { throw $ex; } $this->assertEquals(strpos($ex->getMessage(), ChronoField::DAY_OF_MONTH()->__toString()) !== false, true); } }
public function __toString() { // getLong() reduces chances of exceptions in toString() $yoe = $this->getLong(CF::YEAR_OF_ERA()); $moy = $this->getLong(CF::MONTH_OF_YEAR()); $dom = $this->getLong(CF::DAY_OF_MONTH()); return $this->getChronology()->__toString() . " " . $this->getEra() . " " . $yoe . ($moy < 10 ? "-0" : "-") . $moy . ($dom < 10 ? "-0" : "-") . $dom; }
public function range(TemporalField $field) { if ($field instanceof ChronoField) { if ($this->isSupported($field)) { $f = $field; switch ($f) { case CF::DAY_OF_MONTH(): case CF::DAY_OF_YEAR(): case CF::ALIGNED_WEEK_OF_MONTH(): return $this->isoDate->range($field); case CF::YEAR_OF_ERA(): $range = CF::YEAR()->range(); $max = $this->getProlepticYear() <= 0 ? -($range->getMinimum() + ThaiBuddhistChronology::YEARS_DIFFERENCE) + 1 : $range->getMaximum() + ThaiBuddhistChronology::YEARS_DIFFERENCE; return ValueRange::of(1, $max); } return $this->getChronology()->range($f); } throw new UnsupportedTemporalTypeException("Unsupported field: " . $field); } return $field->rangeRefinedBy($this); }
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 test_appendTextMap_DOM() { $map = [1 => "1st", 2 => "2nd", 3 => "3rd"]; $this->builder->appendText3(ChronoField::DAY_OF_MONTH(), $map); $f = $this->builder->toFormatter(); $dt = LocalDateTime::of(2010, 1, 1, 0, 0); $this->assertEquals($f->format($dt->withDayOfMonth(1)), "1st"); $this->assertEquals($f->format($dt->withDayOfMonth(2)), "2nd"); $this->assertEquals($f->format($dt->withDayOfMonth(3)), "3rd"); }
public function test_padOptional() { $this->builder->appendValue(ChronoField::MONTH_OF_YEAR())->appendLiteral(':')->padNext(5)->optionalStart()->appendValue(ChronoField::DAY_OF_MONTH())->optionalEnd()->appendLiteral(':')->appendValue(ChronoField::YEAR()); $this->assertEquals($this->builder->toFormatter()->format(LocalDate::of(2013, 2, 1)), "2: 1:2013"); $this->assertEquals($this->builder->toFormatter()->format(YearMonth::of(2013, 2)), "2: :2013"); }
/** * @dataProvider data_resolve_ymd */ public function test_resolve_ymd_strict($y, $m, $d, $expected, $smar, $strict) { $fieldValues = new FieldValues(); $fieldValues->put(ChronoField::YEAR(), $y); $fieldValues->put(ChronoField::MONTH_OF_YEAR(), $m); $fieldValues->put(ChronoField::DAY_OF_MONTH(), $d); if ($strict) { $date = IsoChronology::INSTANCE()->resolveDate($fieldValues, ResolverStyle::STRICT()); $this->assertEquals($date, $expected); $this->assertEquals($fieldValues->size(), 0); } else { try { IsoChronology::INSTANCE()->resolveDate($fieldValues, ResolverStyle::STRICT()); $this->fail("Should have failed"); } catch (DateTimeException $ex) { // $expected } } }
/** * @dataProvider data_resolveFourToTime */ public function test_resolveFourToDateTime($style, $hour, $min, $sec, $nano, $expectedTime, $excessPeriod) { $f = (new DateTimeFormatterBuilder())->parseDefaulting(ChronoField::YEAR(), 2012)->parseDefaulting(ChronoField::MONTH_OF_YEAR(), 6)->parseDefaulting(ChronoField::DAY_OF_MONTH(), 30)->parseDefaulting(ChronoField::HOUR_OF_DAY(), $hour)->parseDefaulting(ChronoField::MINUTE_OF_HOUR(), $min)->parseDefaulting(ChronoField::SECOND_OF_MINUTE(), $sec)->parseDefaulting(ChronoField::NANO_OF_SECOND(), $nano)->toFormatter(); $styles = $style !== null ? [$style] : ResolverStyle::values(); if ($expectedTime !== null && $excessPeriod !== null) { $expectedDate = LocalDate::of(2012, 6, 30)->plusAmount($excessPeriod); foreach ($styles as $s) { $accessor = $f->withResolverStyle($s)->parse(""); $this->assertEquals($accessor->query(TemporalQueries::localDate()), $expectedDate, "ResolverStyle: " . $s); $this->assertEquals($accessor->query(TemporalQueries::localTime()), $expectedTime, "ResolverStyle: " . $s); $this->assertEquals($accessor->query(DateTimeFormatter::parsedExcessDays()), Period::ZERO(), "ResolverStyle: " . $s); } } }
function data_localeDisplayNames() { return [[ChronoField::ERA()], [ChronoField::YEAR()], [ChronoField::MONTH_OF_YEAR()], [ChronoField::DAY_OF_WEEK()], [ChronoField::DAY_OF_MONTH()], [ChronoField::AMPM_OF_DAY()], [ChronoField::HOUR_OF_DAY()], [ChronoField::MINUTE_OF_HOUR()], [ChronoField::SECOND_OF_MINUTE()]]; }
/** * @dataProvider provider_parseDigitsAdjacentLenient */ public function test_parseDigitsAdjacentLenient($input, $parseLen, $parseMonth, $parsedDay) { $this->setStrict(false); $pos = new ParsePosition(0); $f = $this->builder->appendValue3(ChronoField::MONTH_OF_YEAR(), 1, 2, SignStyle::NORMAL())->appendValue2(ChronoField::DAY_OF_MONTH(), 2)->toFormatter2($this->locale)->withDecimalStyle($this->decimalStyle); $parsed = $f->parseUnresolved($input, $pos); if ($pos->getErrorIndex() !== -1) { $this->assertEquals($pos->getErrorIndex(), $parseLen); } else { $this->assertEquals($pos->getIndex(), $parseLen); $this->assertEquals($parsed->getLong(ChronoField::MONTH_OF_YEAR()), $parseMonth); $this->assertEquals($parsed->getLong(ChronoField::DAY_OF_MONTH()), $parsedDay); $this->assertEquals($parsed->query(TemporalQueries::chronology()), null); $this->assertEquals($parsed->query(TemporalQueries::zoneId()), null); } }
/** * Returns the day-of-week in month adjuster, which returns a new date * in the same month with the ordinal day-of-week. * This is used for expressions like the 'second Tuesday in March'. * <p> * The ISO calendar system behaves as follows:<br> * The input 2011-12-15 for (1,TUESDAY) will return 2011-12-06.<br> * The input 2011-12-15 for (2,TUESDAY) will return 2011-12-13.<br> * The input 2011-12-15 for (3,TUESDAY) will return 2011-12-20.<br> * The input 2011-12-15 for (4,TUESDAY) will return 2011-12-27.<br> * The input 2011-12-15 for (5,TUESDAY) will return 2012-01-03.<br> * The input 2011-12-15 for (-1,TUESDAY) will return 2011-12-27 (last in month).<br> * The input 2011-12-15 for (-4,TUESDAY) will return 2011-12-06 (3 weeks before last in month).<br> * The input 2011-12-15 for (-5,TUESDAY) will return 2011-11-29 (4 weeks before last in month).<br> * The input 2011-12-15 for (0,TUESDAY) will return 2011-11-29 (last in previous month).<br> * <p> * For a positive or zero ordinal, the algorithm is equivalent to finding the first * day-of-week that matches within the month and then adding a number of weeks to it. * For a negative ordinal, the algorithm is equivalent to finding the last * day-of-week that matches within the month and then subtracting a number of weeks to it. * The ordinal number of weeks is not validated and is interpreted leniently * according to this algorithm. This definition means that an ordinal of zero finds * the last matching day-of-week in the previous month. * <p> * The behavior is suitable for use with most calendar systems. * It uses the {@code DAY_OF_WEEK} and {@code DAY_OF_MONTH} fields * and the {@code DAYS} unit, and assumes a seven day week. * * @param int $ordinal the week within the month, unbounded but typically from -5 to 5 * @param DayOfWeek $dayOfWeek the day-of-week, not null * @return TemporalAdjuster the day-of-week in month adjuster, not null */ public static function dayOfWeekInMonth($ordinal, DayOfWeek $dayOfWeek) { $dowValue = $dayOfWeek->getValue(); if ($ordinal >= 0) { return self::fromCallable(function (Temporal $temporal) use($dowValue, $ordinal) { $temp = $temporal->with(ChronoField::DAY_OF_MONTH(), 1); $curDow = $temp->get(ChronoField::DAY_OF_WEEK()); $dowDiff = ($dowValue - $curDow + 7) % 7; $dowDiff += ($ordinal - 1) * 7; // safe from overflow return $temp->plus($dowDiff, ChronoUnit::DAYS()); }); } else { return self::fromCallable(function (Temporal $temporal) use($dowValue, $ordinal) { $temp = $temporal->with(ChronoField::DAY_OF_MONTH(), $temporal->range(ChronoField::DAY_OF_MONTH())->getMaximum()); $curDow = $temp->get(ChronoField::DAY_OF_WEEK()); $daysDiff = $dowValue - $curDow; $daysDiff = $daysDiff == 0 ? 0 : ($daysDiff > 0 ? $daysDiff - 7 : $daysDiff); $daysDiff -= (-$ordinal - 1) * 7; // safe from overflow return $temp->plus($daysDiff, ChronoUnit::DAYS()); }); } }
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); } } } } } }
protected function resolveYMD(FieldValues $fieldValues, ResolverStyle $resolverStyle) { $y = $this->range(ChronoField::YEAR())->checkValidIntValue($fieldValues->remove(ChronoField::YEAR()), ChronoField::YEAR()); if ($resolverStyle == ResolverStyle::LENIENT()) { $months = Math::subtractExact($fieldValues->remove(ChronoField::MONTH_OF_YEAR()), 1); $days = Math::subtractExact($fieldValues->remove(ChronoField::DAY_OF_MONTH()), 1); return $this->date($y, 1, 1)->plus($months, ChronoUnit::MONTHS())->plus($days, ChronoUnit::DAYS()); } $moy = $this->range(ChronoField::MONTH_OF_YEAR())->checkValidIntValue($fieldValues->remove(ChronoField::MONTH_OF_YEAR()), ChronoField::MONTH_OF_YEAR()); $domRange = $this->range(ChronoField::DAY_OF_MONTH()); $dom = $domRange->checkValidIntValue($fieldValues->remove(ChronoField::DAY_OF_MONTH()), ChronoField::DAY_OF_MONTH()); if ($resolverStyle == ResolverStyle::SMART()) { // previous valid try { return $this->date($y, $moy, $dom); } catch (DateTimeException $ex) { return $this->date($y, $moy, 1)->adjust(TemporalAdjusters::lastDayOfMonth()); } } return $this->date($y, $moy, $dom); }
public function test_parse_decoratedEmpty_lenient() { $this->builder->parseLenient()->padNext2(4, '-')->optionalStart()->appendValue(ChronoField::DAY_OF_MONTH())->optionalEnd(); $parsed = $this->builder->toFormatter()->parseUnresolved("----", $this->pos); $this->assertEquals($this->pos->getIndex(), 4); $this->assertEquals($this->pos->getErrorIndex(), -1); $this->assertNotNull($parsed); }
public function test_getLong_TemporalField() { $test = LocalDate::of(2008, 6, 30); $this->assertEquals($test->getLong(CF::YEAR()), 2008); $this->assertEquals($test->getLong(CF::MONTH_OF_YEAR()), 6); $this->assertEquals($test->getLong(CF::YEAR_OF_ERA()), 2008); $this->assertEquals($test->getLong(CF::ERA()), 1); $this->assertEquals($test->getLong(CF::PROLEPTIC_MONTH()), 2008 * 12 + 6 - 1); $this->assertEquals($test->getLong(CF::DAY_OF_MONTH()), 30); $this->assertEquals($test->getLong(CF::DAY_OF_WEEK()), 1); $this->assertEquals($test->getLong(CF::DAY_OF_YEAR()), 182); }
/** * Adjusts the specified temporal object to have this month-day. * <p> * This returns a temporal object of the same observable type as the input * with the month and day-of-month changed to be the same as this. * <p> * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)} * twice, passing {@link ChronoField#MONTH_OF_YEAR} and * {@link ChronoField#DAY_OF_MONTH} as the fields. * If the specified temporal object does not use the ISO calendar system then * a {@code DateTimeException} is thrown. * <p> * In most cases, it is clearer to reverse the calling pattern by using * {@link Temporal#with(TemporalAdjuster)}: * <pre> * // these two lines are equivalent, but the second approach is recommended * temporal = thisMonthDay.adjustInto(temporal); * temporal = temporal.with(thisMonthDay); * </pre> * <p> * This instance is immutable and unaffected by this method call. * * @param Temporal $temporal the target object to be adjusted, not null * @return Temporal the adjusted object, not null * @throws DateTimeException if unable to make the adjustment * @throws ArithmeticException if numeric overflow occurs */ public function adjustInto(Temporal $temporal) { if (AbstractChronology::from($temporal)->equals(IsoChronology::INSTANCE()) == false) { throw new DateTimeException("Adjustment only supported on ISO date-time"); } $temporal = $temporal->with(ChronoField::MONTH_OF_YEAR(), $this->month); return $temporal->with(ChronoField::DAY_OF_MONTH(), Math::min($temporal->range(ChronoField::DAY_OF_MONTH())->getMaximum(), $this->day)); }
function data_withFieldLong() { return [[self::TEST_2008_6_30_11_30_59_000000500(), CF::YEAR(), 2009, OffsetDateTime::of(2009, 6, 30, 11, 30, 59, 500, self::OFFSET_PONE())], [self::TEST_2008_6_30_11_30_59_000000500(), CF::MONTH_OF_YEAR(), 7, OffsetDateTime::of(2008, 7, 30, 11, 30, 59, 500, self::OFFSET_PONE())], [self::TEST_2008_6_30_11_30_59_000000500(), CF::DAY_OF_MONTH(), 15, OffsetDateTime::of(2008, 6, 15, 11, 30, 59, 500, self::OFFSET_PONE())], [self::TEST_2008_6_30_11_30_59_000000500(), CF::HOUR_OF_DAY(), 14, OffsetDateTime::of(2008, 6, 30, 14, 30, 59, 500, self::OFFSET_PONE())], [self::TEST_2008_6_30_11_30_59_000000500(), CF::OFFSET_SECONDS(), -3600, OffsetDateTime::of(2008, 6, 30, 11, 30, 59, 500, self::OFFSET_MONE())]]; }
public function test_withLocale_same() { $base = (new DateTimeFormatterBuilder())->appendLiteral2("ONE")->appendValue3(ChronoField::DAY_OF_MONTH(), 1, 2, SignStyle::NOT_NEGATIVE())->toFormatter2(Locale::ENGLISH())->withDecimalStyle(DecimalStyle::STANDARD()); $test = $base->withLocale(Locale::ENGLISH()); $this->assertSame($test, $base); }
function resolveYMD(FieldValues $fieldValues, ResolverStyle $resolverStyle) { $y = CF::YEAR()->checkValidIntValue($fieldValues->remove(CF::YEAR())); if ($resolverStyle == ResolverStyle::LENIENT()) { $months = Math::subtractExact($fieldValues->remove(CF::MONTH_OF_YEAR()), 1); $days = Math::subtractExact($fieldValues->remove(CF::DAY_OF_MONTH()), 1); return LocalDate::of($y, 1, 1)->plusMonths($months)->plusDays($days); } $moy = CF::MONTH_OF_YEAR()->checkValidIntValue($fieldValues->remove(CF::MONTH_OF_YEAR())); $dom = CF::DAY_OF_MONTH()->checkValidIntValue($fieldValues->remove(CF::DAY_OF_MONTH())); if ($resolverStyle == ResolverStyle::SMART()) { // previous valid if ($moy == 4 || $moy == 6 || $moy == 9 || $moy == 11) { $dom = Math::min($dom, 30); } else { if ($moy == 2) { $dom = Math::min($dom, Month::FEBRUARY()->length(Year::isLeapYear($y))); } } } return LocalDate::of($y, $moy, $dom); }
/** * @dataProvider data_weekFields * @group long */ public function test_fieldRanges(DayOfWeek $firstDayOfWeek, $minDays) { $weekDef = WeekFields::of($firstDayOfWeek, $minDays); $womField = $weekDef->weekOfMonth(); $woyField = $weekDef->weekOfYear(); $day = LocalDate::of(2012, 11, 30); $endDay = LocalDate::of(2013, 1, 2); while ($day->isBefore($endDay)) { $last = $day->with(CF::DAY_OF_MONTH(), $day->lengthOfMonth()); $lastWOM = $last->get($womField); $first = $day->with(CF::DAY_OF_MONTH(), 1); $firstWOM = $first->get($womField); $rangeWOM = $day->range($womField); $this->assertEquals($rangeWOM->getMinimum(), $firstWOM, "Range min should be same as WeekOfMonth for first day of month: " . $first . ", " . $weekDef); $this->assertEquals($rangeWOM->getMaximum(), $lastWOM, "Range max should be same as WeekOfMonth for last day of month: " . $last . ", " . $weekDef); $last = $day->with(CF::DAY_OF_YEAR(), $day->lengthOfYear()); $lastWOY = $last->get($woyField); $first = $day->with(CF::DAY_OF_YEAR(), 1); $firstWOY = $first->get($woyField); $rangeWOY = $day->range($woyField); $this->assertEquals($rangeWOY->getMinimum(), $firstWOY, "Range min should be same as WeekOfYear for first day of Year: " . $day . ", " . $weekDef); $this->assertEquals($rangeWOY->getMaximum(), $lastWOY, "Range max should be same as WeekOfYear for last day of Year: " . $day . ", " . $weekDef); $day = $day->plusDays(1); } }
public function test_isSupported_TemporalField() { // TODO $this->assertEquals(self::TEST_2008_06()->isSupported(null), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::NANO_OF_SECOND()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::NANO_OF_DAY()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::MICRO_OF_SECOND()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::MICRO_OF_DAY()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::MILLI_OF_SECOND()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::MILLI_OF_DAY()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::SECOND_OF_MINUTE()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::SECOND_OF_DAY()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::MINUTE_OF_HOUR()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::MINUTE_OF_DAY()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::HOUR_OF_AMPM()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::CLOCK_HOUR_OF_AMPM()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::HOUR_OF_DAY()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::CLOCK_HOUR_OF_DAY()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::AMPM_OF_DAY()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::DAY_OF_WEEK()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::ALIGNED_DAY_OF_WEEK_IN_MONTH()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::ALIGNED_DAY_OF_WEEK_IN_YEAR()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::DAY_OF_MONTH()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::DAY_OF_YEAR()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::EPOCH_DAY()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::ALIGNED_WEEK_OF_MONTH()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::ALIGNED_WEEK_OF_YEAR()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::MONTH_OF_YEAR()), true); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::PROLEPTIC_MONTH()), true); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::YEAR()), true); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::YEAR_OF_ERA()), true); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::ERA()), true); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::INSTANT_SECONDS()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::OFFSET_SECONDS()), false); }
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_getLong_TemporalField() { $test = LocalDateTime::of(2008, 6, 30, 12, 30, 40, 987654321); $this->assertEquals($test->getLong(CF::YEAR()), 2008); $this->assertEquals($test->getLong(CF::MONTH_OF_YEAR()), 6); $this->assertEquals($test->getLong(CF::DAY_OF_MONTH()), 30); $this->assertEquals($test->getLong(CF::DAY_OF_WEEK()), 1); $this->assertEquals($test->getLong(CF::DAY_OF_YEAR()), 182); $this->assertEquals($test->getLong(CF::HOUR_OF_DAY()), 12); $this->assertEquals($test->getLong(CF::MINUTE_OF_HOUR()), 30); $this->assertEquals($test->getLong(CF::SECOND_OF_MINUTE()), 40); $this->assertEquals($test->getLong(CF::NANO_OF_SECOND()), 987654321); $this->assertEquals($test->getLong(CF::HOUR_OF_AMPM()), 0); $this->assertEquals($test->getLong(CF::AMPM_OF_DAY()), 1); }
public static function RFC_1123_DATE_TIME() { // manually code maps to ensure correct data always used // (locale data can be changed by application code) $dow = [1 => "Mon", 2 => "Tue", 3 => "Wed", 4 => "Thu", 5 => "Fri", 6 => "Sat", 7 => "Sun"]; $moy = [1 => "Jan", 2 => "Feb", 3 => "Mar", 4 => "Apr", 5 => "May", 6 => "Jun", 7 => "Jul", 8 => "Aug", 9 => "Sep", 10 => "Oct", 11 => "Nov", 12 => "Dec"]; return self::$RFC_1123_DATE_TIME = (new DateTimeFormatterBuilder())->parseCaseInsensitive()->parseLenient()->optionalStart()->appendText3(ChronoField::DAY_OF_WEEK(), $dow)->appendLiteral2(", ")->optionalEnd()->appendValue3(ChronoField::DAY_OF_MONTH(), 1, 2, SignStyle::NOT_NEGATIVE())->appendLiteral(' ')->appendText3(ChronoField::MONTH_OF_YEAR(), $moy)->appendLiteral(' ')->appendValue2(ChronoField::YEAR(), 4)->appendLiteral(' ')->appendValue2(ChronoField::HOUR_OF_DAY(), 2)->appendLiteral(':')->appendValue2(ChronoField::MINUTE_OF_HOUR(), 2)->optionalStart()->appendLiteral(':')->appendValue2(ChronoField::SECOND_OF_MINUTE(), 2)->optionalEnd()->appendLiteral(' ')->appendOffset("+HHMM", "GMT")->toFormatter3(ResolverStyle::SMART(), IsoChronology::INSTANCE()); }
/** * Returns a copy of this date with the specified field set to a new value. * <p> * This returns a {@code LocalDate}, based on this one, with the value * for the specified field changed. * This can be used to change any supported field, such as the year, month or day-of-month. * If it is not possible to set the value, because the field is not supported or for * some other reason, an exception is thrown. * <p> * In some cases, changing the specified field can cause the resulting date to become invalid, * such as changing the month from 31st January to February would make the day-of-month invalid. * In cases like this, the field is responsible for resolving the date. Typically it will choose * the previous valid date, which would be the last valid day of February in this example. * <p> * If the field is a {@link ChronoField} then the adjustment is implemented here. * The supported fields behave as follows: * <ul> * <li>{@code DAY_OF_WEEK} - * Returns a {@code LocalDate} with the specified day-of-week. * The date is adjusted up to 6 days forward or backward within the boundary * of a Monday to Sunday week. * <li>{@code ALIGNED_DAY_OF_WEEK_IN_MONTH} - * Returns a {@code LocalDate} with the specified aligned-day-of-week. * The date is adjusted to the specified month-based aligned-day-of-week. * Aligned weeks are counted such that the first week of a given month starts * on the first day of that month. * This may cause the date to be moved up to 6 days into the following month. * <li>{@code ALIGNED_DAY_OF_WEEK_IN_YEAR} - * Returns a {@code LocalDate} with the specified aligned-day-of-week. * The date is adjusted to the specified year-based aligned-day-of-week. * Aligned weeks are counted such that the first week of a given year starts * on the first day of that year. * This may cause the date to be moved up to 6 days into the following year. * <li>{@code DAY_OF_MONTH} - * Returns a {@code LocalDate} with the specified day-of-month. * The month and year will be unchanged. If the day-of-month is invalid for the * year and month, then a {@code DateTimeException} is thrown. * <li>{@code DAY_OF_YEAR} - * Returns a {@code LocalDate} with the specified day-of-year. * The year will be unchanged. If the day-of-year is invalid for the * year, then a {@code DateTimeException} is thrown. * <li>{@code EPOCH_DAY} - * Returns a {@code LocalDate} with the specified epoch-day. * This completely replaces the date and is equivalent to {@link #ofEpochDay(long)}. * <li>{@code ALIGNED_WEEK_OF_MONTH} - * Returns a {@code LocalDate} with the specified aligned-week-of-month. * Aligned weeks are counted such that the first week of a given month starts * on the first day of that month. * This adjustment moves the date in whole week chunks to match the specified week. * The result will have the same day-of-week as this date. * This may cause the date to be moved into the following month. * <li>{@code ALIGNED_WEEK_OF_YEAR} - * Returns a {@code LocalDate} with the specified aligned-week-of-year. * Aligned weeks are counted such that the first week of a given year starts * on the first day of that year. * This adjustment moves the date in whole week chunks to match the specified week. * The result will have the same day-of-week as this date. * This may cause the date to be moved into the following year. * <li>{@code MONTH_OF_YEAR} - * Returns a {@code LocalDate} with the specified month-of-year. * The year will be unchanged. The day-of-month will also be unchanged, * unless it would be invalid for the new month and year. In that case, the * day-of-month is adjusted to the maximum valid value for the new month and year. * <li>{@code PROLEPTIC_MONTH} - * Returns a {@code LocalDate} with the specified proleptic-month. * The day-of-month will be unchanged, unless it would be invalid for the new month * and year. In that case, the day-of-month is adjusted to the maximum valid value * for the new month and year. * <li>{@code YEAR_OF_ERA} - * Returns a {@code LocalDate} with the specified year-of-era. * The era and month will be unchanged. The day-of-month will also be unchanged, * unless it would be invalid for the new month and year. In that case, the * day-of-month is adjusted to the maximum valid value for the new month and year. * <li>{@code YEAR} - * Returns a {@code LocalDate} with the specified year. * The month will be unchanged. The day-of-month will also be unchanged, * unless it would be invalid for the new month and year. In that case, the * day-of-month is adjusted to the maximum valid value for the new month and year. * <li>{@code ERA} - * Returns a {@code LocalDate} with the specified era. * The year-of-era and month will be unchanged. The day-of-month will also be unchanged, * unless it would be invalid for the new month and year. In that case, the * day-of-month is adjusted to the maximum valid value for the new month and year. * </ul> * <p> * In all cases, if the new value is outside the valid range of values for the field * then a {@code DateTimeException} will be thrown. * <p> * 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.adjustInto(Temporal, long)} * passing {@code this} as the argument. In this case, the field determines * whether and how to adjust the instant. * <p> * This instance is immutable and unaffected by this method call. * * @param TemporalField $field the field to set in the result, not null * @param int $newValue the new value of the field in the result * @return LocalDate a {@code LocalDate} based on {@code this} with the specified field set, not null * @throws DateTimeException if the field cannot be set * @throws UnsupportedTemporalTypeException if the field is not supported * @throws ArithmeticException if numeric overflow occurs */ public function with(TemporalField $field, $newValue) { if ($field instanceof ChronoField) { /** @var Chronofield $f */ $f = $field; $f->checkValidValue($newValue); switch ($f) { case ChronoField::DAY_OF_WEEK(): return $this->plusDays($newValue - $this->getDayOfWeek()->getValue()); case ChronoField::ALIGNED_DAY_OF_WEEK_IN_MONTH(): return $this->plusDays($newValue - $this->getLong(ChronoField::ALIGNED_DAY_OF_WEEK_IN_MONTH())); case ChronoField::ALIGNED_DAY_OF_WEEK_IN_YEAR(): return $this->plusDays($newValue - $this->getLong(ChronoField::ALIGNED_DAY_OF_WEEK_IN_YEAR())); case ChronoField::DAY_OF_MONTH(): return $this->withDayOfMonth((int) $newValue); case ChronoField::DAY_OF_YEAR(): return $this->withDayOfYear((int) $newValue); case ChronoField::EPOCH_DAY(): return LocalDate::ofEpochDay($newValue); case ChronoField::ALIGNED_WEEK_OF_MONTH(): return $this->plusWeeks($newValue - $this->getLong(ChronoField::ALIGNED_WEEK_OF_MONTH())); case ChronoField::ALIGNED_WEEK_OF_YEAR(): return $this->plusWeeks($newValue - $this->getLong(ChronoField::ALIGNED_WEEK_OF_YEAR())); case ChronoField::MONTH_OF_YEAR(): return $this->withMonth((int) $newValue); case ChronoField::PROLEPTIC_MONTH(): return $this->plusMonths($newValue - $this->getProlepticMonth()); case ChronoField::YEAR_OF_ERA(): return $this->withYear((int) ($this->year >= 1 ? $newValue : 1 - $newValue)); case ChronoField::YEAR(): return $this->withYear((int) $newValue); case ChronoField::ERA(): return $this->getLong(ChronoField::ERA()) == $newValue ? $this : $this->withYear(1 - $this->year); } throw new UnsupportedTemporalTypeException("Unsupported field: " . $field); } return $field->adjustInto($this, $newValue); }
public function test_getLong_TemporalField() { $this->assertEquals(self::TEST_07_15()->getLong(CF::DAY_OF_MONTH()), 15); $this->assertEquals(self::TEST_07_15()->getLong(CF::MONTH_OF_YEAR()), 7); }
public function test_parseUnresolved_StringParsePosition() { $test = $this->fmt->withLocale(Locale::ENGLISH())->withDecimalStyle(DecimalStyle::STANDARD()); $pos = new ParsePosition(0); $result = $test->parseUnresolved("ONE30XXX", $pos); $this->assertEquals($pos->getIndex(), 5); $this->assertEquals($pos->getErrorIndex(), -1); $this->assertEquals($result->getLong(CF::DAY_OF_MONTH()), 30); }
/** * @dataProvider provider_parseAdjacent */ public function test_parseAdjacent($pattern, $input, $strict, $pos, $parseLen, $year, $month, $day) { $ppos = new ParsePosition(0); $this->setStrict($strict); $this->builder->appendPattern($pattern); $dtf = $this->builder->toFormatter(); $parsed = $dtf->parseUnresolved($input, $ppos); $this->assertNotNull($parsed, "parse failed: ppos: " . $ppos . ", formatter: " . $dtf); if ($ppos->getErrorIndex() != -1) { $this->assertEquals($ppos->getErrorIndex(), $parseLen, "error case parse position"); } else { $this->assertEquals($parseLen, $ppos->getIndex(), "parse position"); $this->assertParsed($parsed, ChronoField::YEAR_OF_ERA(), $year); $this->assertParsed($parsed, ChronoField::MONTH_OF_YEAR(), $month); $this->assertParsed($parsed, ChronoField::DAY_OF_MONTH(), $day); } }