private function toDateTime($year) { $this->adjustToFowards($year); if ($this->dayOfMonth === -1) { $dayOfMonth = $this->month->length(Year::isLeapYear($year)); $date = LocalDate::ofMonth($year, $this->month, $dayOfMonth); if ($this->dayOfWeek !== null) { $date = $date->adjust(TemporalAdjusters::previousOrSame($this->dayOfWeek)); } } else { $date = LocalDate::ofMonth($year, $this->month, $this->dayOfMonth); if ($this->dayOfWeek !== null) { $date = $date->adjust(TemporalAdjusters::nextOrSame($this->dayOfWeek)); } } $ldt = LocalDateTime::ofDateAndTime($date, $this->time); if ($this->endOfDay) { $ldt = $ldt->plusDays(1); } return $ldt; }
protected function resolveAligned(ChronoLocalDate $base, $months, $weeks, $dow) { $date = $base->plus($months, ChronoUnit::MONTHS())->plus($weeks, ChronoUnit::WEEKS()); if ($dow > 7) { $date = $date->plus(($dow - 1) / 7, ChronoUnit::WEEKS()); $dow = ($dow - 1) % 7 + 1; } else { if ($dow < 1) { $date = $date->plus(Math::subtractExact($dow, 7) / 7, ChronoUnit::WEEKS()); $dow = ($dow + 6) % 7 + 1; } } return $date->adjust(TemporalAdjusters::nextOrSame(DayOfWeek::of((int) $dow))); }
/** * @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; }
/** * 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_nextOrCurrent() { 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::nextOrSame($dow)->adjustInto($date); $this->assertSame($test->getDayOfWeek(), $dow); if ($test->getYear() == 2007) { $dayDiff = $test->getDayOfYear() - $date->getDayOfYear(); $this->assertTrue($dayDiff < 8); $this->assertEquals($date->equals($test), $date->getDayOfWeek() == $dow); } else { $this->assertFalse($date->getDayOfWeek() == $dow); $this->assertSame($month, Month::DECEMBER()); $this->assertTrue($date->getDayOfMonth() > 24); $this->assertEquals($test->getYear(), 2008); $this->assertSame($test->getMonth(), Month::JANUARY()); $this->assertTrue($test->getDayOfMonth() < 8); } } } } }