1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """
25 Spanish-specific classes for parsing and displaying dates.
26 """
27
28
29
30
31
32
33 import re
34
35
36
37
38
39
40 from gen.lib import Date
41 from _DateParser import DateParser
42 from _DateDisplay import DateDisplay
43 from _DateHandler import register_datehandler
44
45
46
47
48
49
51
52 modifier_to_int = {
53 u'antes de' : Date.MOD_BEFORE,
54 u'antes' : Date.MOD_BEFORE,
55 u'ant.' : Date.MOD_BEFORE,
56 u'ant' : Date.MOD_BEFORE,
57 u'después de' : Date.MOD_AFTER,
58 u'después' : Date.MOD_AFTER,
59 u'desp.' : Date.MOD_AFTER,
60 u'desp' : Date.MOD_AFTER,
61 u'aprox.' : Date.MOD_ABOUT,
62 u'aprox' : Date.MOD_ABOUT,
63 u'apr.' : Date.MOD_ABOUT,
64 u'apr' : Date.MOD_ABOUT,
65 u'circa' : Date.MOD_ABOUT,
66 u'ca.' : Date.MOD_ABOUT,
67 u'ca' : Date.MOD_ABOUT,
68 u'c.' : Date.MOD_ABOUT,
69 u'hacia' : Date.MOD_ABOUT,
70 }
71
72 calendar_to_int = {
73 u'gregoriano' : Date.CAL_GREGORIAN,
74 u'g' : Date.CAL_GREGORIAN,
75 u'juliano' : Date.CAL_JULIAN,
76 u'j' : Date.CAL_JULIAN,
77 u'hebreo' : Date.CAL_HEBREW,
78 u'h' : Date.CAL_HEBREW,
79 u'islámico' : Date.CAL_ISLAMIC,
80 u'i' : Date.CAL_ISLAMIC,
81 u'revolucionario' : Date.CAL_FRENCH,
82 u'r' : Date.CAL_FRENCH,
83 u'persa' : Date.CAL_PERSIAN,
84 u'p' : Date.CAL_PERSIAN,
85 }
86
87 quality_to_int = {
88 u'estimado' : Date.QUAL_ESTIMATED,
89 u'est.' : Date.QUAL_ESTIMATED,
90 u'est' : Date.QUAL_ESTIMATED,
91 u'calc.' : Date.QUAL_CALCULATED,
92 u'calc' : Date.QUAL_CALCULATED,
93 u'calculado' : Date.QUAL_CALCULATED,
94 }
95
97 DateParser.init_strings(self)
98 _span_1 = [u'de']
99 _span_2 = [u'a']
100 _range_1 = [u'entre', u'ent\.', u'ent']
101 _range_2 = [u'y']
102 self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
103 ('|'.join(_span_1), '|'.join(_span_2)),
104 re.IGNORECASE)
105 self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
106 ('|'.join(_range_1), '|'.join(_range_2)),
107 re.IGNORECASE)
108
109
110
111
112
113
115
116 calendar = (
117 "", u" (Juliano)", u" (Hebreo)",
118 u" (Revolucionario)", u" (Persa)", u" (Islámico)"
119 )
120
121 _mod_str = ("", u"antes de ", u"después de ", u"hacia ", "", "", "")
122
123 _qual_str = ("", "estimado ", "calculado ")
124
125 formats = (
126 "AAAA-MM-DD (ISO)", "Numérica", "Mes Día, Año",
127 "MES Día, Año", "Día Mes, Año", "Día MES, Año"
128 )
129
131 """
132 Return a text string representing the date.
133 """
134 mod = date.get_modifier()
135 cal = date.get_calendar()
136 qual = date.get_quality()
137 start = date.get_start_date()
138
139 qual_str = self._qual_str[qual]
140
141 if mod == Date.MOD_TEXTONLY:
142 return date.get_text()
143 elif start == Date.EMPTY:
144 return ""
145 elif mod == Date.MOD_SPAN:
146 d1 = self.display_cal[cal](start)
147 d2 = self.display_cal[cal](date.get_stop_date())
148 return "%s%s %s %s %s%s" % (qual_str, u'de', d1, u'a', d2, self.calendar[cal])
149 elif mod == Date.MOD_RANGE:
150 d1 = self.display_cal[cal](start)
151 d2 = self.display_cal[cal](date.get_stop_date())
152 return "%s%s %s %s %s%s" % (qual_str, u'entre', d1, u'y', d2, self.calendar[cal])
153 else:
154 text = self.display_cal[date.get_calendar()](start)
155 return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, self.calendar[cal])
156
157
158
159
160
161
162 register_datehandler(('es_ES', 'es', 'spanish'), DateParserES, DateDisplayES)
163