1: <?php
2: class Horde_Date_Parser_Locale_Base_Ordinal
3: {
4: public $ordinalRegex = '/^(\d*)(st|nd|rd|th)$/';
5: public $ordinalDayRegex = '/^(\d*)(st|nd|rd|th)$/';
6:
7: public function scan($tokens)
8: {
9: foreach ($tokens as &$token) {
10: if (!is_null($t = $this->scanForOrdinals($token))) {
11: $token->tag('ordinal', $t);
12: }
13: if (!is_null($t = $this->scanForDays($token))) {
14: $token->tag('ordinal_day', $t);
15: }
16: }
17:
18: return $tokens;
19: }
20:
21: public function scanForOrdinals($token)
22: {
23: if (preg_match($this->ordinalRegex, $token->word, $matches)) {
24: return (int)$matches[1];
25: }
26: }
27:
28: public function scanForDays($token)
29: {
30: if (preg_match($this->ordinalDayRegex, $token->word, $matches)) {
31: if ($matches[1] <= 31) {
32: return (int)$matches[1];
33: }
34: }
35: }
36:
37: }
38: