1: <?php
2: class Horde_Date_Parser_Locale_Base_Scalar
3: {
4: public $scalarRegex = '/^\d*$/';
5: public $dayRegex = '/^\d\d?$/';
6: public $monthRegex = '/^\d\d?$/';
7: public $yearRegex = '/^([1-9]\d)?\d\d?$/';
8: public $timeSignifiers = array('am', 'pm', 'morning', 'afternoon', 'evening', 'night');
9:
10: public function scan($tokens)
11: {
12: foreach ($tokens as $i => &$token) {
13: $postToken = isset($tokens[$i + 1]) ? $tokens[$i + 1]->word : null;
14: if (!is_null($t = $this->scanForScalars($token, $postToken))) {
15: $token->tag('scalar', $t);
16: }
17: if (!is_null($t = $this->scanForDays($token, $postToken))) {
18: $token->tag('scalar_day', $t);
19: }
20: if (!is_null($t = $this->scanForMonths($token, $postToken))) {
21: $token->tag('scalar_month', $t);
22: }
23: if (!is_null($t = $this->scanForYears($token, $postToken))) {
24: $token->tag('scalar_year', $t);
25: }
26: }
27: return $tokens;
28: }
29:
30: public function scanForScalars($token, $postToken)
31: {
32: if (preg_match($this->scalarRegex, $token->word)) {
33: if (!in_array($postToken, $this->timeSignifiers)) {
34: return $token->word;
35: }
36: }
37: }
38:
39: public function scanForDays($token, $postToken)
40: {
41: if (preg_match($this->dayRegex, $token->word)) {
42: if ($token->word <= 31 && !in_array($postToken, $this->timeSignifiers)) {
43: return $token->word;
44: }
45: }
46: }
47:
48: public function scanForMonths($token, $postToken)
49: {
50: if (preg_match($this->monthRegex, $token->word)) {
51: if ($token->word <= 12 && !in_array($postToken, $this->timeSignifiers)) {
52: return $token->word;
53: }
54: }
55: }
56:
57: public function scanForYears($token, $postToken)
58: {
59: if (preg_match($this->yearRegex, $token->word)) {
60: if (!in_array($postToken, $this->timeSignifiers)) {
61: return $token->word;
62: }
63: }
64: }
65:
66: }
67: