Пример #1
0
 /**
  * @return LocalDate
  */
 private function toLocalDate()
 {
     if ($this->dayOfMonthIndicator < 0) {
         $monthLen = $this->month->length(IsoChronology::INSTANCE()->isLeapYear($this->year));
         $date = LocalDate::ofMonth($this->year, $this->month, $monthLen + 1 + $this->dayOfMonthIndicator);
         if ($this->dayOfWeek !== null) {
             $date = $date->adjust(TemporalAdjusters::previousOrSame($this->dayOfWeek));
         }
     } else {
         $date = LocalDate::ofMonth($this->year, $this->month, $this->dayOfMonthIndicator);
         if ($this->dayOfWeek != null) {
             $date = $date->adjust(TemporalAdjusters::nextOrSame($this->dayOfWeek));
         }
     }
     if ($this->timeEndOfDay) {
         $date = $date->plusDays(1);
     }
     return $date;
 }
Пример #2
0
 public function test_with_Month_noChange_equal()
 {
     $test = YearMonth::of(2008, 6);
     $this->assertEquals($test->adjust(Month::JUNE()), $test);
 }
Пример #3
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);
 }
Пример #4
0
 public function __construct()
 {
     $this->month = Month::JANUARY();
     $this->time = LocalTime::MIDNIGHT();
     $this->timeDefinition = TimeDefinition::WALL();
 }
 public function test_with_adjustment_Month()
 {
     $test = self::TEST_2008_6_30_11_30_59_000000500()->adjust(Month::DECEMBER());
     $this->assertEquals($test, OffsetDateTime::ofDateAndTime(LocalDate::of(2008, 12, 30), LocalTime::of(11, 30, 59, 500), self::OFFSET_PONE()));
 }
Пример #6
0
 public function test_getDayOfWeek()
 {
     $dow = DayOfWeek::MONDAY();
     foreach (Month::values() as $month) {
         $length = $month->length(false);
         for ($i = 1; $i <= $length; $i++) {
             $d = LocalDate::ofMonth(2007, $month, $i);
             $this->assertSame($d->getDayOfWeek(), $dow);
             $dow = $dow->plus(1);
         }
     }
 }
Пример #7
0
 public function test_enum()
 {
     $this->assertEquals(Month::valueOf("JANUARY"), Month::JANUARY());
     $this->assertEquals(Month::values()[0], Month::JANUARY());
 }
Пример #8
0
 /**
  * Gets the month-of-year field using the {@code Month} enum.
  * <p>
  * This method returns the enum {@link Month} for the month.
  * This avoids confusion as to what {@code int} values mean.
  * If you need access to the primitive {@code int} value then the enum
  * provides the {@link Month#getValue() int value}.
  *
  * @return Month the month-of-year, not null
  * @see #getMonthValue()
  */
 public function getMonth()
 {
     return Month::of($this->month);
 }
 /**
  * Creates a transition instance for the specified year.
  * <p>
  * Calculations are performed using the ISO-8601 chronology.
  *
  * @param int $year the year to create a transition for, not null
  * @return ZoneOffsetTransition the transition instance, not null
  */
 public function createTransition($year)
 {
     if ($this->dom < 0) {
         $date = LocalDate::ofMonth($year, $this->month, $this->month->length(IsoChronology::INSTANCE()->isLeapYear($year)) + 1 + $this->dom);
         if ($this->dow !== null) {
             $date = $date->adjust(TemporalAdjusters::previousOrSame($this->dow));
         }
     } else {
         $date = LocalDate::ofMonth($year, $this->month, $this->dom);
         if ($this->dow !== null) {
             $date = $date->adjust(TemporalAdjusters::nextOrSame($this->dow));
         }
     }
     if ($this->timeEndOfDay) {
         $date = $date->plusDays(1);
     }
     $localDT = LocalDateTime::ofDateAndTime($date, $this->time);
     $transition = $this->timeDefinition->createDateTime($localDT, $this->standardOffset, $this->offsetBefore);
     return ZoneOffsetTransition::of($transition, $this->offsetBefore, $this->offsetAfter);
 }
 public function test_toString_fixedDate()
 {
     $test = ZoneOffsetTransitionRule::of(Month::MARCH(), 20, null, self::TIME_0100(), false, TimeDefinition::STANDARD(), self::OFFSET_0200(), self::OFFSET_0200(), self::OFFSET_0300());
     $this->assertEquals($test->__toString(), "TransitionRule[Gap +02:00 to +03:00, MARCH 20 at 01:00 STANDARD, standard offset +02:00]");
 }
 private function parseMonth(\CachingIterator $s)
 {
     $s->next();
     $month = $s->current();
     if ($m = preg_match(self::$MONTH, $month, $mr)) {
         for ($moy = 1; $moy < 13 && $moy < count($mr); $moy++) {
             if ($mr[$moy] !== '') {
                 return Month::of($moy);
             }
         }
     }
     throw new IllegalArgumentException("Unknown month: " . $month);
 }
Пример #12
0
 /**
  * Returns a copy of this {@code MonthDay} with the month-of-year altered.
  * <p>
  * This returns a month-day with the specified month.
  * If the day-of-month is invalid for the specified month, the day will
  * be adjusted to the last valid day-of-month.
  * <p>
  * This instance is immutable and unaffected by this method call.
  *
  * @param Month $month the month-of-year to set in the returned month-day, not null
  * @return MonthDay a {@code MonthDay} based on this month-day with the requested month, not null
  */
 public function with(Month $month)
 {
     if ($month->getValue() == $this->month) {
         return $this;
     }
     $day = Math::min($this->day, $month->maxLength());
     return new MonthDay($month->getValue(), $day);
 }
