Beispiel #1
0
 /**
  * @param DateTimeParseResult $result
  *
  * @return LocalDate
  *
  * @throws DateTimeException      If the date is not valid.
  * @throws DateTimeParseException If required fields are missing from the result.
  */
 public static function from(DateTimeParseResult $result)
 {
     $year = (int) $result->getField(Field\Year::NAME);
     $month = (int) $result->getField(Field\MonthOfYear::NAME);
     $day = (int) $result->getField(Field\DayOfMonth::NAME);
     return LocalDate::of($year, $month, $day);
 }
Beispiel #2
0
 /**
  * @param DateTimeParseResult $result
  *
  * @return TimeZoneRegion
  *
  * @throws DateTimeException      If the region is not valid.
  * @throws DateTimeParseException If required fields are missing from the result.
  */
 public static function from(DateTimeParseResult $result)
 {
     $region = $result->getField(Field\TimeZoneRegion::NAME);
     return TimeZoneRegion::of($region);
 }
Beispiel #3
0
 /**
  * @param DateTimeParseResult $result
  *
  * @return TimeZoneOffset
  *
  * @throws DateTimeException      If the offset is not valid.
  * @throws DateTimeParseException If required fields are missing from the result.
  */
 public static function from(DateTimeParseResult $result)
 {
     $sign = $result->getField(Field\TimeZoneOffsetSign::NAME);
     if ($sign === 'Z' || $sign === 'z') {
         return TimeZoneOffset::utc();
     }
     $hour = $result->getField(Field\TimeZoneOffsetHour::NAME);
     $minute = $result->getField(Field\TimeZoneOffsetMinute::NAME);
     $second = $result->getOptionalField(Field\TimeZoneOffsetSecond::NAME);
     $hour = (int) $hour;
     $minute = (int) $minute;
     $second = (int) $second;
     if ($sign === '-') {
         $hour = -$hour;
         $minute = -$minute;
         $second = -$second;
     }
     return self::of($hour, $minute, $second);
 }
Beispiel #4
0
 /**
  * @param DateTimeParseResult $result
  *
  * @return YearMonth
  *
  * @throws DateTimeException      If the year-month is not valid.
  * @throws DateTimeParseException If required fields are missing from the result.
  */
 public static function from(DateTimeParseResult $result)
 {
     return YearMonth::of((int) $result->getField(Field\Year::NAME), (int) $result->getField(Field\MonthOfYear::NAME));
 }
Beispiel #5
0
 /**
  * @param DateTimeParseResult $result
  *
  * @return LocalTime
  *
  * @throws DateTimeException      If the time is not valid.
  * @throws DateTimeParseException If required fields are missing from the result.
  */
 public static function from(DateTimeParseResult $result)
 {
     $hour = $result->getField(HourOfDay::NAME);
     $minute = $result->getField(MinuteOfHour::NAME);
     $second = $result->getOptionalField(SecondOfMinute::NAME);
     $fraction = $result->getOptionalField(Field\FractionOfSecond::NAME);
     $nano = substr($fraction . '000000000', 0, 9);
     return LocalTime::of((int) $hour, (int) $minute, (int) $second, (int) $nano);
 }