Source for file DayMonthNameYearStringParser.class.php

Documentation is available at DayMonthNameYearStringParser.class.php

  1. <?php
  2. /**
  3. * @since 5/23/05
  4. * @package harmoni.primitives.chronology.string_parsers
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: DayMonthNameYearStringParser.class.php,v 1.2 2006/06/26 12:55:08 adamfranco Exp $
  10. *
  11. * @link http://harmoni.sourceforge.net/
  12. * @author Adam Franco <adam AT adamfranco DOT com> <afranco AT middlebury DOT edu>
  13. */
  14.  
  15. require_once(dirname(__FILE__)."/StringParser.class.php");
  16. //require_once(dirname(__FILE__)."/TwoDigitYearStringParser.class.php");
  17.  
  18. /**
  19. * This StringParser can handle dates that contain an integer day followed by
  20. * a textual month-name or month-abbreviation followed by an integer year.
  21. * Delimiters are ignored. Examples:
  22. * - 5 April 1982
  23. * - 5 April '82
  24. * - 5-APR-82
  25. * - 5APR82
  26. * - 5APRIL1982
  27. *
  28. * @since 5/23/05
  29. * @package harmoni.primitives.chronology.string_parsers
  30. *
  31. * @copyright Copyright &copy; 2005, Middlebury College
  32. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  33. *
  34. * @version $Id: DayMonthNameYearStringParser.class.php,v 1.2 2006/06/26 12:55:08 adamfranco Exp $
  35. *
  36. * @link http://harmoni.sourceforge.net/
  37. * @author Adam Franco <adam AT adamfranco DOT com> <afranco AT middlebury DOT edu>
  38. */
  39. class DayMonthNameYearStringParser
  40. extends TwoDigitYearStringParser {
  41. /*******************************************************
  42. * Instance Methods
  43. *********************************************************/
  44.  
  45. /**
  46. * Return the regular expression used by this parser
  47. *
  48. * @return string
  49. * @access protected
  50. * @since 5/24/05
  51. */
  52. function getRegex () {
  53. return
  54. "/
  55. ^
  56. ( # Day of Month (optional)
  57. (?: 0?[1-9])
  58. |
  59. (?: [1-2][0-9])
  60. |
  61. (?: 3[01])
  62. )?
  63. [^0-9a-zA-Z]* # Delimiter
  64. ([a-zA-Z]+) # Month
  65. [^0-9a-zA-Z]* # Delimiter
  66. ([0-9]{2,}) # Year
  67. $
  68. /x";
  69. }
  70. /**
  71. * Parse the input string and set our elements based on the contents of the
  72. * input string. Elements not found in the string will be null.
  73. *
  74. * @return void
  75. * @access private
  76. * @since 5/23/05
  77. */
  78. function parse () {
  79. preg_match($this->getRegex(), $this->input, $matches);
  80. // Matches:
  81. // [0] => 23 May 2005
  82. // [1] => 23
  83. // [2] => May
  84. // [3] => 2005
  85. $this->setYear($matches[3]);
  86. $this->setMonth($matches[2]);
  87. $this->setDay($matches[1]);
  88. }
  89. }
  90.  
  91. ?>

Documentation generated on Wed, 19 Sep 2007 10:22:37 -0400 by phpDocumentor 1.3.0RC3