コード例 #1
0
ファイル: MonthDay.php プロジェクト: brick/date-time
 /**
  * Obtains an instance of `LocalDate` from a text string.
  *
  * @param string              $text   The text to parse, such as `--12-03`.
  * @param DateTimeParser|null $parser The parser to use, defaults to the ISO 8601 parser.
  *
  * @return MonthDay
  *
  * @throws DateTimeException      If the date is not valid.
  * @throws DateTimeParseException If the text string does not follow the expected format.
  */
 public static function parse($text, DateTimeParser $parser = null)
 {
     if (!$parser) {
         $parser = IsoParsers::monthDay();
     }
     return MonthDay::from($parser->parse($text));
 }
コード例 #2
0
ファイル: LocalDateRange.php プロジェクト: brick/date-time
 /**
  * Obtains an instance of `LocalDateRange` from a set of date-time fields.
  *
  * This method is only useful to parsers.
  *
  * @param DateTimeParseResult $result
  *
  * @return LocalDateRange
  *
  * @throws DateTimeException      If the date range is not valid.
  * @throws DateTimeParseException If required fields are missing from the result.
  */
 public static function from(DateTimeParseResult $result)
 {
     $startDate = LocalDate::from($result);
     if ($result->hasField(Field\MonthOfYear::NAME)) {
         if ($result->hasField(Field\Year::NAME)) {
             $endDate = LocalDate::from($result);
         } else {
             $endDate = MonthDay::from($result)->atYear($startDate->getYear());
         }
     } else {
         $endDate = $startDate->withDay((int) $result->getField(Field\DayOfMonth::NAME));
     }
     return LocalDateRange::of($startDate, $endDate);
 }