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
26 """
27 Portuguese-specific classes for parsing and displaying dates.
28 """
29
30
31
32
33
34
35 import re
36
37
38
39
40
41
42 from gen.lib import Date
43 from _DateParser import DateParser
44 from _DateDisplay import DateDisplay
45 from _DateHandler import register_datehandler
46
47
48
49
50
51
53
54 modifier_to_int = {
55 u'antes de' : Date.MOD_BEFORE,
56 u'antes' : Date.MOD_BEFORE,
57 u'ant.' : Date.MOD_BEFORE,
58 u'ant' : Date.MOD_BEFORE,
59 u'após' : Date.MOD_AFTER,
60 u'aprox.' : Date.MOD_ABOUT,
61 u'aprox' : Date.MOD_ABOUT,
62 u'apr.' : Date.MOD_ABOUT,
63 u'apr' : Date.MOD_ABOUT,
64 u'cerca de' : Date.MOD_ABOUT,
65 u'ca.' : Date.MOD_ABOUT,
66 u'ca' : Date.MOD_ABOUT,
67 u'c.' : Date.MOD_ABOUT,
68 u'até' : Date.MOD_ABOUT,
69 }
70
71 calendar_to_int = {
72 u'gregoriano' : Date.CAL_GREGORIAN,
73 u'g' : Date.CAL_GREGORIAN,
74 u'juliano' : Date.CAL_JULIAN,
75 u'j' : Date.CAL_JULIAN,
76 u'hebreu' : Date.CAL_HEBREW,
77 u'h' : Date.CAL_HEBREW,
78 u'islâmico' : Date.CAL_ISLAMIC,
79 u'i' : Date.CAL_ISLAMIC,
80 u'revolucionário' : Date.CAL_FRENCH,
81 u'r' : Date.CAL_FRENCH,
82 u'persa' : Date.CAL_PERSIAN,
83 u'p' : Date.CAL_PERSIAN,
84 }
85
86 quality_to_int = {
87 u'estimado' : Date.QUAL_ESTIMATED,
88 u'est.' : Date.QUAL_ESTIMATED,
89 u'est' : Date.QUAL_ESTIMATED,
90 u'calc.' : Date.QUAL_CALCULATED,
91 u'calc' : Date.QUAL_CALCULATED,
92 u'calculado' : Date.QUAL_CALCULATED,
93 }
94
96 DateParser.init_strings(self)
97 _span_1 = [u'de']
98 _span_2 = [u'a']
99 _range_1 = [u'entre',u'ent\.',u'ent']
100 _range_2 = [u'e']
101 self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
102 ('|'.join(_span_1),'|'.join(_span_2)),
103 re.IGNORECASE)
104 self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
105 ('|'.join(_range_1),'|'.join(_range_2)),
106 re.IGNORECASE)
107
108
109
110
111
112
114
115 calendar = (
116 "", u" (Juliano)", u" (Hebreu)",
117 u" (Revolucionário)", u" (Persa)", u" (Islâmico)"
118 )
119
120 _mod_str = ("",u"antes de ",u"depois de ",u"até ","","","")
121
122 _qual_str = ("","estimado ","calculado ")
123
124 formats = (
125 "AAAA-MM-DD (ISO)", "Numérica", "Mês Dia, Ano",
126 "MÊS Dia, Ano", "Dia Mês, Ano", "Dia MÊS, Ano"
127 )
128
130 """
131 Return a text string representing the date.
132 """
133 mod = date.get_modifier()
134 cal = date.get_calendar()
135 qual = date.get_quality()
136 start = date.get_start_date()
137
138 qual_str = self._qual_str[qual]
139
140 if mod == Date.MOD_TEXTONLY:
141 return date.get_text()
142 elif start == Date.EMPTY:
143 return ""
144 elif mod == Date.MOD_SPAN:
145 d1 = self.display_cal[cal](start)
146 d2 = self.display_cal[cal](date.get_stop_date())
147 return "%s%s %s %s %s%s" % (qual_str, u'de', d1, u'a', d2,self.calendar[cal])
148 elif mod == Date.MOD_RANGE:
149 d1 = self.display_cal[cal](start)
150 d2 = self.display_cal[cal](date.get_stop_date())
151 return "%s%s %s %s %s%s" % (qual_str, u'entre', d1, u'e', d2, self.calendar[cal])
152 else:
153 text = self.display_cal[date.get_calendar()](start)
154 return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, self.calendar[cal])
155
156
157
158
159
160
161 register_datehandler(('pt', 'pt_PT', 'pt_PT.UTF-8', 'pt_BR', 'pt_BR.UTF-8', 'pt', 'portuguese'), DateParserPT, DateDisplayPT)
162