예제 #1
0
 /**
  * @dataProvider data_signStyle
  */
 public function test_signStyle(LocalDate $localDate, SignStyle $style, $expectedEx, $expectedStr)
 {
     $builder = new DateTimeFormatterBuilder();
     $formatter = $builder->appendValue3(ChronoField::YEAR(), 2, 4, $style)->toFormatter();
     $formatter = $formatter->withZone(ZoneOffset::UTC());
     if ($expectedEx === null) {
         $output = $formatter->format($localDate);
         $this->assertEquals($output, $expectedStr);
     } else {
         try {
             $formatter->format($localDate);
             $this->fail();
         } catch (\Exception $ex) {
             $this->assertInstanceOf($expectedEx, $ex);
         }
     }
 }
예제 #2
0
 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);
                     }
                 }
             }
         }
     }
 }
 /**
  * @dataProvider data_success
  */
 public function test_parse_success($s, $caseSensitive, $text, $pos, $expectedPos)
 {
     $this->setCaseSensitive($caseSensitive);
     $ppos = new ParsePosition($pos);
     $parsed = $this->getFormatterString($s)->parseUnresolved($text, $ppos);
     if ($ppos->getErrorIndex() != -1) {
         $this->assertEquals($ppos->getIndex(), $expectedPos);
     } else {
         $this->assertEquals($ppos->getIndex(), $expectedPos);
         $this->assertEquals($parsed->isSupported(ChronoField::YEAR()), false);
         $this->assertEquals($parsed->query(TemporalQueries::chronology()), null);
         $this->assertEquals($parsed->query(TemporalQueries::zoneId()), null);
     }
 }
 public function test_parse_CharSequence_ParsePosition_resolved()
 {
     $test = DateTimeFormatter::ISO_DATE();
     $pos = new ParsePosition(3);
     $result = $test->parsePos("XXX2012-06-30XXX", $pos);
     $this->assertEquals($pos->getIndex(), 13);
     $this->assertEquals($pos->getErrorIndex(), -1);
     $this->assertEquals($result->isSupported(CF::YEAR()), true);
     $this->assertEquals($result->isSupported(CF::MONTH_OF_YEAR()), true);
     $this->assertEquals($result->isSupported(CF::DAY_OF_MONTH()), true);
     $this->assertEquals($result->isSupported(CF::HOUR_OF_DAY()), false);
     $this->assertEquals($result->getLong(CF::YEAR()), 2012);
     $this->assertEquals($result->getLong(CF::MONTH_OF_YEAR()), 6);
     $this->assertEquals($result->getLong(CF::DAY_OF_MONTH()), 30);
     $this->assertEquals($result->query(TemporalQueries::fromCallable([LocalDate::class, 'from'])), LocalDate::of(2012, 6, 30));
 }
 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())]];
 }
예제 #6
0
 public function with(TemporalField $field, $newValue)
 {
     if ($field instanceof ChronoField) {
         $f = $field;
         if ($this->getLong($f) === $newValue) {
             return $this;
         }
         switch ($f) {
             case CF::PROLEPTIC_MONTH():
                 $this->getChronology()->range($f)->checkValidValue($newValue, $f);
                 return $this->plusMonths($newValue - $this->getProlepticMonth());
             case CF::YEAR_OF_ERA():
             case CF::YEAR():
             case ERA:
                 $nvalue = $this->getChronology()->range($f)->checkValidIntValue($newValue, $f);
                 switch ($f) {
                     case CF::YEAR_OF_ERA():
                         return $this->withDate($this->isoDate->withYear(($this->getProlepticYear() >= 1 ? $nvalue : 1 - $nvalue) - ThaiBuddhistChronology::YEARS_DIFFERENCE));
                     case CF::YEAR():
                         return $this->withDate($this->isoDate->withYear($nvalue - ThaiBuddhistChronology::YEARS_DIFFERENCE));
                     case ERA:
                         return $this->withDate($this->isoDate->withYear(1 - $this->getProlepticYear() - ThaiBuddhistChronology::YEARS_DIFFERENCE));
                 }
         }
         return $this->withDate($this->isoDate->with($field, $newValue));
     }
     return parent::with($field, $newValue);
 }
예제 #7
0
 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);
 }
