StringParser and its decendent classes form a Strategy pattern. They classes that each implement a differnt method (strategy) for parsing strings into dates and times.
To try to parse a string using all (general) StringParsers use the getParserFor($aString) method to iterate through the parsers until one is found that can handle the input:
- $parser = StringParser::getParserFor($aString);
- if (!$parser)
- die("'".$aString."' is not in a valid format.");
- $result = Date::withYearMonthDay($parser->year(), $parser->month(), $parser->day());
To use StringParsers individually, use the canHandle($aString) method to find out if it is appropriate to use this parse for a given string. If it is appropriate, create a new StringParser with the given string and access its elements for the results:
- $parser = new ANSI58216StringParser($aString);
- if (!$parser)
- die("'".$aString."' is not in a valid format.");
- $result = Duration::withDaysHoursMinutesSeconds($parser->day(), $parser->hour(),
- $parser->minute(), $parser->second());
To create new StringParsers, implement the canHandle() and parse() methods.
Located in /harmoni/core/Primitives/Chronology/StringParser/StringParser.class.php (line 62)
SObject | --StringParser
Class | Description |
---|---|
KeywordStringParser | KeywordStringParser matches keywords to common times. |
RegexStringParser | RegexStringParser is an abstract class that implements a common canHandle() method for decendents as well as defines a 'getRegex()' class method which must be set by decendent classes. |
Create a new parser with the given input string.
Answer True if this parser can handle the format of the string passed.
Answer the parser that was able to successfully parse the input string or FALSE if none could handle the input string.
Parse the input string and set our elements based on the contents of the input string. Elements not found in the string will be null.
Set the day
Set the hour offset from UTC
Set the minute offset from UTC
Set the second offset from UTC
Set the year
Inherited From SObject
SObject::asA()
SObject::asString()
SObject::copy()
SObject::copySameFrom()
SObject::copyTwoLevel()
SObject::deepCopy()
SObject::isEqual()
SObject::isEqualTo()
SObject::isNotEqualTo()
SObject::isNotReferenceTo()
SObject::isReferenceTo()
SObject::newFrom()
SObject::postCopy()
SObject::printableString()
SObject::shallowCopy()
SObject::_deepCopyArray()
Documentation generated on Wed, 19 Sep 2007 10:26:54 -0400 by phpDocumentor 1.3.0RC3