コード例 #1
0
ファイル: DateTimeConverter.php プロジェクト: brick/brick
 /**
  * {@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;
 }
コード例 #2
0
ファイル: DurationTest.php プロジェクト: brick/date-time
 /**
  * @dataProvider providerParseFailureThrowsException
  * @expectedException \Brick\DateTime\Parser\DateTimeParseException
  *
  * @param string $text The string to test.
  */
 public function testParseFailureThrowsException($text)
 {
     Duration::parse($text);
 }
コード例 #3
0
ファイル: OffsetClockTest.php プロジェクト: brick/date-time
 /**
  * @dataProvider providerOffsetClock
  *
  * @param integer $second         The epoch second to set the base clock to.
  * @param integer $nano           The nano to set the base clock to.
  * @param string  $duration       A parsable duration string.
  * @param integer $expectedSecond The expected epoch second returned by the clock.
  * @param integer $expectedNano   The expected nano returned by the clock.
  */
 public function testOffsetClock($second, $nano, $duration, $expectedSecond, $expectedNano)
 {
     $baseClock = new FixedClock(Instant::of($second, $nano));
     $clock = new OffsetClock($baseClock, Duration::parse($duration));
     $this->assertReadableInstantIs($expectedSecond, $expectedNano, $clock->getTime());
 }