Wikibase
MediaWiki Wikibase extension
Wikibase\Repo\Parsers\MwTimeIsoParser Class Reference

Class to parse values that can be formatted by MWTimeIsoFormatter This includes parsing of localized values. More...

+ Inheritance diagram for Wikibase\Repo\Parsers\MwTimeIsoParser:
+ Collaboration diagram for Wikibase\Repo\Parsers\MwTimeIsoParser:

Public Member Functions

 __construct (ParserOptions $options=null)
 

Public Attributes

const FORMAT_NAME = 'mw-time-iso'
 

Protected Member Functions

 stringParse ( $value)
 Parses the provided string and returns the result. More...
 

Private Member Functions

 reconvertOutputString ( $value, Language $lang)
 Analyzes a string if it is a time value that has been specified in one of the output precision formats specified in the settings. More...
 
 parseFromOutputString (Language $lang, $value, $precision, $msgKey)
 
 getRegexpFromMessageText ( $msgText)
 Creates a regular expression snippet from a given message. More...
 
 chooseAndParseNumber (Language $lang, $matches, $precision, $isBceMsg)
 Tries to find the number from the given matches and parses it. More...
 
 isBceMsg ( $msgKey)
 
 getTimeFromYear ( $year, $isBce)
 
 setPrecision ( $precision)
 

Private Attributes

 $lang
 
 $isoTimestampParser
 

Static Private Attributes

static $precisionMsgKeys
 
static $paddedZeros
 

Detailed Description

Class to parse values that can be formatted by MWTimeIsoFormatter This includes parsing of localized values.

Author
Addshore
Marius Hoch
Todo:
move me to DataValues-time

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Repo\Parsers\MwTimeIsoParser::__construct ( ParserOptions  $options = null)
See also
StringValueParser::__construct
Parameters
ParserOptions | null$options

Member Function Documentation

◆ chooseAndParseNumber()

Wikibase\Repo\Parsers\MwTimeIsoParser::chooseAndParseNumber ( Language  $lang,
  $matches,
  $precision,
  $isBceMsg 
)
private

Tries to find the number from the given matches and parses it.

This naively assumes the first parseable number to be the best match.

Parameters
Language$lang
string[]$matches
int$precision
boolean$isBceMsg
Returns
TimeValue|bool

◆ getRegexpFromMessageText()

Wikibase\Repo\Parsers\MwTimeIsoParser::getRegexpFromMessageText (   $msgText)
private

Creates a regular expression snippet from a given message.

This replaces $1 with (.+?) and also expands PLURAL clauses so that we can match for every combination of these.

Parameters
string$msgText
Returns
string

◆ getTimeFromYear()

Wikibase\Repo\Parsers\MwTimeIsoParser::getTimeFromYear (   $year,
  $isBce 
)
private
Parameters
string$year
bool$isBce
Returns
TimeValue

◆ isBceMsg()

Wikibase\Repo\Parsers\MwTimeIsoParser::isBceMsg (   $msgKey)
private
Parameters
string$msgKey
Returns
boolean

◆ parseFromOutputString()

Wikibase\Repo\Parsers\MwTimeIsoParser::parseFromOutputString ( Language  $lang,
  $value,
  $precision,
  $msgKey 
)
private
Parameters
Language$lang
string$value
int$precision
string$msgKey
Returns
TimeValue|bool|null

◆ reconvertOutputString()

Wikibase\Repo\Parsers\MwTimeIsoParser::reconvertOutputString (   $value,
Language  $lang 
)
private

Analyzes a string if it is a time value that has been specified in one of the output precision formats specified in the settings.

If so, this method re-converts such an output string to an object that can be used to instantiate a time.Time object.

Parameters
string$value
Language$lang
Exceptions
RuntimeException
Returns
TimeValue|bool

◆ setPrecision()

Wikibase\Repo\Parsers\MwTimeIsoParser::setPrecision (   $precision)
private
Parameters
int$precision

◆ stringParse()

Wikibase\Repo\Parsers\MwTimeIsoParser::stringParse (   $value)
protected

Parses the provided string and returns the result.

Parameters
string$value
Exceptions
ParseException
Returns
TimeValue

Member Data Documentation

◆ $isoTimestampParser

Wikibase\Repo\Parsers\MwTimeIsoParser::$isoTimestampParser
private

◆ $lang

Wikibase\Repo\Parsers\MwTimeIsoParser::$lang
private

◆ $paddedZeros

Wikibase\Repo\Parsers\MwTimeIsoParser::$paddedZeros
staticprivate
Initial value:
= [
TimeValue::PRECISION_YEAR1G => 9,
TimeValue::PRECISION_YEAR1M => 6,
TimeValue::PRECISION_YEAR1K => 3,
TimeValue::PRECISION_YEAR100 => 2,
TimeValue::PRECISION_YEAR10 => 0
]

◆ $precisionMsgKeys

Wikibase\Repo\Parsers\MwTimeIsoParser::$precisionMsgKeys
staticprivate
Initial value:
= [
TimeValue::PRECISION_YEAR1G => [
'wikibase-time-precision-Gannum',
'wikibase-time-precision-BCE-Gannum',
],
TimeValue::PRECISION_YEAR1M => [
'wikibase-time-precision-Mannum',
'wikibase-time-precision-BCE-Mannum',
],
TimeValue::PRECISION_YEAR1K => [
'wikibase-time-precision-millennium',
'wikibase-time-precision-BCE-millennium',
],
TimeValue::PRECISION_YEAR100 => [
'wikibase-time-precision-century',
'wikibase-time-precision-BCE-century',
],
TimeValue::PRECISION_YEAR10 => [
'wikibase-time-precision-annum',
'wikibase-time-precision-BCE-annum',
'wikibase-time-precision-10annum',
'wikibase-time-precision-BCE-10annum',
],
]

◆ FORMAT_NAME

const Wikibase\Repo\Parsers\MwTimeIsoParser::FORMAT_NAME = 'mw-time-iso'

The documentation for this class was generated from the following file: