Source for file MonthNameDayYearStringParser.class.php

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

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