Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function getId()
 {
     if ($this->id === null) {
         if ($this->totalSeconds < 0) {
             $this->id = '-' . LocalTime::ofSecondOfDay(-$this->totalSeconds);
         } elseif ($this->totalSeconds > 0) {
             $this->id = '+' . LocalTime::ofSecondOfDay($this->totalSeconds);
         } else {
             $this->id = 'Z';
         }
     }
     return $this->id;
 }
Esempio n. 2
0
 /**
  * Returns a copy of this `LocalDateTime` with the specified period added.
  *
  * @param integer $hours   The hours to add, validated as an integer. May be negative.
  * @param integer $minutes The minutes to add, validated as an integer. May be negative.
  * @param integer $seconds The seconds to add, validated as an integer. May be negative.
  * @param integer $nanos   The nanos to add, validated as an integer. May be negative.
  * @param integer $sign    The sign, validated as an integer of value `1` to add or `-1` to subtract.
  *
  * @return LocalDateTime The combined result.
  */
 private function plusWithOverflow($hours, $minutes, $seconds, $nanos, $sign)
 {
     $totDays = intdiv($hours, LocalTime::HOURS_PER_DAY) + intdiv($minutes, LocalTime::MINUTES_PER_DAY) + intdiv($seconds, LocalTime::SECONDS_PER_DAY);
     $totDays *= $sign;
     $totSeconds = $seconds % LocalTime::SECONDS_PER_DAY + $minutes % LocalTime::MINUTES_PER_DAY * LocalTime::SECONDS_PER_MINUTE + $hours % LocalTime::HOURS_PER_DAY * LocalTime::SECONDS_PER_HOUR;
     $curSoD = $this->time->toSecondOfDay();
     $totSeconds = $totSeconds * $sign + $curSoD;
     $totNanos = $nanos * $sign + $this->time->getNano();
     $totSeconds += Math::floorDiv($totNanos, LocalTime::NANOS_PER_SECOND);
     $newNano = Math::floorMod($totNanos, LocalTime::NANOS_PER_SECOND);
     $totDays += Math::floorDiv($totSeconds, LocalTime::SECONDS_PER_DAY);
     $newSoD = Math::floorMod($totSeconds, LocalTime::SECONDS_PER_DAY);
     $newTime = $newSoD === $curSoD ? $this->time : LocalTime::ofSecondOfDay($newSoD, $newNano);
     return $this->with($this->date->plusDays($totDays), $newTime);
 }
Esempio n. 3
0
 /**
  * @dataProvider providerOfInvalidSecondOfDayThrowsException
  * @expectedException \Brick\DateTime\DateTimeException
  *
  * @param integer $secondOfDay
  * @param integer $nanoOfSecond
  */
 public function testOfInvalidSecondOfDayThrowsException($secondOfDay, $nanoOfSecond)
 {
     LocalTime::ofSecondOfDay($secondOfDay, $nanoOfSecond);
 }