Thiemo Mättig (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/197875
Change subject: use ValueParsers\TimeParser as IsoTimestampParser; ...................................................................... use ValueParsers\TimeParser as IsoTimestampParser; The way to generic "TimeParser" class will be renamed in https://github.com/DataValues/Time/pull/39 This is a simple backwards-compatible patch that already renames the class where it's used. Reason is readablility. Now it's much easier to see what this parser does: It turns YMD-ordered timestamp strings into TimeValue objects. Change-Id: I0fff7239d62eca4f524bbe9ff6c2a94cf606e55c --- M lib/includes/parsers/MWTimeIsoParser.php M lib/includes/parsers/PhpDateTimeParser.php M lib/includes/parsers/TimeParser.php M lib/includes/parsers/YearMonthTimeParser.php M lib/includes/parsers/YearTimeParser.php 5 files changed, 20 insertions(+), 15 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/75/197875/1 diff --git a/lib/includes/parsers/MWTimeIsoParser.php b/lib/includes/parsers/MWTimeIsoParser.php index 7843812..cbf75e6 100644 --- a/lib/includes/parsers/MWTimeIsoParser.php +++ b/lib/includes/parsers/MWTimeIsoParser.php @@ -10,6 +10,7 @@ use ValueParsers\ParseException; use ValueParsers\ParserOptions; use ValueParsers\StringValueParser; +use ValueParsers\TimeParser as IsoTimestampParser; use ValueParsers\ValueParser; /** @@ -67,12 +68,12 @@ /** * @var Language */ - protected $lang; + private $lang; /** - * @var \ValueParsers\TimeParser + * @var IsoTimestampParser */ - protected $timeValueTimeParser; + private $isoTimestampParser; /** * @see StringValueParser::__construct @@ -85,7 +86,7 @@ parent::__construct( $options ); $this->lang = Language::factory( $this->getOptions()->getOption( ValueParser::OPT_LANG ) ); - $this->timeValueTimeParser = new \ValueParsers\TimeParser( + $this->isoTimestampParser = new IsoTimestampParser( new CalendarModelParser(), $this->getOptions() ); @@ -190,15 +191,15 @@ $timeString = $sign . $year . '-00-00T00:00:00Z'; - return $this->timeValueTimeParser->parse( $timeString ); + return $this->isoTimestampParser->parse( $timeString ); } /** * @param int $precision */ private function setPrecision( $precision ) { - $this->timeValueTimeParser->getOptions()->setOption( - \ValueParsers\TimeParser::OPT_PRECISION, + $this->isoTimestampParser->getOptions()->setOption( + IsoTimestampParser::OPT_PRECISION, $precision ); } diff --git a/lib/includes/parsers/PhpDateTimeParser.php b/lib/includes/parsers/PhpDateTimeParser.php index 986da80..1b51b943 100644 --- a/lib/includes/parsers/PhpDateTimeParser.php +++ b/lib/includes/parsers/PhpDateTimeParser.php @@ -9,6 +9,7 @@ use ValueParsers\ParseException; use ValueParsers\ParserOptions; use ValueParsers\StringValueParser; +use ValueParsers\TimeParser as IsoTimestampParser; use ValueParsers\ValueParser; /** @@ -96,7 +97,7 @@ } // Pass the reformatted string into a base parser that parses this +/-Y-m-d\TH:i:s\Z format with a precision - $valueParser = new \ValueParsers\TimeParser( $calendarModelParser, $options ); + $valueParser = new IsoTimestampParser( $calendarModelParser, $options ); return $valueParser->parse( $timeString ); } catch ( Exception $exception ) { throw new ParseException( $exception->getMessage(), $rawValue, self::FORMAT_NAME ); diff --git a/lib/includes/parsers/TimeParser.php b/lib/includes/parsers/TimeParser.php index 88b3e74..8ba1b62 100644 --- a/lib/includes/parsers/TimeParser.php +++ b/lib/includes/parsers/TimeParser.php @@ -7,6 +7,7 @@ use ValueParsers\ParseException; use ValueParsers\ParserOptions; use ValueParsers\StringValueParser; +use ValueParsers\TimeParser as IsoTimestampParser; /** * Time Parser @@ -61,7 +62,7 @@ // Year-month parser must be first to not parse "May 2014" as "2014-05-01". $parsers[] = new YearMonthTimeParser( $this->getOptions() ); - $parsers[] = new \ValueParsers\TimeParser( + $parsers[] = new IsoTimestampParser( $calenderModelParser, $this->getOptions() ); diff --git a/lib/includes/parsers/YearMonthTimeParser.php b/lib/includes/parsers/YearMonthTimeParser.php index 4a622c1..4e5e2de 100644 --- a/lib/includes/parsers/YearMonthTimeParser.php +++ b/lib/includes/parsers/YearMonthTimeParser.php @@ -8,6 +8,7 @@ use ValueParsers\ParseException; use ValueParsers\ParserOptions; use ValueParsers\StringValueParser; +use ValueParsers\TimeParser as IsoTimestampParser; use ValueParsers\ValueParser; /** @@ -138,7 +139,7 @@ * @return TimeValue */ private function getTimeFromYearMonth( $year, $month ) { - $timeParser = new \ValueParsers\TimeParser( new CalendarModelParser(), $this->getOptions() ); + $timeParser = new IsoTimestampParser( new CalendarModelParser(), $this->getOptions() ); return $timeParser->parse( sprintf( '+%d-%02d-00T00:00:00Z', $year, $month ) ); } @@ -151,4 +152,4 @@ return $value >= 0 && $value <= 12; } -} \ No newline at end of file +} diff --git a/lib/includes/parsers/YearTimeParser.php b/lib/includes/parsers/YearTimeParser.php index 4157c13..45afdee 100644 --- a/lib/includes/parsers/YearTimeParser.php +++ b/lib/includes/parsers/YearTimeParser.php @@ -8,6 +8,7 @@ use ValueParsers\ParseException; use ValueParsers\ParserOptions; use ValueParsers\StringValueParser; +use ValueParsers\TimeParser as IsoTimestampParser; use ValueParsers\ValueParser; /** @@ -33,9 +34,9 @@ private $lang; /** - * @var \ValueParsers\TimeParser + * @var IsoTimestampParser */ - private $timeValueTimeParser; + private $isoTimestampParser; /** * @param ValueParser $eraParser @@ -48,7 +49,7 @@ parent::__construct( $options ); $this->lang = Language::factory( $this->getOptions()->getOption( ValueParser::OPT_LANG ) ); - $this->timeValueTimeParser = new \ValueParsers\TimeParser( + $this->isoTimestampParser = new IsoTimestampParser( new CalendarModelParser(), $this->getOptions() ); @@ -86,7 +87,7 @@ throw new ParseException( 'Failed to parse year', $value, self::FORMAT_NAME ); } - return $this->timeValueTimeParser->parse( $sign . $year . '-00-00T00:00:00Z' ); + return $this->isoTimestampParser->parse( $sign . $year . '-00-00T00:00:00Z' ); } } -- To view, visit https://gerrit.wikimedia.org/r/197875 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0fff7239d62eca4f524bbe9ff6c2a94cf606e55c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
