/** * Obtains an instance of `YearMonth` from a text string. * * @param string $text The text to parse, such as `2007-12`. * @param DateTimeParser|null $parser The parser to use, defaults to the ISO 8601 parser. * * @return YearMonth * * @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::yearMonth(); } return YearMonth::from($parser->parse($text)); }
/** * 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)); }
/** * Obtains an instance of `LocalDateTime` from a text string. * * @param string $text The text to parse, such as `2007-12-03T10:15:30`. * @param DateTimeParser|null $parser The parser to use, defaults to the ISO 8601 parser. * * @return LocalDateTime * * @throws DateTimeException If the date-time 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::localDateTime(); } return LocalDateTime::from($parser->parse($text)); }
/** * Parses a region id, such as 'Europe/London'. * * @param string $text * @param DateTimeParser|null $parser * * @return TimeZoneRegion * * @throws DateTimeParseException */ public static function parse($text, DateTimeParser $parser = null) { if (!$parser) { $parser = IsoParsers::timeZoneRegion(); } return TimeZoneRegion::from($parser->parse($text)); }