1: <?php
2: class Horde_Date_Parser_Locale_Base_Repeater
3: {
4: public $monthNameScanner = array(
5: '/^jan\.?(uary)?$/' => 'january',
6: '/^feb\.?(ruary)?$/' => 'february',
7: '/^mar\.?(ch)?$/' => 'march',
8: '/^apr\.?(il)?$/' => 'april',
9: '/^may$/' => 'may',
10: '/^jun\.?e?$/' => 'june',
11: '/^jul\.?y?$/' => 'july',
12: '/^aug\.?(ust)?$/' => 'august',
13: '/^sep\.?(t\.?|tember)?$/' => 'september',
14: '/^oct\.?(ober)?$/' => 'october',
15: '/^nov\.?(ember)?$/' => 'november',
16: '/^dec\.?(ember)?$/' => 'december',
17: );
18:
19: public $dayNameScanner = array(
20: '/^m[ou]n(day)?$/' => 'monday',
21: '/^t(ue|eu|oo|u|)s(day)?$/' => 'tuesday',
22: '/^tue$/' => 'tuesday',
23: '/^we(dnes|nds|nns)day$/' => 'wednesday',
24: '/^wed$/' => 'wednesday',
25: '/^th(urs|ers)day$/' => 'thursday',
26: '/^thu$/' => 'thursday',
27: '/^fr[iy](day)?$/' => 'friday',
28: '/^sat(t?[ue]rday)?$/' => 'saturday',
29: '/^su[nm](day)?$/' => 'sunday',
30: );
31:
32: public $dayPortionScanner = array(
33: '/^ams?$/' => 'am',
34: '/^pms?$/' => 'pm',
35: '/^mornings?$/' => 'morning',
36: '/^afternoons?$/' => 'afternoon',
37: '/^evenings?$/' => 'evening',
38: '/^(night|nite)s?$/' => 'night',
39: );
40:
41: public $unitScanner = array(
42: '/^years?$/' => 'year',
43: '/^seasons?$/' => 'season',
44: '/^months?$/' => 'month',
45: '/^fortnights?$/' => 'fortnight',
46: '/^weeks?$/' => 'week',
47: '/^weekends?$/' => 'weekend',
48: '/^days?$/' => 'day',
49: '/^hours?$/' => 'hour',
50: '/^minutes?$/' => 'minute',
51: '/^seconds?$/' => 'second',
52: );
53:
54: public $timeRegex = '/^\d{1,2}(:?\d{2})?([\.:]?\d{2})?$/';
55:
56:
57: public function scan($tokens, $options)
58: {
59: foreach ($tokens as &$token) {
60: if ($t = $this->scanForMonthNames($token)) {
61: $token->tag('repeater_month_name', $t);
62: } elseif ($t = $this->scanForDayNames($token)) {
63: $token->tag('repeater_day_name', $t);
64: } elseif ($t = $this->scanForDayPortions($token)) {
65: $token->tag('repeater_day_portion', $t);
66: } elseif ($t = $this->scanForTimes($token, $options)) {
67: $token->tag('repeater_time', $t);
68: } elseif ($t = $this->scanForUnits($token)) {
69: $token->tag(strtolower(str_replace('Horde_Date_', '', get_class($t))), $t);
70: }
71: }
72: return $tokens;
73: }
74:
75: public function scanForMonthNames($token)
76: {
77: foreach ($this->monthNameScanner as $scannerItem => $scannerTag) {
78: if (preg_match($scannerItem, $token->word)) {
79: return new Horde_Date_Repeater_MonthName($scannerTag);
80: }
81: }
82: }
83:
84: public function scanForDayNames($token)
85: {
86: foreach ($this->dayNameScanner as $scannerItem => $scannerTag) {
87: if (preg_match($scannerItem, $token->word)) {
88: return new Horde_Date_Repeater_DayName($scannerTag);
89: }
90: }
91: }
92:
93: public function scanForDayPortions($token)
94: {
95: foreach ($this->dayPortionScanner as $scannerItem => $scannerTag) {
96: if (preg_match($scannerItem, $token->word)) {
97: return new Horde_Date_Repeater_DayPortion($scannerTag);
98: }
99: }
100: }
101:
102: public function scanForTimes($token, $options)
103: {
104: if (preg_match($this->timeRegex, $token->word)) {
105: return new Horde_Date_Repeater_Time($token->word, $options);
106: }
107: }
108:
109: public function scanForUnits($token)
110: {
111: foreach ($this->unitScanner as $scannerItem => $scannerTag) {
112: if (preg_match($scannerItem, $token->word)) {
113: $class = 'Horde_Date_Repeater_' . ucfirst($scannerTag);
114: return new $class($scannerTag);
115: }
116: }
117: }
118:
119: }
120: