Class StringParser

Description

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:

  1. $parser = StringParser::getParserFor($aString);
  2.  
  3. if (!$parser)
  4. die("'".$aString."' is not in a valid format.");
  5.  
  6. $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:

  1. $parser = new ANSI58216StringParser($aString);
  2.  
  3. if (!$parser)
  4. die("'".$aString."' is not in a valid format.");
  5.  
  6. $result = Duration::withDaysHoursMinutesSeconds($parser->day(), $parser->hour(),
  7. $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
Direct descendents
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.
Variable Summary
integer $day
integer $hour
string $input
integer $minute
integer $month
integer $offsetHour
integer $offsetMinute
integer $offsetSecond
integer $second
integer $year
Method Summary
object StringParser StringParser (string $aString)
boolean canHandle ()
integer day ()
mixed getParserFor (string $aString)
integer hour ()
integer minute ()
integer month ()
integer offsetHour ()
integer offsetMinute ()
integer offsetSecond ()
void parse ()
integer second ()
void setDay (integer $anInteger)
void setHour (integer $anInteger)
void setMinute (integer $anInteger)
void setMonth (mixed $anIntOrString)
void setOffsetHour (integer $anInteger)
void setOffsetMinute (integer $anInteger)
void setOffsetSecond (integer $anInteger)
void setSecond (mixed $anInteger, float $aFloat)
void setYear (integer $anInteger)
integer year ()
Variables
integer $day = NULL (line 143)
  • var: The day found in the input
  • since: 5/23/05
  • access: private
integer $hour = NULL (line 150)
  • var: The hour found in the input
  • since: 5/23/05
  • access: private
string $input (line 122)
  • var: The input string
  • since: 5/23/05
  • access: private
integer $minute = NULL (line 157)
  • var: The minute found in the input
  • since: 5/23/05
  • access: private
integer $month = NULL (line 136)
  • var: The month found in the input
  • since: 5/23/05
  • access: private
integer $offsetHour = NULL (line 171)
  • var: The hour offset from UTC found in the input
  • since: 5/23/05
  • access: private
integer $offsetMinute = NULL (line 178)
  • var: The minute offset from UTC found in the input
  • since: 5/23/05
  • access: private
integer $offsetSecond = NULL (line 185)
  • var: The second offset from UTC found in the input
  • since: 5/23/05
  • access: private
integer $second = NULL (line 164)
  • var: The second found in the input
  • since: 5/23/05
  • access: private
integer $year = NULL (line 129)
  • var: The year found in the input
  • since: 5/23/05
  • access: private
Methods
Constructor StringParser (line 200)

Create a new parser with the given input string.

  • since: 5/23/05
  • access: public
object StringParser StringParser (string $aString)
  • string $aString
canHandle (line 214)

Answer True if this parser can handle the format of the string passed.

  • since: 5/23/05
  • access: public
boolean canHandle ()

Redefined in descendants as:
day (line 263)

Answer the day or NULL.

  • since: 5/23/05
  • access: public
integer day ()
getParserFor (line 79)

Answer the parser that was able to successfully parse the input string or FALSE if none could handle the input string.

  • return: object StringParser OR FALSE
  • static:
  • since: 5/24/05
  • access: public
mixed getParserFor (string $aString)
  • string $aString
hour (line 274)

Answer the hour or NULL.

  • since: 5/23/05
  • access: public
integer hour ()
minute (line 285)

Answer the minute or NULL.

  • since: 5/23/05
  • access: public
integer minute ()
month (line 252)

Answer the month or NULL.

  • since: 5/23/05
  • access: public
integer month ()
offsetHour (line 307)

Answer the hour offset from UTC or NULL.

  • since: 5/23/05
  • access: public
integer offsetHour ()
offsetMinute (line 318)

Answer the minute offset from UTC or NULL.

  • since: 5/23/05
  • access: public
integer offsetMinute ()
offsetSecond (line 329)

Answer the second offset from UTC or NULL.

  • since: 5/23/05
  • access: public
integer offsetSecond ()
parse (line 226)

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.

  • since: 5/23/05
  • access: private
void parse ()

Redefined in descendants as:
  • KeywordStringParser::parse() : 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.
  • ANSI58216StringParser::parse() : 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.
  • DateAndTimeStringParser::parse() : 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.
  • ISO8601StringParser::parse() : 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.
  • ISO8601TimeStringParser::parse() : 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.
  • TimeStringParser::parse() : 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.
  • DayMonthNameYearStringParser::parse() : 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.
  • MonthNameDayYearStringParser::parse() : 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.
  • MonthNumberDayYearStringParser::parse() : 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.
second (line 296)

Answer the second or NULL.

  • since: 5/23/05
  • access: public
integer second ()
setDay (line 375)

Set the day

  • since: 5/23/05
  • access: private
void setDay (integer $anInteger)
  • integer $anInteger

Redefined in descendants as:
setHour (line 387)

Set the hour

  • since: 5/23/05
  • access: private
void setHour (integer $anInteger)
  • integer $anInteger
setMinute (line 399)

Set the minute

  • since: 5/23/05
  • access: private
void setMinute (integer $anInteger)
  • integer $anInteger
setMonth (line 357)

Set the month

  • since: 5/23/05
  • access: private
void setMonth (mixed $anIntOrString)
  • mixed $anIntOrString
setOffsetHour (line 423)

Set the hour offset from UTC

  • since: 5/23/05
  • access: private
void setOffsetHour (integer $anInteger)
  • integer $anInteger
setOffsetMinute (line 435)

Set the minute offset from UTC

  • since: 5/23/05
  • access: private
void setOffsetMinute (integer $anInteger)
  • integer $anInteger
setOffsetSecond (line 447)

Set the second offset from UTC

  • since: 5/23/05
  • access: private
void setOffsetSecond (integer $anInteger)
  • integer $anInteger
setSecond (line 411)

Set the second

  • since: 5/23/05
  • access: private
void setSecond (mixed $anInteger, float $aFloat)
  • float $aFloat
setYear (line 345)

Set the year

  • since: 5/23/05
  • access: private
void setYear (integer $anInteger)
  • integer $anInteger

Redefined in descendants as:
year (line 241)

Answer the year or NULL.

  • since: 5/23/05
  • access: public
integer year ()

Inherited Methods

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