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