Пример #13
0
     * </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::MONTH_OF_YEAR(), $this->getValue());
    }
    public function __toString()
    {
        return $this->name;
    }
    public function compareTo(Month $other)
    {
        return $this->val - $other->val;
    }
    public function name()
    {
        return $this->__toString();
    }
}
Month::init();
Пример #14
0
 public function test_atMonth()
 {
     $test = Year::of(2008);
     $this->assertEquals($test->atMonth(Month::JUNE()), YearMonth::of(2008, 6));
 }
 public function test_pattern_String()
 {
     $test = DateTimeFormatter::ofPattern("d MMM yyyy");
     $fmtLocale = Locale::getDefault();
     $this->assertEquals($test->format(LocalDate::of(2012, 6, 30)), "30 " . Month::JUNE()->getDisplayName(TextStyle::SHORT(), $fmtLocale) . " 2012");
     $this->assertEquals($test->getLocale(), $fmtLocale, "Locale.Category.FORMAT");
 }
Пример #16
0
 function data_adjustInto()
 {
     return [[LocalDateTime::of(2012, 3, 4, 23, 5), LocalDateTime::of(2012, 3, 4, 1, 1, 1, 100), LocalDateTime::of(2012, 3, 4, 23, 5, 0, 0), null], [LocalDateTime::ofMonth(2012, Month::MARCH(), 4, 0, 0), LocalDateTime::of(2012, 3, 4, 1, 1, 1, 100), LocalDateTime::of(2012, 3, 4, 0, 0), null], [LocalDateTime::of(2012, 3, 4, 23, 5), LocalDateTime::MAX(), LocalDateTime::of(2012, 3, 4, 23, 5), null], [LocalDateTime::of(2012, 3, 4, 23, 5), LocalDateTime::MIN(), LocalDateTime::of(2012, 3, 4, 23, 5), null], [LocalDateTime::MAX(), LocalDateTime::of(2012, 3, 4, 23, 5), LocalDateTime::MAX(), null], [LocalDateTime::MIN(), LocalDateTime::of(2012, 3, 4, 23, 5), LocalDateTime::MIN(), null], [LocalDateTime::of(2012, 3, 4, 23, 5), OffsetDateTime::of(2210, 2, 2, 0, 0, 0, 0, ZoneOffset::UTC()), OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, ZoneOffset::UTC()), null], [LocalDateTime::of(2012, 3, 4, 23, 5), OffsetDateTime::of(2210, 2, 2, 0, 0, 0, 0, self::OFFSET_PONE()), OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), null], [LocalDateTime::of(2012, 3, 4, 23, 5), ZonedDateTime::of(2210, 2, 2, 0, 0, 0, 0, self::ZONE_PARIS()), ZonedDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::ZONE_PARIS()), null], [LocalDateTime::of(2012, 3, 4, 23, 5), LocalDate::of(2210, 2, 2), null, DateTimeException::class], [LocalDateTime::of(2012, 3, 4, 23, 5), LocalTime::of(22, 3, 0), null, DateTimeException::class], [LocalDateTime::of(2012, 3, 4, 23, 5), OffsetTime::of(22, 3, 0, 0, ZoneOffset::UTC()), null, DateTimeException::class]];
 }
Пример #17
0
 public function test_withMonth_Month_normal()
 {
     $base = ZonedDateTime::ofDateTime(self::TEST_LOCAL_2008_06_30_11_30_59_500(), self::ZONE_0100());
     $test = $base->adjust(Month::JANUARY());
     $this->assertEquals($test, ZonedDateTime::ofDateTime(self::TEST_LOCAL_2008_06_30_11_30_59_500()->withMonth(1), self::ZONE_0100()));
 }
Пример #18
0
 public function test_with_Month_noChangeEqual()
 {
     $test = MonthDay::of(6, 30);
     $this->assertEquals($test->with(Month::JUNE()), $test);
 }
Пример #19
0
 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_previousOrCurrent()
 {
     foreach (Month::values() as $month) {
         for ($i = 1; $i <= $month->length(false); $i++) {
             $date = self::date(2007, $month, $i);
             foreach (DayOfWeek::values() as $dow) {
                 $test = TemporalAdjusters::previousOrSame($dow)->adjustInto($date);
                 $this->assertSame($test->getDayOfWeek(), $dow);
                 if ($test->getYear() == 2007) {
                     $dayDiff = $test->getDayOfYear() - $date->getDayOfYear();
                     $this->assertTrue($dayDiff <= 0 && $dayDiff > -7);
                     $this->assertEquals($date->equals($test), $date->getDayOfWeek() == $dow);
                 } else {
                     $this->assertFalse($date->getDayOfWeek() == $dow);
                     $this->assertSame($month, Month::JANUARY());
                     $this->assertTrue($date->getDayOfMonth() < 7);
                     $this->assertEquals($test->getYear(), 2006);
                     $this->assertSame($test->getMonth(), Month::DECEMBER());
                     $this->assertTrue($test->getDayOfMonth() > 25);
                 }
             }
         }
     }
 }