public function adjustInto(Temporal $temporal, $newValue) { // calls getFrom() to check if supported $curValue = $this->getFrom($temporal); $this->range()->checkValidValue($newValue, $this); // strictly check from 1 to 4 return $temporal->with(ChronoField::MONTH_OF_YEAR(), $temporal->getLong(ChronoField::MONTH_OF_YEAR()) + ($newValue - $curValue) * 3); }
public function getFrom(TemporalAccessor $temporal) { if ($this->isSupportedBy($temporal) == false) { throw new UnsupportedTemporalTypeException("Unsupported field: DayOfQuarter"); } $doy = $temporal->get(ChronoField::DAY_OF_YEAR()); $moy = $temporal->get(ChronoField::MONTH_OF_YEAR()); $year = $temporal->getLong(ChronoField::YEAR()); $quarterDays = [0, 90, 181, 273, 0, 91, 182, 274]; return $doy - $quarterDays[Math::div($moy - 1, 3) + (IsoChronology::INSTANCE()->isLeapYear($year) ? 4 : 0)]; }
/** * 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; }
public function test_parseUnresolved_StringParsePosition_duplicateFieldDifferentValue() { $test = (new DateTimeFormatterBuilder())->appendValue(CF::MONTH_OF_YEAR())->appendLiteral('-')->appendValue(CF::MONTH_OF_YEAR())->toFormatter(); $pos = new ParsePosition(3); $result = $test->parseUnresolved("XXX6-7", $pos); $this->assertEquals($pos->getIndex(), 3); $this->assertEquals($pos->getErrorIndex(), 5); $this->assertEquals($result, null); }
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())]]; }
public function test_getLong_TemporalField() { $this->assertEquals(self::TEST_2008_06()->getLong(CF::YEAR()), 2008); $this->assertEquals(self::TEST_2008_06()->getLong(CF::MONTH_OF_YEAR()), 6); $this->assertEquals(self::TEST_2008_06()->getLong(CF::YEAR_OF_ERA()), 2008); $this->assertEquals(self::TEST_2008_06()->getLong(CF::ERA()), 1); $this->assertEquals(self::TEST_2008_06()->getLong(CF::PROLEPTIC_MONTH()), 2008 * 12 + 6 - 1); }
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); }
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_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); }
/** * Returns a copy of this {@code YearMonth} with the month-of-year altered. * <p> * This instance is immutable and unaffected by this method call. * * @param int $month the month-of-year to set in the returned year-month, from 1 (January) to 12 (December) * @return YearMonth a {@code YearMonth} based on this year-month with the requested month, not null * @throws DateTimeException if the month-of-year value is invalid */ public function withMonth($month) { ChronoField::MONTH_OF_YEAR()->checkValidValue($month); return $this->_with($this->year, $month); }
/** * @dataProvider data_resolve_ymaa */ public function test_resolve_ymaa_strict($y, $m, $w, $d, $expected, $smar, $strict) { $fieldValues = new FieldValues(); $fieldValues->put(ChronoField::YEAR(), $y); $fieldValues->put(ChronoField::MONTH_OF_YEAR(), $m); $fieldValues->put(ChronoField::ALIGNED_WEEK_OF_MONTH(), $w); $fieldValues->put(ChronoField::ALIGNED_DAY_OF_WEEK_IN_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 } } }
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"); }
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 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); } } }
/** * @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); } }
public function test_parse_decoratedStartsWithPad_number() { $this->builder->padNext2(3, '-')->appendValue3(ChronoField::MONTH_OF_YEAR(), 1, 2, SignStyle::NORMAL()); $parsed = $this->builder->toFormatter()->parseUnresolved("--2", $this->pos); $this->assertEquals($this->pos->getIndex(), 3); $this->assertEquals($this->pos->getErrorIndex(), -1); $this->assertEquals($parsed->isSupported(ChronoField::MONTH_OF_YEAR()), true); $this->assertEquals($parsed->getLong(ChronoField::MONTH_OF_YEAR()), 2); // +2, not -2 }
protected function resolveYMAD(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); $weeks = Math::subtractExact($fieldValues->remove(ChronoField::ALIGNED_WEEK_OF_MONTH()), 1); $dow = Math::subtractExact($fieldValues->remove(ChronoField::DAY_OF_WEEK()), 1); return $this->resolveAligned($this->date($y, 1, 1), $months, $weeks, $dow); } $moy = $this->range(ChronoField::MONTH_OF_YEAR())->checkValidIntValue($fieldValues->remove(ChronoField::MONTH_OF_YEAR()), ChronoField::MONTH_OF_YEAR()); $aw = $this->range(ChronoField::ALIGNED_WEEK_OF_MONTH())->checkValidIntValue($fieldValues->remove(ChronoField::ALIGNED_WEEK_OF_MONTH()), ChronoField::ALIGNED_WEEK_OF_MONTH()); $dow = $this->range(ChronoField::DAY_OF_WEEK())->checkValidIntValue($fieldValues->remove(ChronoField::DAY_OF_WEEK()), ChronoField::DAY_OF_WEEK()); $date = $this->date($y, $moy, 1)->plus(($aw - 1) * 7, ChronoUnit::DAYS())->adjust(TemporalAdjusters::nextOrSame(DayOfWeek::of($dow))); if ($resolverStyle == ResolverStyle::STRICT() && $date->get(ChronoField::MONTH_OF_YEAR()) != $moy) { throw new DateTimeException("Strict mode rejected resolved date as it is in a different month"); } return $date; }
/** * 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)); }
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)); }
/** * @dataProvider data_weekFields * @group long */ public function test_parse_resolve_localizedWoyDow(DayOfWeek $firstDayOfWeek, $minDays) { $date = LocalDate::of(2012, 12, 15); $week = WeekFields::of($firstDayOfWeek, $minDays); $dowField = $week->dayOfWeek(); $woyField = $week->weekOfYear(); for ($i = 1; $i <= 60; $i++) { $f = (new DateTimeFormatterBuilder())->appendValue(CF::YEAR())->appendLiteral(':')->appendValue(CF::MONTH_OF_YEAR())->appendLiteral(':')->appendValue($woyField)->appendLiteral(':')->appendValue($dowField)->toFormatter(); $str = $date->getYear() . ":" . $date->getMonthValue() . ":" . $date->get($woyField) . ":" . $date->get($dowField); $parsed = LocalDate::parseWith($str, $f); $this->assertEquals($parsed, $date, " :: " . $str . " " . $i); $date = $date->plusDays(1); } }
public function test_appendTextMapIncomplete() { $map = [1, "JNY"]; $this->builder->appendText3(ChronoField::MONTH_OF_YEAR(), $map); $f = $this->builder->toFormatter(); $dt = LocalDateTime::of(2010, 2, 1, 0, 0); $this->assertEquals($f->format($dt), "2"); }
public function test_toString2() { $this->assertEquals("Text(MonthOfYear,SHORT)", $this->getFormatterFieldStyle(ChronoField::MONTH_OF_YEAR(), TextStyle::SHORT())->__toString()); }
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 test_isSupported_TemporalField() { //$this->assertEquals(DayOfWeek::THURSDAY()->isSupported(null), false); TODO $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::NANO_OF_SECOND()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::NANO_OF_DAY()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::MICRO_OF_SECOND()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::MICRO_OF_DAY()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::MILLI_OF_SECOND()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::MILLI_OF_DAY()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::SECOND_OF_MINUTE()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::SECOND_OF_DAY()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::MINUTE_OF_HOUR()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::MINUTE_OF_DAY()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::HOUR_OF_AMPM()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::CLOCK_HOUR_OF_AMPM()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::HOUR_OF_DAY()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::CLOCK_HOUR_OF_DAY()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::AMPM_OF_DAY()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::DAY_OF_WEEK()), true); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::ALIGNED_DAY_OF_WEEK_IN_MONTH()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::ALIGNED_DAY_OF_WEEK_IN_YEAR()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::DAY_OF_MONTH()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::DAY_OF_YEAR()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::EPOCH_DAY()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::ALIGNED_WEEK_OF_MONTH()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::ALIGNED_WEEK_OF_YEAR()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::MONTH_OF_YEAR()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::PROLEPTIC_MONTH()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::YEAR()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::YEAR_OF_ERA()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::ERA()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::INSTANT_SECONDS()), false); $this->assertEquals(DayOfWeek::THURSDAY()->isSupported(ChronoField::OFFSET_SECONDS()), false); }
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 {@code LocalDate} with the month-of-year altered. * <p> * If the day-of-month is invalid for the year, it will be changed to the last valid day of the month. * <p> * This instance is immutable and unaffected by this method call. * * @param int $month the month-of-year to set in the result, from 1 (January) to 12 (December) * @return LocalDate a {@code LocalDate} based on this date with the requested month, not null * @throws DateTimeException if the month-of-year value is invalid */ public function withMonth($month) { if ($this->month == $month) { return $this; } ChronoField::MONTH_OF_YEAR()->checkValidValue($month); return self::resolvePreviousValid($this->year, $month, $this->day); }
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 data_text() { return [[ChronoField::DAY_OF_WEEK(), 1, TextStyle::SHORT(), self::enUS(), "Mon"], [ChronoField::DAY_OF_WEEK(), 2, TextStyle::SHORT(), self::enUS(), "Tue"], [ChronoField::DAY_OF_WEEK(), 3, TextStyle::SHORT(), self::enUS(), "Wed"], [ChronoField::DAY_OF_WEEK(), 4, TextStyle::SHORT(), self::enUS(), "Thu"], [ChronoField::DAY_OF_WEEK(), 5, TextStyle::SHORT(), self::enUS(), "Fri"], [ChronoField::DAY_OF_WEEK(), 6, TextStyle::SHORT(), self::enUS(), "Sat"], [ChronoField::DAY_OF_WEEK(), 7, TextStyle::SHORT(), self::enUS(), "Sun"], [ChronoField::DAY_OF_WEEK(), 1, TextStyle::SHORT(), self::ptBR(), "seg"], [ChronoField::DAY_OF_WEEK(), 2, TextStyle::SHORT(), self::ptBR(), "ter"], [ChronoField::DAY_OF_WEEK(), 3, TextStyle::SHORT(), self::ptBR(), "qua"], [ChronoField::DAY_OF_WEEK(), 4, TextStyle::SHORT(), self::ptBR(), "qui"], [ChronoField::DAY_OF_WEEK(), 5, TextStyle::SHORT(), self::ptBR(), "sex"], [ChronoField::DAY_OF_WEEK(), 6, TextStyle::SHORT(), self::ptBR(), "sáb"], [ChronoField::DAY_OF_WEEK(), 7, TextStyle::SHORT(), self::ptBR(), "dom"], [ChronoField::DAY_OF_WEEK(), 1, TextStyle::FULL(), self::enUS(), "Monday"], [ChronoField::DAY_OF_WEEK(), 2, TextStyle::FULL(), self::enUS(), "Tuesday"], [ChronoField::DAY_OF_WEEK(), 3, TextStyle::FULL(), self::enUS(), "Wednesday"], [ChronoField::DAY_OF_WEEK(), 4, TextStyle::FULL(), self::enUS(), "Thursday"], [ChronoField::DAY_OF_WEEK(), 5, TextStyle::FULL(), self::enUS(), "Friday"], [ChronoField::DAY_OF_WEEK(), 6, TextStyle::FULL(), self::enUS(), "Saturday"], [ChronoField::DAY_OF_WEEK(), 7, TextStyle::FULL(), self::enUS(), "Sunday"], [ChronoField::DAY_OF_WEEK(), 1, TextStyle::FULL(), self::ptBR(), "segunda-feira"], [ChronoField::DAY_OF_WEEK(), 2, TextStyle::FULL(), self::ptBR(), "terça-feira"], [ChronoField::DAY_OF_WEEK(), 3, TextStyle::FULL(), self::ptBR(), "quarta-feira"], [ChronoField::DAY_OF_WEEK(), 4, TextStyle::FULL(), self::ptBR(), "quinta-feira"], [ChronoField::DAY_OF_WEEK(), 5, TextStyle::FULL(), self::ptBR(), "sexta-feira"], [ChronoField::DAY_OF_WEEK(), 6, TextStyle::FULL(), self::ptBR(), "sábado"], [ChronoField::DAY_OF_WEEK(), 7, TextStyle::FULL(), self::ptBR(), "domingo"], [ChronoField::MONTH_OF_YEAR(), 1, TextStyle::SHORT(), self::enUS(), "Jan"], [ChronoField::MONTH_OF_YEAR(), 2, TextStyle::SHORT(), self::enUS(), "Feb"], [ChronoField::MONTH_OF_YEAR(), 3, TextStyle::SHORT(), self::enUS(), "Mar"], [ChronoField::MONTH_OF_YEAR(), 4, TextStyle::SHORT(), self::enUS(), "Apr"], [ChronoField::MONTH_OF_YEAR(), 5, TextStyle::SHORT(), self::enUS(), "May"], [ChronoField::MONTH_OF_YEAR(), 6, TextStyle::SHORT(), self::enUS(), "Jun"], [ChronoField::MONTH_OF_YEAR(), 7, TextStyle::SHORT(), self::enUS(), "Jul"], [ChronoField::MONTH_OF_YEAR(), 8, TextStyle::SHORT(), self::enUS(), "Aug"], [ChronoField::MONTH_OF_YEAR(), 9, TextStyle::SHORT(), self::enUS(), "Sep"], [ChronoField::MONTH_OF_YEAR(), 10, TextStyle::SHORT(), self::enUS(), "Oct"], [ChronoField::MONTH_OF_YEAR(), 11, TextStyle::SHORT(), self::enUS(), "Nov"], [ChronoField::MONTH_OF_YEAR(), 12, TextStyle::SHORT(), self::enUS(), "Dec"], [ChronoField::MONTH_OF_YEAR(), 1, TextStyle::SHORT(), self::ptBR(), "jan"], [ChronoField::MONTH_OF_YEAR(), 2, TextStyle::SHORT(), self::ptBR(), "fev"], [ChronoField::MONTH_OF_YEAR(), 3, TextStyle::SHORT(), self::ptBR(), "mar"], [ChronoField::MONTH_OF_YEAR(), 4, TextStyle::SHORT(), self::ptBR(), "abr"], [ChronoField::MONTH_OF_YEAR(), 5, TextStyle::SHORT(), self::ptBR(), "mai"], [ChronoField::MONTH_OF_YEAR(), 6, TextStyle::SHORT(), self::ptBR(), "jun"], [ChronoField::MONTH_OF_YEAR(), 7, TextStyle::SHORT(), self::ptBR(), "jul"], [ChronoField::MONTH_OF_YEAR(), 8, TextStyle::SHORT(), self::ptBR(), "ago"], [ChronoField::MONTH_OF_YEAR(), 9, TextStyle::SHORT(), self::ptBR(), "set"], [ChronoField::MONTH_OF_YEAR(), 10, TextStyle::SHORT(), self::ptBR(), "out"], [ChronoField::MONTH_OF_YEAR(), 11, TextStyle::SHORT(), self::ptBR(), "nov"], [ChronoField::MONTH_OF_YEAR(), 12, TextStyle::SHORT(), self::ptBR(), "dez"], [ChronoField::MONTH_OF_YEAR(), 1, TextStyle::FULL(), self::enUS(), "January"], [ChronoField::MONTH_OF_YEAR(), 2, TextStyle::FULL(), self::enUS(), "February"], [ChronoField::MONTH_OF_YEAR(), 3, TextStyle::FULL(), self::enUS(), "March"], [ChronoField::MONTH_OF_YEAR(), 4, TextStyle::FULL(), self::enUS(), "April"], [ChronoField::MONTH_OF_YEAR(), 5, TextStyle::FULL(), self::enUS(), "May"], [ChronoField::MONTH_OF_YEAR(), 6, TextStyle::FULL(), self::enUS(), "June"], [ChronoField::MONTH_OF_YEAR(), 7, TextStyle::FULL(), self::enUS(), "July"], [ChronoField::MONTH_OF_YEAR(), 8, TextStyle::FULL(), self::enUS(), "August"], [ChronoField::MONTH_OF_YEAR(), 9, TextStyle::FULL(), self::enUS(), "September"], [ChronoField::MONTH_OF_YEAR(), 10, TextStyle::FULL(), self::enUS(), "October"], [ChronoField::MONTH_OF_YEAR(), 11, TextStyle::FULL(), self::enUS(), "November"], [ChronoField::MONTH_OF_YEAR(), 12, TextStyle::FULL(), self::enUS(), "December"], [ChronoField::MONTH_OF_YEAR(), 1, TextStyle::FULL(), self::ptBR(), "janeiro"], [ChronoField::MONTH_OF_YEAR(), 2, TextStyle::FULL(), self::ptBR(), "fevereiro"], [ChronoField::MONTH_OF_YEAR(), 3, TextStyle::FULL(), self::ptBR(), "março"], [ChronoField::MONTH_OF_YEAR(), 4, TextStyle::FULL(), self::ptBR(), "abril"], [ChronoField::MONTH_OF_YEAR(), 5, TextStyle::FULL(), self::ptBR(), "maio"], [ChronoField::MONTH_OF_YEAR(), 6, TextStyle::FULL(), self::ptBR(), "junho"], [ChronoField::MONTH_OF_YEAR(), 7, TextStyle::FULL(), self::ptBR(), "julho"], [ChronoField::MONTH_OF_YEAR(), 8, TextStyle::FULL(), self::ptBR(), "agosto"], [ChronoField::MONTH_OF_YEAR(), 9, TextStyle::FULL(), self::ptBR(), "setembro"], [ChronoField::MONTH_OF_YEAR(), 10, TextStyle::FULL(), self::ptBR(), "outubro"], [ChronoField::MONTH_OF_YEAR(), 11, TextStyle::FULL(), self::ptBR(), "novembro"], [ChronoField::MONTH_OF_YEAR(), 12, TextStyle::FULL(), self::ptBR(), "dezembro"], [ChronoField::AMPM_OF_DAY(), 0, TextStyle::SHORT(), self::enUS(), "AM"], [ChronoField::AMPM_OF_DAY(), 1, TextStyle::SHORT(), self::enUS(), "PM"]]; }
private function resolveWoM(FieldValues $fieldValues, Chronology $chrono, $year, $month, $wom, $localDow, ResolverStyle $resolverStyle) { if ($resolverStyle == ResolverStyle::LENIENT()) { $date = $chrono->date($year, 1, 1)->plus(Math::subtractExact($month, 1), ChronoUnit::MONTHS()); $weeks = Math::subtractExact($wom, $this->localizedWeekOfMonth($date)); $days = $localDow - $this->localizedDayOfWeek($date); // safe from overflow $date = $date->plus(Math::addExact(Math::multiplyExact($weeks, 7), $days), ChronoUnit::DAYS()); } else { $monthValid = CF::MONTH_OF_YEAR()->checkValidIntValue($month); // validate $date = $chrono->date($year, $monthValid, 1); $womInt = $this->range->checkValidIntValue($wom, $this); // validate $weeks = (int) ($womInt - $this->localizedWeekOfMonth($date)); // safe from overflow $days = $localDow - $this->localizedDayOfWeek($date); // safe from overflow $date = $date->plus($weeks * 7 + $days, ChronoUnit::DAYS()); if ($resolverStyle == ResolverStyle::STRICT() && $date->getLong(CF::MONTH_OF_YEAR()) !== $month) { throw new DateTimeException("Strict mode rejected resolved date as it is in a different month"); } } $fieldValues->remove($this); $fieldValues->remove(CF::YEAR()); $fieldValues->remove(CF::MONTH_OF_YEAR()); $fieldValues->remove(CF::DAY_OF_WEEK()); return $date; }