コード例 #1
0
ファイル: Instant.php プロジェクト: brick/date-time
 /**
  * @param integer $days
  *
  * @return Instant
  */
 public function minusDays($days)
 {
     $days = Cast::toInteger($days);
     return $this->plusDays(-$days);
 }
コード例 #2
0
ファイル: Period.php プロジェクト: brick/date-time
 /**
  * Returns a new Period with each value multiplied by the given scalar.
  *
  * @param integer $scalar
  *
  * @return Period
  */
 public function multipliedBy($scalar)
 {
     $scalar = Cast::toInteger($scalar);
     if ($scalar === 1) {
         return $this;
     }
     return new Period($this->years * $scalar, $this->months * $scalar, $this->days * $scalar);
 }
コード例 #3
0
ファイル: LocalDateTime.php プロジェクト: brick/date-time
 /**
  * Returns a copy of this LocalDateTime with the specified period in nanoseconds subtracted.
  *
  * @param integer $nanos
  *
  * @return LocalDateTime
  */
 public function minusNanos($nanos)
 {
     $nanos = Cast::toInteger($nanos);
     if ($nanos === 0) {
         return $this;
     }
     return $this->plusWithOverflow(0, 0, 0, $nanos, -1);
 }
コード例 #4
0
ファイル: YearMonth.php プロジェクト: brick/date-time
 /**
  * Returns a copy of this YearMonth with the specified period in years added.
  *
  * @param integer $years
  *
  * @return YearMonth
  */
 public function plusYears($years)
 {
     $years = Cast::toInteger($years);
     if ($years === 0) {
         return $this;
     }
     return $this->withYear($this->year + $years);
 }
コード例 #5
0
ファイル: LocalDate.php プロジェクト: brick/date-time
 /**
  * Returns a copy of this LocalDate with the specified period in days added.
  *
  * @param integer $days
  *
  * @return LocalDate
  */
 public function plusDays($days)
 {
     $days = Cast::toInteger($days);
     if ($days === 0) {
         return $this;
     }
     return LocalDate::ofEpochDay($this->toEpochDay() + $days);
 }
コード例 #6
0
ファイル: MonthDay.php プロジェクト: brick/date-time
 /**
  * Returns a copy of this MonthDay with the day-of-month altered.
  *
  * If the day-of-month is invalid for the month, an exception is thrown.
  *
  * @param integer $day
  *
  * @return MonthDay
  *
  * @throws DateTimeException If the day-of-month is invalid for the month.
  */
 public function withDay($day)
 {
     $day = Cast::toInteger($day);
     if ($day === $this->day) {
         return $this;
     }
     Field\DayOfMonth::check($day, $this->month);
     return new MonthDay($this->month, $day);
 }
コード例 #7
0
ファイル: TimeZoneOffset.php プロジェクト: brick/date-time
 /**
  * Obtains an instance of `TimeZoneOffset` specifying the total offset in seconds.
  *
  * The offset must be in the range `-18:00` to `+18:00`, which corresponds to -64800 to +64800.
  *
  * @param integer $totalSeconds The total offset in seconds.
  *
  * @return TimeZoneOffset
  *
  * @throws DateTimeException
  */
 public static function ofTotalSeconds($totalSeconds)
 {
     $totalSeconds = Cast::toInteger($totalSeconds);
     Field\TimeZoneOffsetTotalSeconds::check($totalSeconds);
     return new TimeZoneOffset($totalSeconds);
 }
コード例 #8
0
ファイル: LocalTime.php プロジェクト: brick/date-time
 /**
  * Returns a copy of this LocalTime with the specified period in nanoseconds added.
  *
  * @param integer $nanos The seconds to add, may be negative.
  *
  * @return LocalTime A LocalTime based on this time with the nanoseconds added.
  */
 public function plusNanos($nanos)
 {
     $nanos = Cast::toInteger($nanos);
     if ($nanos === 0) {
         return $this;
     }
     $divBase = Math::floorDiv($this->nano, LocalTime::NANOS_PER_SECOND);
     $modBase = Math::floorMod($this->nano, LocalTime::NANOS_PER_SECOND);
     $divPlus = Math::floorDiv($nanos, LocalTime::NANOS_PER_SECOND);
     $modPlus = Math::floorMod($nanos, LocalTime::NANOS_PER_SECOND);
     $diffSeconds = $divBase + $divPlus;
     $nano = $modBase + $modPlus;
     if ($nano >= LocalTime::NANOS_PER_SECOND) {
         $nano -= LocalTime::NANOS_PER_SECOND;
         $diffSeconds++;
     }
     return $this->withNano($nano)->plusSeconds($diffSeconds);
 }
コード例 #9
0
ファイル: Duration.php プロジェクト: brick/date-time
 /**
  * Returns a copy of this Duration divided by the given value.
  *
  * If this yields an inexact result, the result will be rounded down.
  *
  * @param integer $divisor
  *
  * @return \Brick\DateTime\Duration
  */
 public function dividedBy($divisor)
 {
     $divisor = Cast::toInteger($divisor);
     if ($divisor === 0) {
         throw new DateTimeException('Cannot divide a Duration by zero.');
     }
     if ($divisor === 1) {
         return $this;
     }
     $seconds = $this->seconds;
     $nanos = $this->nanos;
     if ($seconds < 0 && $nanos !== 0) {
         $seconds++;
         $nanos -= LocalTime::NANOS_PER_SECOND;
     }
     $remainder = $seconds % $divisor;
     $seconds = intdiv($seconds, $divisor);
     $r1 = $nanos % $divisor;
     $nanos = intdiv($nanos, $divisor);
     $r2 = LocalTime::NANOS_PER_SECOND % $divisor;
     $nanos += $remainder * intdiv(LocalTime::NANOS_PER_SECOND, $divisor);
     $nanos += intdiv($r1 + $remainder * $r2, $divisor);
     if ($nanos < 0) {
         $seconds--;
         $nanos = LocalTime::NANOS_PER_SECOND + $nanos;
     }
     return new Duration($seconds, $nanos);
 }
コード例 #10
0
ファイル: CastTest.php プロジェクト: brick/date-time
 /**
  * @dataProvider providerToIntegerThrowsException
  * @expectedException \InvalidArgumentException
  *
  * @param mixed $value The invalid value.
  */
 public function testToIntegerThrowsException($value)
 {
     Cast::toInteger($value);
 }
コード例 #11
0
ファイル: Year.php プロジェクト: brick/date-time
 /**
  * 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);
 }
コード例 #12
0
ファイル: Month.php プロジェクト: brick/date-time
 /**
  * Returns the month that is the specified number of months before this one.
  *
  * The calculation rolls around the start of the year from January to December.
  * The specified period may be negative.
  *
  * @param integer $months
  *
  * @return Month
  */
 public function minus($months)
 {
     $months = Cast::toInteger($months);
     return $this->plus(-$months);
 }