public function test_of()
 {
     //used for standard offset
     $stdOffset1 = ZoneOffset::UTC();
     $stdOffset2 = ZoneOffset::ofHours(1);
     $time_of_stdOffsetTransition1 = LocalDateTime::of(2013, 1, 5, 1, 0);
     $stdOffsetTransition1 = ZoneOffsetTransition::of($time_of_stdOffsetTransition1, $stdOffset1, $stdOffset2);
     $stdOffsetTransition_list = [];
     $stdOffsetTransition_list[] = $stdOffsetTransition1;
     //used for wall offset
     $wallOffset1 = ZoneOffset::ofHours(2);
     $wallOffset2 = ZoneOffset::ofHours(4);
     $wallOffset3 = ZoneOffset::ofHours(7);
     $time_of_wallOffsetTransition1 = LocalDateTime::of(2013, 2, 5, 1, 0);
     $time_of_wallOffsetTransition2 = LocalDateTime::of(2013, 3, 5, 1, 0);
     $time_of_wallOffsetTransition3 = LocalDateTime::of(2013, 10, 5, 1, 0);
     $wallOffsetTransition1 = ZoneOffsetTransition::of($time_of_wallOffsetTransition1, $wallOffset1, $wallOffset2);
     $wallOffsetTransition2 = ZoneOffsetTransition::of($time_of_wallOffsetTransition2, $wallOffset2, $wallOffset3);
     $wallOffsetTransition3 = ZoneOffsetTransition::of($time_of_wallOffsetTransition3, $wallOffset3, $wallOffset1);
     $wallOffsetTransition_list = [];
     $wallOffsetTransition_list[] = $wallOffsetTransition1;
     $wallOffsetTransition_list[] = $wallOffsetTransition2;
     $wallOffsetTransition_list[] = $wallOffsetTransition3;
     //used for ZoneOffsetTransitionRule
     $ruleOffset = ZoneOffset::ofHours(3);
     $timeDefinition = TimeDefinition::WALL();
     $rule1 = ZoneOffsetTransitionRule::of(Month::FEBRUARY(), 2, DayOfWeek::MONDAY(), LocalTime::of(1, 0), false, $timeDefinition, ZoneOffset::UTC(), ZoneOffset::UTC(), $ruleOffset);
     $rule_list = [];
     $rule_list[] = $rule1;
     //Begin verification
     $zoneRule = ZoneRules::of($stdOffset1, $wallOffset1, $stdOffsetTransition_list, $wallOffsetTransition_list, $rule_list);
     $before_time_of_stdOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_stdOffsetTransition1, $stdOffset1)->minusSeconds(1);
     $after_time_of_stdOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_stdOffsetTransition1, $stdOffset1)->plusSeconds(1);
     $this->assertEquals($zoneRule->getStandardOffset($before_time_of_stdOffsetTransition1->toInstant()), $stdOffset1);
     $this->assertEquals($zoneRule->getStandardOffset($after_time_of_stdOffsetTransition1->toInstant()), $stdOffset2);
     $before_time_of_wallOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition1, $wallOffset1)->minusSeconds(1);
     $after_time_of_wallOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition1, $wallOffset1)->plusSeconds(1);
     $this->assertEquals($zoneRule->nextTransition($before_time_of_wallOffsetTransition1->toInstant()), $wallOffsetTransition1);
     $this->assertEquals($zoneRule->nextTransition($after_time_of_wallOffsetTransition1->toInstant()), $wallOffsetTransition2);
     $before_time_of_wallOffsetTransition2 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition2, $wallOffset2)->minusSeconds(1);
     $after_time_of_wallOffsetTransition2 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition2, $wallOffset2)->plusSeconds(1);
     $this->assertEquals($zoneRule->nextTransition($before_time_of_wallOffsetTransition2->toInstant()), $wallOffsetTransition2);
     $this->assertEquals($zoneRule->nextTransition($after_time_of_wallOffsetTransition2->toInstant()), $wallOffsetTransition3);
     $before_time_of_wallOffsetTransition3 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition3, $wallOffset3)->minusSeconds(1);
     $after_time_of_wallOffsetTransition3 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition3, $wallOffset3)->plusSeconds(1);
     $this->assertEquals($zoneRule->nextTransition($before_time_of_wallOffsetTransition3->toInstant()), $wallOffsetTransition3);
     $this->assertEquals($zoneRule->nextTransition($after_time_of_wallOffsetTransition3->toInstant()), $rule1->createTransition(2014));
 }
 public function test_factory_intsMonth()
 {
     $test = YearMonth::ofMonth(2008, Month::FEBRUARY());
     $this->check($test, 2008, 2);
 }
