Пример #1
0
 /**
  * Parses a time-zone offset.
  *
  * The following ISO 8601 formats are accepted:
  * 
  * * `Z` - for UTC
  * * `±hh:mm`
  * * `±hh:mm:ss`
  *
  * Note that ± means either the plus or minus symbol.
  *
  * @param string              $text
  * @param DateTimeParser|null $parser
  *
  * @return TimeZoneOffset
  *
  * @throws DateTimeParseException
  */
 public static function parse($text, DateTimeParser $parser = null)
 {
     if (!$parser) {
         $parser = IsoParsers::timeZoneOffset();
     }
     return TimeZoneOffset::from($parser->parse($text));
 }
Пример #2
0
 /**
  * Obtains an instance of `ZonedDateTime` from a set of date-time fields.
  *
  * This method is only useful to parsers.
  *
  * @param DateTimeParseResult $result
  *
  * @return ZonedDateTime
  *
  * @throws DateTimeException      If the zoned date-time is not valid.
  * @throws DateTimeParseException If required fields are missing from the result.
  */
 public static function from(DateTimeParseResult $result)
 {
     $localDateTime = LocalDateTime::from($result);
     $timeZoneOffset = TimeZoneOffset::from($result);
     if ($result->hasField(Field\TimeZoneRegion::NAME)) {
         $timeZone = TimeZoneRegion::from($result);
     } else {
         $timeZone = $timeZoneOffset;
     }
     return ZonedDateTime::of($localDateTime, $timeZone, $timeZoneOffset);
 }