1: <?php
2: class Horde_Date_Parser_Locale_Pt_Repeater extends Horde_Date_Parser_Locale_Base_Repeater
3: {
4:
5: public $monthNameScanner = array(
6: '/^jan(eiro)?$/' => 'january',
7: '/^fev(ereiro)?$/' => 'february',
8: '/^mar(co)?$/' => 'march',
9: '/^abr(il)?$/' => 'april',
10: '/^mai(o)?$/' => 'may',
11: '/^jun(ho)?$/' => 'june',
12: '/^jul(ho)?$/' => 'july',
13: '/^ago(sto)?$/' => 'august',
14: '/^set(embro)?$/' => 'september',
15: '/^out(ubro)?$/' => 'october',
16: '/^nov(embro)?$/' => 'november',
17: '/^dez(embro)?$/' => 'december',
18: );
19:
20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35:
36:
37: public $dayNameScanner = array(
38: '/^seg$/' => 'monday',
39: '/^ter$/' => 'tuesday',
40: '/^qua$/' => 'wednesday',
41: '/^qui$/' => 'thursday',
42: '/^sex$/' => 'friday',
43: '/^sab$/' => 'saturday',
44: '/^dom$/' => 'sunday',
45: '/^segunda$/' => 'monday',
46: '/^terca$/' => 'tuesday',
47: '/^quarta$/' => 'wednesday',
48: '/^quinta$/' => 'thursday',
49: '/^sexta$/' => 'friday',
50: '/^sab(ado)?$/' => 'saturday',
51: '/^dom(ingo)?$/' => 'sunday',
52: );
53:
54: 55: 56: 57: 58: 59: 60: 61: 62:
63:
64: public $dayPortionScanner = array(
65: '/^(\d*)\s?ams?$/' => 'am',
66: '/^(\d*)\s?pms?$/' => 'pm',
67: '/^(?:de|na|a|durante\s+a) (manh[aã]|madrugada)$/' => 'morning',
68: '/^(?:de|na|a|durante\s+a) tarde$/' => 'afternoon',
69: '/^((fim\s(d[ea]\s)tarde)|anoitecer)$/' => 'evening',
70: '/^noite$/' => 'night',
71: '/^ams?$/' => 'am',
72: '/^pms?$/' => 'pm',
73: '/^mornings?$/' => 'morning',
74: '/^afternoons?$/' => 'afternoon',
75: '/^evenings?$/' => 'evening',
76: '/^(night|nite)s?$/' => 'night',
77:
78: );
79:
80: public $unitScanner = array(
81: '/^anos?$/' => 'year',
82: '/^(estacao|epoca)$/' => 'season',
83: '/^mes$/' => 'month',
84: '/^quinzena$/' => 'fortnight',
85: '/^semanas?$/' => 'week',
86: '/^(fds|fim( |( |\-)de( |\-))semana)?$/' => 'weekend',
87: '/^dias?$/' => 'day',
88: '/^horas?$/' => 'hour',
89: '/^minutos?$/' => 'minute',
90: '/^segundos?$/' => 'second',
91: '/^years?$/' => 'year',
92: '/^seasons?$/' => 'season',
93: '/^months?$/' => 'month',
94: '/^fortnights?$/' => 'fortnight',
95: '/^weeks?$/' => 'week',
96: '/^weekends?$/' => 'weekend',
97: '/^days?$/' => 'day',
98: '/^hours?$/' => 'hour',
99: '/^minutes?$/' => 'minute',
100: '/^seconds?$/' => 'second',
101: );
102:
103: public $timeRegex = '/^\d{1,2}(:?\d{2})?([\.:]?\d{2})?$/';
104:
105:
106:
107: public function scan($tokens, $options)
108: {
109: foreach ($tokens as &$token) {
110: if ($t = $this->scanForMonthNames($token)) {
111: $token->tag('repeater_month_name', $t);
112: } elseif ($t = $this->scanForDayNames($token)) {
113: $token->tag('repeater_day_name', $t);
114: } elseif ($t = $this->scanForDayPortions($token)) {
115: $token->tag('repeater_day_portion', $t);
116: } elseif ($t = $this->scanForTimes($token, $options)) {
117: $token->tag('repeater_time', $t);
118: } elseif ($t = $this->scanForUnits($token)) {
119: $token->tag(strtolower(str_replace('Horde_Date_', '', get_class($t))), $t);
120: }
121: }
122: return $tokens;
123: }
124:
125: public function scanForMonthNames($token)
126: {
127: foreach ($this->monthNameScanner as $scannerItem => $scannerTag) {
128: if (preg_match($scannerItem, $token->word)) {
129: return new Horde_Date_Repeater_MonthName($scannerTag);
130: }
131: }
132: }
133:
134: public function scanForDayNames($token)
135: {
136: foreach ($this->dayNameScanner as $scannerItem => $scannerTag) {
137: if (preg_match($scannerItem, $token->word)) {
138: return new Horde_Date_Repeater_DayName($scannerTag);
139: }
140: }
141: }
142:
143: public function scanForDayPortions($token)
144: {
145: foreach ($this->dayPortionScanner as $scannerItem => $scannerTag) {
146: if (preg_match($scannerItem, $token->word)) {
147: return new Horde_Date_Repeater_DayPortion($scannerTag);
148: }
149: }
150: }
151:
152: public function scanForTimes($token, $options)
153: {
154: if (preg_match($this->timeRegex, $token->word)) {
155: return new Horde_Date_Repeater_Time($token->word, $options);
156: }
157: }
158:
159: public function scanForUnits($token)
160: {
161: foreach ($this->unitScanner as $scannerItem => $scannerTag) {
162: if (preg_match($scannerItem, $token->word)) {
163: $class = 'Horde_Date_Repeater_' . ucfirst($scannerTag);
164: return new $class($scannerTag);
165: }
166: }
167: }
168:
169: }
170: