コード例 #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
ファイル: TimeZone.php プロジェクト: brick/date-time
 /**
  * Obtains an instance of `TimeZone` from a string representation.
  *
  * @param string $text
  *
  * @return TimeZone
  *
  * @throws \Brick\DateTime\Parser\DateTimeParseException
  */
 public static function parse($text)
 {
     $text = (string) $text;
     if ($text === 'Z' || $text === 'z') {
         return TimeZoneOffset::utc();
     }
     if ($text === '') {
         throw new DateTimeParseException('The string is empty.');
     }
     if ($text[0] === '+' || $text[0] === '-') {
         return TimeZoneOffset::parse($text);
     }
     return TimeZoneRegion::parse($text);
 }
コード例 #3
0
 /**
  * @dataProvider providerParseInvalidStringThrowsException
  * @expectedException \Brick\DateTime\Parser\DateTimeParseException
  *
  * @param string $text
  */
 public function testParseInvalidStringThrowsException($text)
 {
     TimeZoneRegion::parse($text);
 }