예제 #1
0
 /**
  * Returns a copy of this LocalDate with the month-of-year altered.
  *
  * If the day-of-month is invalid for the month and year, it will be changed to the last valid day of the month.
  *
  * @param integer $month
  *
  * @return LocalDate
  *
  * @throws DateTimeException If the month is invalid.
  */
 public function withMonth($month)
 {
     $month = Cast::toInteger($month);
     if ($month === $this->month) {
         return $this;
     }
     Field\MonthOfYear::check($month);
     return $this->resolvePreviousValid($this->year, $month, $this->day);
 }
예제 #2
0
 /**
  * Returns a copy of this MonthDay with the month-of-year altered.
  *
  * If the day-of-month is invalid for the specified month, the day will
  * be adjusted to the last valid day-of-month.
  *
  * @param integer $month
  *
  * @return MonthDay
  *
  * @throws DateTimeException If the month is invalid.
  */
 public function withMonth($month)
 {
     $month = Cast::toInteger($month);
     if ($month === $this->month) {
         return $this;
     }
     Field\MonthOfYear::check($month);
     $lastDay = Field\MonthOfYear::getLength($month);
     return new MonthDay($month, $lastDay < $this->day ? $lastDay : $this->day);
 }
예제 #3
0
 /**
  * Returns a copy of this YearMonth with the month-of-year altered.
  *
  * @param integer $month
  *
  * @return YearMonth
  */
 public function withMonth($month)
 {
     $month = Cast::toInteger($month);
     if ($month === $this->month) {
         return $this;
     }
     Field\MonthOfYear::check($month);
     return new YearMonth($this->year, $month);
 }
예제 #4
0
파일: Month.php 프로젝트: brick/date-time
 /**
  * Returns an instance of Month for the given month value.
  *
  * @param integer $value The month number, from 1 (January) to 12 (December).
  *
  * @return Month The Month instance.
  *
  * @throws DateTimeException
  */
 public static function of($value)
 {
     $value = Cast::toInteger($value);
     Field\MonthOfYear::check($value);
     return Month::get($value);
 }