Beispiel #1
0
 /**
  * Returns a copy of this YearMonth with the year altered.
  *
  * @param integer $year
  *
  * @return YearMonth
  */
 public function withYear($year)
 {
     $year = Cast::toInteger($year);
     if ($year === $this->year) {
         return $this;
     }
     Field\Year::check($year);
     return new YearMonth($year, $this->month);
 }
Beispiel #2
0
 /**
  * Returns a copy of this LocalDate with the year altered.
  *
  * If the day-of-month is invalid for the year, it will be changed to the last valid day of the month.
  *
  * @param integer $year
  *
  * @return LocalDate
  *
  * @throws DateTimeException If the year is outside the valid range.
  */
 public function withYear($year)
 {
     $year = Cast::toInteger($year);
     if ($year === $this->year) {
         return $this;
     }
     Field\Year::check($year);
     return $this->resolvePreviousValid($year, $this->month, $this->day);
 }
Beispiel #3
0
 /**
  * Returns a copy of this year with the specified number of years subtracted.
  *
  * This instance is immutable and unaffected by this method call.
  *
  * @param integer $years The years to subtract, may be negative.
  *
  * @return Year A Year based on this year with the period subtracted.
  *
  * @throws DateTimeException If the resulting year exceeds the supported range.
  */
 public function minus($years)
 {
     $years = Cast::toInteger($years);
     if ($years === 0) {
         return $this;
     }
     $year = $this->year - $years;
     Field\Year::check($year);
     return new Year($year);
 }