Example #1
0
 /**
  * {@inheritdoc}
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null) {
         return null;
     }
     return LocalTime::parse($value);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function expand($className, $value, array $options = [])
 {
     try {
         switch ($className) {
             case Duration::class:
                 return Duration::parse($value);
             case LocalDate::class:
                 return LocalDate::parse($value);
             case LocalTime::class:
                 return LocalTime::parse($value);
             case LocalDateTime::class:
                 return LocalDateTime::parse($value);
             case TimeZoneOffset::class:
                 return TimeZoneOffset::parse($value);
             case TimeZoneRegion::class:
                 return TimeZoneRegion::parse($value);
             case YearMonth::class:
                 return YearMonth::parse($value);
             case ZonedDateTime::class:
                 return ZonedDateTime::parse($value);
         }
     } catch (DateTimeParseException $e) {
         throw new ObjectNotConvertibleException($e->getMessage(), $e->getCode(), $e);
     }
     return null;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function getField($field)
 {
     $value = $this->date->getField($field);
     if ($value !== null) {
         return $value;
     }
     return $this->time->getField($field);
 }
Example #4
0
 public function testAtTime()
 {
     $localDateTime = LocalDate::of(1, 2, 3)->atTime(LocalTime::of(4, 5, 6, 7));
     $this->assertLocalDateTimeIs(1, 2, 3, 4, 5, 6, 7, $localDateTime);
 }
Example #5
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;
 }
Example #6
0
 /**
  * Compares this LocalTime with another.
  *
  * @param LocalTime $that The time to compare to.
  *
  * @return integer [-1,0,1] If this time is before, on, or after the given time.
  */
 public function compareTo(LocalTime $that)
 {
     $seconds = $this->toSecondOfDay() - $that->toSecondOfDay();
     if ($seconds !== 0) {
         return $seconds > 0 ? 1 : -1;
     }
     $nanos = $this->nano - $that->nano;
     if ($nanos !== 0) {
         return $nanos > 0 ? 1 : -1;
     }
     return 0;
 }
Example #7
0
 /**
  * @expectedException \Brick\DateTime\DateTimeException
  */
 public function testMaxOfZeroElementsThrowsException()
 {
     LocalTime::maxOf();
 }
Example #8
0
 /**
  * @dataProvider providerDuration
  *
  * @param integer $ds The seconds of the duration.
  * @param integer $dn The nano adjustment of the duration.
  * @param integer $y  The expected year.
  * @param integer $m  The expected month.
  * @param integer $d  The expected day.
  * @param integer $h  The exepected hour.
  * @param integer $i  The expected minute.
  * @param integer $s  The expected second.
  * @param integer $n  The expected nano.
  */
 public function testMinusDuration($ds, $dn, $y, $m, $d, $h, $i, $s, $n)
 {
     $localDateTime = LocalDate::of(2001, 2, 3)->atTime(LocalTime::of(4, 5, 6, 123456789));
     $duration = Duration::ofSeconds(-$ds, -$dn);
     $this->assertLocalDateTimeIs($y, $m, $d, $h, $i, $s, $n, $localDateTime->minusDuration($duration));
 }
Example #9
0
 /**
  * @param integer   $hour   The expected hour.
  * @param integer   $minute The expected minute.
  * @param integer   $second The expected second.
  * @param integer   $nano   The expected nano-of-second.
  * @param LocalTime $time   The local time to test.
  */
 protected function assertLocalTimeIs($hour, $minute, $second, $nano, LocalTime $time)
 {
     $this->compare([$hour, $minute, $second, $nano], [$time->getHour(), $time->getMinute(), $time->getSecond(), $time->getNano()]);
 }