Ejemplo n.º 1
0
 /**
  * @internal
  * @param LocalDate $date
  * @return bool|int
  */
 public static function getWeek(LocalDate $date)
 {
     $dow0 = $date->getDayOfWeek()->getValue() - 1;
     $doy0 = $date->getDayOfYear() - 1;
     $doyThu0 = $doy0 + (3 - $dow0);
     // adjust to mid-week Thursday (which is 3 indexed from zero)
     $alignedWeek = Math::div($doyThu0, 7);
     $firstThuDoy0 = $doyThu0 - $alignedWeek * 7;
     $firstMonDoy0 = $firstThuDoy0 - 3;
     if ($firstMonDoy0 < -3) {
         $firstMonDoy0 += 7;
     }
     if ($doy0 < $firstMonDoy0) {
         return self::getWeekRange($date->withDayOfYear(180)->minusYears(1))->getMaximum();
     }
     $week = Math::div($doy0 - $firstMonDoy0, 7) + 1;
     if ($week == 53) {
         if (($firstMonDoy0 == -3 || $firstMonDoy0 == -2 && $date->isLeapYear()) == false) {
             $week = 1;
         }
     }
     return $week;
 }
Ejemplo n.º 2
0
 /**
  * Returns a copy of this {@code LocalDateTime} with the day-of-year altered.
  * <p>
  * If the resulting date-time is invalid, an exception is thrown.
  * <p>
  * This instance is immutable and unaffected by this method call.
  *
  * @param int $dayOfYear the day-of-year to set in the result, from 1 to 365-366
  * @return LocalDateTime a {@code LocalDateTime} based on this date with the requested day, not null
  * @throws DateTimeException if the day-of-year value is invalid,
  *  or if the day-of-year is invalid for the year
  */
 public function withDayOfYear($dayOfYear)
 {
     return $this->_with($this->date->withDayOfYear($dayOfYear), $this->time);
 }