예제 #8
0
 /**
  * Adjusts the specified temporal object to have this year.
  * <p>
  * This returns a temporal object of the same observable type as the input
  * with the year changed to be the same as this.
  * <p>
  * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
  * passing {@link ChronoField#YEAR} as the field.
  * 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 = thisYear.adjustInto(temporal);
  *   temporal = temporal.with(thisYear);
  * </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");
     }
     return $temporal->with(ChronoField::YEAR(), $this->year);
 }
예제 #9
0
 /**
  * @dataProvider data_weekFields
  * @group long
  */
 public function test_parse_resolve_localizedWoyDow_lenient(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($woyField)->appendLiteral(':')->appendValue($dowField)->toFormatter()->withResolverStyle(ResolverStyle::LENIENT());
         $woy = $date->get($woyField);
         $dow = $date->get($dowField);
         for ($j = $woy - 60; $j < $woy + 60; $j++) {
             $str = $date->getYear() . ":" . $j . ":" . $dow;
             $parsed = LocalDate::parseWith($str, $f);
             $this->assertEquals($parsed, $date->plusWeeks($j - $woy), " ::" . $str . ": :" . $i . "::" . $j);
         }
         $date = $date->plusDays(1);
     }
 }
예제 #10
0
 /**
  * @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
         }
     }
 }
예제 #11
0
 public function range()
 {
     return ChronoField::YEAR()->range();
 }
 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");
 }
예제 #13
0
 public function test_nullLocaleChronoFieldDisplayName()
 {
     TestHelper::assertNullException($this, function () {
         ChronoField::YEAR()->getDisplayName(null);
     });
 }
 /**
  * @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);
         }
     }
 }
예제 #15
0
 public function test_toString()
 {
     $this->assertEquals($this->getFormatter1(ChronoField::YEAR(), 2, 2, 2005)->__toString(), "ReducedValue(Year,2,2,2005)");
 }
예제 #16
0
 function data_fieldAndAccessor()
 {
     return [[CF::YEAR(), LocalDate::of(2000, 2, 29), true, 2000], [CF::YEAR(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 2000], [CF::MONTH_OF_YEAR(), LocalDate::of(2000, 2, 29), true, 2], [CF::MONTH_OF_YEAR(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 2], [CF::DAY_OF_MONTH(), LocalDate::of(2000, 2, 29), true, 29], [CF::DAY_OF_MONTH(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 29], [CF::DAY_OF_YEAR(), LocalDate::of(2000, 2, 29), true, 60], [CF::DAY_OF_YEAR(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 60], [CF::HOUR_OF_DAY(), LocalTime::of(5, 4, 3, 200), true, 5], [CF::HOUR_OF_DAY(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 5], [CF::MINUTE_OF_DAY(), LocalTime::of(5, 4, 3, 200), true, 5 * 60 + 4], [CF::MINUTE_OF_DAY(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 5 * 60 + 4], [CF::MINUTE_OF_HOUR(), LocalTime::of(5, 4, 3, 200), true, 4], [CF::MINUTE_OF_HOUR(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 4], [CF::SECOND_OF_DAY(), LocalTime::of(5, 4, 3, 200), true, 5 * 3600 + 4 * 60 + 3], [CF::SECOND_OF_DAY(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 5 * 3600 + 4 * 60 + 3], [CF::SECOND_OF_MINUTE(), LocalTime::of(5, 4, 3, 200), true, 3], [CF::SECOND_OF_MINUTE(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 3], [CF::NANO_OF_SECOND(), LocalTime::of(5, 4, 3, 200), true, 200], [CF::NANO_OF_SECOND(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 200], [CF::YEAR(), LocalTime::of(5, 4, 3, 200), false, -1], [CF::MONTH_OF_YEAR(), LocalTime::of(5, 4, 3, 200), false, -1], [CF::DAY_OF_MONTH(), LocalTime::of(5, 4, 3, 200), false, -1], [CF::DAY_OF_YEAR(), LocalTime::of(5, 4, 3, 200), false, -1], [CF::HOUR_OF_DAY(), LocalDate::of(2000, 2, 29), false, -1], [CF::MINUTE_OF_DAY(), LocalDate::of(2000, 2, 29), false, -1], [CF::MINUTE_OF_HOUR(), LocalDate::of(2000, 2, 29), false, -1], [CF::SECOND_OF_DAY(), LocalDate::of(2000, 2, 29), false, -1], [CF::SECOND_OF_MINUTE(), LocalDate::of(2000, 2, 29), false, -1], [CF::NANO_OF_SECOND(), LocalDate::of(2000, 2, 29), false, -1]];
 }
 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())]];
 }
예제 #18
0
 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());
 }
예제 #19
0
 public function test_isSupported_TemporalField()
 {
     // TODO $this->assertEquals(self::TEST_07_15()->isSupported(null), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::NANO_OF_SECOND()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::NANO_OF_DAY()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::MICRO_OF_SECOND()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::MICRO_OF_DAY()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::MILLI_OF_SECOND()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::MILLI_OF_DAY()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::SECOND_OF_MINUTE()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::SECOND_OF_DAY()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::MINUTE_OF_HOUR()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::MINUTE_OF_DAY()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::HOUR_OF_AMPM()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::CLOCK_HOUR_OF_AMPM()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::HOUR_OF_DAY()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::CLOCK_HOUR_OF_DAY()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::AMPM_OF_DAY()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::DAY_OF_WEEK()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::ALIGNED_DAY_OF_WEEK_IN_MONTH()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::ALIGNED_DAY_OF_WEEK_IN_YEAR()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::DAY_OF_MONTH()), true);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::DAY_OF_YEAR()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::EPOCH_DAY()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::ALIGNED_WEEK_OF_MONTH()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::ALIGNED_WEEK_OF_YEAR()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::MONTH_OF_YEAR()), true);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::PROLEPTIC_MONTH()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::YEAR()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::YEAR_OF_ERA()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::ERA()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::INSTANT_SECONDS()), false);
     $this->assertEquals(self::TEST_07_15()->isSupported(CF::OFFSET_SECONDS()), false);
 }
예제 #20
0
 /**
  * @dataProvider data_parseLenientQuarter
  */
 public function test_parse_parseLenientQuarter_LENIENT($str, LocalDate $expected, $smart)
 {
     $f = (new DateTimeFormatterBuilder())->appendValue(CF::YEAR())->appendLiteral(':')->appendValue(IsoFields::QUARTER_OF_YEAR())->appendLiteral(':')->appendValue(IsoFields::DAY_OF_QUARTER())->toFormatter()->withResolverStyle(ResolverStyle::LENIENT());
     $parsed = LocalDate::parseWith($str, $f);
     $this->assertEquals($parsed, $expected);
 }
