1: <?php
2: class Horde_Date_Parser_Locale_Pt_Ordinal extends Horde_Date_Parser_Locale_Base_Ordinal
3: {
4: /*
5: public $ordinalRegex = '/^(\d*)(\.|\xBA|\xAA|º|ª|st|nd|rd|th)?$/';
6: public $ordinalDayRegex = '/^(0[1-9]|[12][0-9]|3[01])(\.|\xBA|\xAA|º|ª|st|nd|rd|th)?$/';
7: public $ordinalMonthsRegex = '/^(0[1-9]|1[012])(\.|\xBA|\xAA|º|ª|st|nd|rd|th)?$/';
8: */
9: public $ordinalRegex = '/^(\d*)(st|nd|rd|th)$/';
10: public $ordinalDayRegex = '/^(\d*)(st|nd|rd|th)$/';
11: public $ordinalMonthsRegex = '/^(\d*)(st|nd|rd|th)$/';
12:
13:
14: public function scan($tokens)
15: {
16: foreach ($tokens as &$token) {
17: if (!is_null($t = $this->scanForOrdinals($token))) {
18: $token->tag('ordinal', $t);
19: }
20: if (!is_null($t = $this->scanForDays($token))) {
21: $token->tag('ordinal_day', $t);
22: }
23: if (!is_null($t = $this->scanForMonths($token))) {
24: $token->tag('ordinal_month', $t);
25: }
26: }
27:
28: return $tokens;
29: }
30:
31: public function scanForOrdinals($token)
32: {
33: if (preg_match($this->ordinalRegex, $token->word, $matches)) {
34: return (int)$matches[1];
35: }
36: }
37:
38: public function scanForDays($token)
39: {
40: if (preg_match($this->ordinalDayRegex, $token->word, $matches)) {
41: if ($matches[1] <= 31) {
42: return (int)$matches[1];
43: }
44: }
45: }
46:
47: public function scanForMonths($token)
48: {
49: if (preg_match($this->ordinalMonthsRegex, $token->word, $matches)) {
50: if ($matches[1] <= 12) {
51: return (int)$matches[1];
52: }
53: }
54: }
55: }
56: