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; }
/** * @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_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); } } } } }