Source for file MonthNumberDayYearStringParser.class.php

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

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