예제 #21
0
 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);
 }
 /**
  * @inheritdoc
  */
 public function isLeapYear()
 {
     return $this->getChronology()->isLeapYear($this->getLong(ChronoField::YEAR()));
 }
예제 #23
0
 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);
 }
예제 #24
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);
 }
예제 #25
0
 /**
  * Returns a copy of this {@code LocalDate} with the specified number of months added.
  * <p>
  * This method adds the specified amount to the months field in three steps:
  * <ol>
  * <li>Add the input months to the month-of-year field</li>
  * <li>Check if the resulting date would be invalid</li>
  * <li>Adjust the day-of-month to the last valid day if necessary</li>
  * </ol>
  * <p>
  * For example, 2007-03-31 plus one month would result in the invalid date
  * 2007-04-31. Instead of returning an invalid result, the last valid day
  * of the month, 2007-04-30, is selected instead.
  * <p>
  * This instance is immutable and unaffected by this method call.
  *
  * @param int $monthsToAdd the months to add, may be negative
  * @return LocalDate a {@code LocalDate} based on this date with the months added, not null
  * @throws DateTimeException if the result exceeds the supported date range
  */
 public function plusMonths($monthsToAdd)
 {
     if ($monthsToAdd === 0) {
         return $this;
     }
     $monthCount = $this->year * 12 + ($this->month - 1);
     $calcMonths = $monthCount + $monthsToAdd;
     // safe overflow
     if (!is_int($calcMonths)) {
         throw new DateTimeException('Overflow');
         // Todo better message
     }
     $newYear = ChronoField::YEAR()->checkValidIntValue(Math::floorDiv($calcMonths, 12));
     $newMonth = Math::floorMod($calcMonths, 12) + 1;
     return self::resolvePreviousValid($newYear, $newMonth, $this->day);
 }
예제 #26
0
 protected function resolveYAD(FieldValues $fieldValues, ResolverStyle $resolverStyle)
 {
     $y = $this->range(ChronoField::YEAR())->checkValidIntValue($fieldValues->remove(ChronoField::YEAR()), ChronoField::YEAR());
     if ($resolverStyle == ResolverStyle::LENIENT()) {
         $weeks = Math::subtractExact($fieldValues->remove(ChronoField::ALIGNED_WEEK_OF_YEAR()), 1);
         $dow = Math::subtractExact($fieldValues->remove(ChronoField::DAY_OF_WEEK()), 1);
         return $this->resolveAligned($this->dateYearDay($y, 1), 0, $weeks, $dow);
     }
     $aw = $this->range(ChronoField::ALIGNED_WEEK_OF_YEAR())->checkValidIntValue($fieldValues->remove(ChronoField::ALIGNED_WEEK_OF_YEAR()), ChronoField::ALIGNED_WEEK_OF_YEAR());
     $dow = $this->range(ChronoField::DAY_OF_WEEK())->checkValidIntValue($fieldValues->remove(ChronoField::DAY_OF_WEEK()), ChronoField::DAY_OF_WEEK());
     $date = $this->dateYearDay($y, 1)->plus(($aw - 1) * 7, ChronoUnit::DAYS())->adjust(TemporalAdjusters::nextOrSame(DayOfWeek::of($dow)));
     if ($resolverStyle == ResolverStyle::STRICT() && $date->get(ChronoField::YEAR()) != $y) {
         throw new DateTimeException("Strict mode rejected resolved date as it is in a different year");
     }
     return $date;
 }