Beispiel #3
0
 /**
  * Gets the range of valid values for the specified field.
  * <p>
  * The range object expresses the minimum and maximum valid values for a field.
  * This date is used to enhance the accuracy of the returned range.
  * If it is not possible to return the range, because the field is not supported
  * or for some other reason, an exception is thrown.
  * <p>
  * If the field is a {@link ChronoField} then the query is implemented here.
  * The {@link #isSupported(TemporalField) supported fields} will return
  * appropriate range instances.
  * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.
  * <p>
  * If the field is not a {@code ChronoField}, then the result of this method
  * is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessor)}
  * passing {@code this} as the argument.
  * Whether the range can be obtained is determined by the field.
  *
  * @param TemporalField $field the field to query the range for, not null
  * @return ValueRange the range of valid values for the field, not null
  * @throws DateTimeException if the range for the field cannot be obtained
  * @throws UnsupportedTemporalTypeException if the field is not supported
  */
 public function range(TemporalField $field)
 {
     if ($field instanceof ChronoField) {
         /** @var ChronoField $f */
         $f = $field;
         if ($f->isDateBased()) {
             switch ($f) {
                 case ChronoField::DAY_OF_MONTH():
                     return ValueRange::of(1, $this->lengthOfMonth());
                 case ChronoField::DAY_OF_YEAR():
                     return ValueRange::of(1, $this->lengthOfYear());
                 case ChronoField::ALIGNED_WEEK_OF_MONTH():
                     return ValueRange::of(1, $this->getMonth() == Month::FEBRUARY() && $this->isLeapYear() == false ? 4 : 5);
                 case ChronoField::YEAR_OF_ERA():
                     return $this->getYear() <= 0 ? ValueRange::of(1, Year::MAX_VALUE + 1) : ValueRange::of(1, Year::MAX_VALUE);
             }
             return $field->range();
         }
         throw new UnsupportedTemporalTypeException("Unsupported field: " . $field);
     }
     return $field->rangeRefinedBy($this);
 }
 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);
 }
 /**
  * @expectedException \Celest\DateTimeException
  */
 public function test_factory_of_intsMonth_29febNonLeap()
 {
     LocalDate::ofMonth(2007, Month::FEBRUARY(), 29);
 }
 public function test_with_Month_adjustToValidFeb()
 {
     $this->assertEquals(MonthDay::of(7, 31)->with(Month::FEBRUARY()), MonthDay::of(2, 29));
 }
Beispiel #7
0
 /**
  * Converts this to a transition rule.
  *
  * @param ZoneOffset $standardOffset the active standard offset, not null
  * @param int $savingsBeforeSecs the active savings before the transition in seconds
  * @return ZoneOffsetTransitionRule the transition, not null
  */
 function toTransitionRule(ZoneOffset $standardOffset, $savingsBeforeSecs)
 {
     // optimize stored format
     if ($this->dayOfMonthIndicator < 0) {
         if ($this->month != Month::FEBRUARY()) {
             $this->dayOfMonthIndicator = $this->month->maxLength() - 6;
         }
     }
     if ($this->timeEndOfDay && $this->dayOfMonthIndicator > 0 && ($this->dayOfMonthIndicator === 28 && $this->month == Month::FEBRUARY()) == false) {
         $date = LocalDate::ofMonth(2004, $this->month, $this->dayOfMonthIndicator)->plusDays(1);
         // leap-year
         $this->month = $date->getMonth();
         $this->dayOfMonthIndicator = $date->getDayOfMonth();
         if ($this->dayOfWeek !== null) {
             $this->dayOfWeek = $this->dayOfWeek->plus(1);
         }
         $this->timeEndOfDay = false;
     }
     // build rule
     $trans = $this->toTransition($standardOffset, $savingsBeforeSecs);
     return ZoneOffsetTransitionRule::of($this->month, $this->dayOfMonthIndicator, $this->dayOfWeek, $this->time, $this->timeEndOfDay, $this->timeDefinition, $standardOffset, $trans->getOffsetBefore(), $trans->getOffsetAfter());
 }
Beispiel #8
0
 public function test_toString()
 {
     $this->assertEquals(Month::JANUARY()->__toString(), "JANUARY");
     $this->assertEquals(Month::FEBRUARY()->__toString(), "FEBRUARY");
     $this->assertEquals(Month::MARCH()->__toString(), "MARCH");
     $this->assertEquals(Month::APRIL()->__toString(), "APRIL");
     $this->assertEquals(Month::MAY()->__toString(), "MAY");
     $this->assertEquals(Month::JUNE()->__toString(), "JUNE");
     $this->assertEquals(Month::JULY()->__toString(), "JULY");
     $this->assertEquals(Month::AUGUST()->__toString(), "AUGUST");
     $this->assertEquals(Month::SEPTEMBER()->__toString(), "SEPTEMBER");
     $this->assertEquals(Month::OCTOBER()->__toString(), "OCTOBER");
     $this->assertEquals(Month::NOVEMBER()->__toString(), "NOVEMBER");
     $this->assertEquals(Month::DECEMBER()->__toString(), "DECEMBER");
 }