예제 #1
0
 public function adjustToFowards($year)
 {
     if ($this->adjustForwards === false && $this->dayOfMonth > 0) {
         $adjustedDate = LocalDate::ofMonth($year, $this->month, $this->dayOfMonth)->minusDays(6);
         $this->dayOfMonth = $adjustedDate->getDayOfMonth();
         $this->month = $adjustedDate->getMonth();
         $this->adjustForwards = true;
     }
 }
예제 #2
0
 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;
 }
 public function test_getDayOfWeek()
 {
     $dow = DayOfWeek::MONDAY();
     foreach (Month::values() as $month) {
         $length = $month->length(false);
         for ($i = 1; $i <= $length; $i++) {
             $d = LocalDateTime::ofDateAndTime(LocalDate::ofMonth(2007, $month, $i), self::TEST_200707_15_12_30_40_987654321()->toLocalTime());
             $this->assertSame($d->getDayOfWeek(), $dow);
             $dow = $dow->plus(1);
         }
     }
 }
예제 #4
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);
         }
     }
 }
예제 #5
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;
 }
 /**
  * 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);
 }
예제 #7
0
 /**
  * Obtains an instance of {@code LocalDateTime} from year, month,
  * day, hour, minute, second and nanosecond.
  * <p>
  * This returns a {@code LocalDateTime} with the specified year, month,
  * day-of-month, hour, minute, second and nanosecond.
  * The day must be valid for the year and month, otherwise an exception will be thrown.
  *
  * @param int $year the year to represent, from MIN_YEAR to MAX_YEAR
  * @param Month $month the month-of-year to represent, not null
  * @param int $dayOfMonth the day-of-month to represent, from 1 to 31
  * @param int $hour the hour-of-day to represent, from 0 to 23
  * @param int $minute the minute-of-hour to represent, from 0 to 59
  * @param int $second the second-of-minute to represent, from 0 to 59
  * @param int $nanoOfSecond the nano-of-second to represent, from 0 to 999,999,999
  * @return LocalDateTime the local date-time, not null
  * @throws DateTimeException if the value of any field is out of range,
  *  or if the day-of-month is invalid for the month-year
  */
 public static function ofMonth($year, Month $month, $dayOfMonth, $hour, $minute, $second = 0, $nanoOfSecond = 0)
 {
     $date = LocalDate::ofMonth($year, $month, $dayOfMonth);
     $time = LocalTime::of($hour, $minute, $second, $nanoOfSecond);
     return new LocalDateTime($date, $time);
 }
 private function date($year, Month $month, $day)
 {
     return LocalDate::ofMonth($year, $month, $day);
 }