예제 #27
0
 /**
  * Adds a multi-year transition rule to the current window.
  * <p>
  * This adds a rule such that the offset, expressed as a daylight savings amount,
  * changes at the specified date-time for each year in the range.
  *
  * @param int $startYear the start year of the rule, from MIN_VALUE to MAX_VALUE
  * @param int $endYear the end year of the rule, from MIN_VALUE to MAX_VALUE
  * @param Month $month the month of the transition, not null
  * @param int $dayOfMonthIndicator the day-of-month of the transition, adjusted by dayOfWeek,
  *   from 1 to 31 adjusted later, or -1 to -28 adjusted earlier from the last day of the month
  * @param DayOfWeek|null $dayOfWeek the day-of-week to adjust to, null if day-of-month should not be adjusted
  * @param LocalTime $time the time that the transition occurs as defined by timeDefintion, not null
  * @param bool $timeEndOfDay whether midnight is at the end of day
  * @param TimeDefinition $timeDefinition the definition of how to convert local to actual time, not null
  * @param int $savingAmountSecs the amount of saving from the standard offset after the transition in seconds
  * @return ZoneRulesBuilder $this, for chaining
  * @throws DateTimeException if a date-time field is out of range
  * @throws IllegalArgumentException if the day of month indicator is invalid
  * @throws IllegalArgumentException if the end of day midnight flag does not match the time
  * @throws \LogicException if no window has yet been added
  * @throws \LogicException if the window already has fixed savings
  * @throws \LogicException if the window has reached the maximum capacity of 2000 rules
  */
 public function addRuleToWindow9($startYear, $endYear, Month $month, $dayOfMonthIndicator, $dayOfWeek, LocalTime $time, $timeEndOfDay, TimeDefinition $timeDefinition, $savingAmountSecs)
 {
     ChronoField::YEAR()->checkValidValue($startYear);
     ChronoField::YEAR()->checkValidValue($endYear);
     if ($dayOfMonthIndicator < -28 || $dayOfMonthIndicator > 31 || $dayOfMonthIndicator === 0) {
         throw new IllegalArgumentException("Day of month indicator must be between -28 and 31 inclusive excluding zero");
     }
     if ($timeEndOfDay && $time->equals(LocalTime::MIDNIGHT()) == false) {
         throw new IllegalArgumentException("Time must be midnight when end of day flag is true");
     }
     if (empty($this->windowList)) {
         throw new \LogicException("Must add a window before adding a rule");
     }
     $window = $this->windowList[count($this->windowList) - 1];
     $window->addRule($startYear, $endYear, $month, $dayOfMonthIndicator, $dayOfWeek, $time, $timeEndOfDay, $timeDefinition, $savingAmountSecs);
     return $this;
 }
예제 #28
0
 public function test_with_TemporalField_long_normal()
 {
     $t = self::TEST_2007_07_15()->with(CF::YEAR(), 2008);
     $this->assertEquals($t, LocalDate::of(2008, 7, 15));
 }
 public function range(ChronoField $field)
 {
     switch ($field) {
         case CF::PROLEPTIC_MONTH():
             $range = CF::PROLEPTIC_MONTH()->range();
             return ValueRange::of($range->getMinimum() + self::YEARS_DIFFERENCE * 12, $range->getMaximum() + self::YEARS_DIFFERENCE * 12);
         case CF::YEAR_OF_ERA():
             $range = CF::YEAR()->range();
             return ValueRange::ofVariable(1, -($range->getMinimum() + self::YEARS_DIFFERENCE) + 1, $range->getMaximum() + self::YEARS_DIFFERENCE);
         case CF::YEAR():
             $range = CF::YEAR()->range();
             return ValueRange::of($range->getMinimum() + self::YEARS_DIFFERENCE, $range->getMaximum() + self::YEARS_DIFFERENCE);
     }
     return $field->range();
 }
 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]];
 }