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 French-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 month_to_int = DateParser.month_to_int
53
54 month_to_int[u"bluviose"] = 1
55 month_to_int[u"vendose"] = 2
56 month_to_int[u"7bre"] = 9
57 month_to_int[u"8bre"] = 10
58 month_to_int[u"9bre"] = 11
59 month_to_int[u"10bre"] = 12
60 month_to_int[u"xbre"] = 12
61
62 month_to_int[u"januaris"] = 1
63 month_to_int[u"januarii"] = 1
64 month_to_int[u"januarius"] = 1
65 month_to_int[u"februaris"] = 2
66 month_to_int[u"februarii"] = 2
67 month_to_int[u"februarius"] = 2
68 month_to_int[u"martii"] = 3
69 month_to_int[u"martius"] = 3
70 month_to_int[u"aprilis"] = 4
71 month_to_int[u"maius"] = 5
72 month_to_int[u"maii"] = 5
73 month_to_int[u"junius"] = 6
74 month_to_int[u"junii"] = 6
75 month_to_int[u"julius"] = 7
76 month_to_int[u"julii"] = 7
77 month_to_int[u"augustus"] = 8
78 month_to_int[u"augusti"] = 8
79 month_to_int[u"septembris"] = 9
80 month_to_int[u"7bris"] = 9
81 month_to_int[u"september"] = 9
82 month_to_int[u"october"] = 10
83 month_to_int[u"octobris"] = 10
84 month_to_int[u"8bris"] = 10
85 month_to_int[u"novembris"] = 11
86 month_to_int[u"9bris"] = 11
87 month_to_int[u"november"] = 11
88 month_to_int[u"decembris"] = 12
89 month_to_int[u"10bris"] = 12
90 month_to_int[u"xbris"] = 12
91 month_to_int[u"december"] = 12
92
93
94 month_to_int[u"janer"] = 1
95 month_to_int[u"jenner"] = 1
96 month_to_int[u"hartmonat"] = 1
97 month_to_int[u"hartung"] = 1
98 month_to_int[u"eismond"] = 1
99 month_to_int[u"hornung"] = 2
100 month_to_int[u"wintermonat"] = 2
101 month_to_int[u"taumond"] = 2
102 month_to_int[u"narrenmond"] = 2
103 month_to_int[u"lenzing"] = 3
104 month_to_int[u"ostermond"] = 4
105 month_to_int[u"wonnemond"] = 5
106 month_to_int[u"wiesenmonat"] = 5
107 month_to_int[u"brachet"] = 6
108 month_to_int[u"heuet"] = 7
109 month_to_int[u"ernting"] = 8
110 month_to_int[u"scheiding"] = 9
111 month_to_int[u"gilbhard"] = 10
112 month_to_int[u"nebelmonat"] = 11
113 month_to_int[u"nebelung"] = 11
114 month_to_int[u"julmond"] = 12
115
116 modifier_to_int = {
117 u'avant' : Date.MOD_BEFORE,
118 u'av.' : Date.MOD_BEFORE,
119 u'après' : Date.MOD_AFTER,
120 u'ap.' : Date.MOD_AFTER,
121 u'ap' : Date.MOD_AFTER,
122 u'env.' : Date.MOD_ABOUT,
123 u'env' : Date.MOD_ABOUT,
124 u'environ': Date.MOD_ABOUT,
125 u'circa' : Date.MOD_ABOUT,
126 u'c.' : Date.MOD_ABOUT,
127 u'ca' : Date.MOD_ABOUT,
128 u'ca.' : Date.MOD_ABOUT,
129 u'vers' : Date.MOD_ABOUT,
130 u'~' : Date.MOD_ABOUT,
131 }
132
133 calendar_to_int = {
134 u'grégorien' : Date.CAL_GREGORIAN,
135 u'g' : Date.CAL_GREGORIAN,
136 u'julien' : Date.CAL_JULIAN,
137 u'j' : Date.CAL_JULIAN,
138 u'hébreu' : Date.CAL_HEBREW,
139 u'h' : Date.CAL_HEBREW,
140 u'islamique' : Date.CAL_ISLAMIC,
141 u'i' : Date.CAL_ISLAMIC,
142 u'révolutionnaire' : Date.CAL_FRENCH,
143 u'r' : Date.CAL_FRENCH,
144 u'perse' : Date.CAL_PERSIAN,
145 u'p' : Date.CAL_PERSIAN,
146 }
147
148 quality_to_int = {
149 u'estimée' : Date.QUAL_ESTIMATED,
150 u'est.' : Date.QUAL_ESTIMATED,
151 u'est' : Date.QUAL_ESTIMATED,
152 u'calculée' : Date.QUAL_CALCULATED,
153 u'calc.' : Date.QUAL_CALCULATED,
154 u'calc' : Date.QUAL_CALCULATED,
155 u'comptée' : Date.QUAL_CALCULATED,
156 u'compt' : Date.QUAL_CALCULATED,
157 u'compt.' : Date.QUAL_CALCULATED,
158 }
159
160 bce = [u"avant le calendrier", u"avant notre ère",
161 u"avant JC", u"avant J.C"] + DateParser.bce
162
164 DateParser.init_strings(self)
165
166
167 self._numeric = re.compile("((\d+)[/\. ])?\s*((\d+)[/\.])?\s*(\d+)\s*$")
168 self._span = re.compile(u"(de)\s+(?P<start>.+)\s+(à)\s+(?P<stop>.+)", re.IGNORECASE)
169 self._range = re.compile(u"(entre|ent\.|ent)\s+(?P<start>.+)\s+(et)\s+(?P<stop>.+)", re.IGNORECASE)
170
171
172
173 self._text2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._mon_str,
174 re.IGNORECASE)
175
176 self._jtext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._jmon_str,
177 re.IGNORECASE)
178
179 self._ftext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._fmon_str,
180 re.IGNORECASE)
181
182 self._ptext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._pmon_str,
183 re.IGNORECASE)
184
185 self._itext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._imon_str,
186 re.IGNORECASE)
187
188
189
190
191
192
194
195 calendar = (
196 "", u" (Julien)", u" (Hébreu)",
197 u" (Révolutionnaire)", u" (Perse)", u" (Islamique)"
198 )
199
200 _mod_str = ("", u"avant ", u"après ", u"vers ", "", "", "")
201
202 _qual_str = ("", u"estimée ", u"calculée ", "")
203
204 _bce_str = u"%s avant le calendrier"
205
206 formats = (
207 "AAAA-MM-JJ (ISO)", "Numérique", "Mois Jour, Année",
208 "MOI Jour, Année", "Jour. Mois Année", "Jour. MOI Année"
209 )
210
212 year = self._slash_year(date_val[2], date_val[3])
213 if self.format == 0:
214 return self.display_iso(date_val)
215 elif self.format == 1:
216 if date_val[2] < 0 or date_val[3]:
217 return self.display_iso(date_val)
218 else:
219 if date_val[0] == 0 and date_val[1] == 0:
220 value = str(date_val[2])
221 else:
222 value = self._tformat.replace('%m', str(date_val[1]))
223 value = value.replace('%d', str(date_val[0]))
224
225
226
227 value = value.replace('%Y', str(date_val[2]))
228 elif self.format == 2:
229
230 if date_val[0] == 0:
231 if date_val[1] == 0:
232 value = year
233 else:
234 value = "%s %s" % (self._months[date_val[1]], year)
235 else:
236 value = "%s %d, %s" % (self._months[date_val[1]], date_val[0], year)
237 elif self.format == 3:
238
239 if date_val[0] == 0:
240 if date_val[1] == 0:
241 value = year
242 else:
243 value = "%s %s" % (self.MONS[date_val[1]], year)
244 else:
245 value = "%s %d, %s" % (self.MONS[date_val[1]], date_val[0], year)
246 elif self.format == 4:
247
248 if date_val[0] == 0:
249 if date_val[1] == 0:
250 value = year
251 else:
252 value = "%s %s" % (self._months[date_val[1]], year)
253 else:
254
255
256 value = "%d. %s %s" % (date_val[0], self._months[date_val[1]], year)
257 else:
258
259 if date_val[0] == 0:
260 if date_val[1] == 0:
261 value = year
262 else:
263 value = "%s %s" % (self.MONS[date_val[1]], year)
264 else:
265
266
267 value = "%d. %s %s" % (date_val[0], self.MONS[date_val[1]], year)
268 if date_val[2] < 0:
269 return self._bce_str % value
270 else:
271 return value
272
274 year = date_val[2]
275 if date_val[0] == 0:
276 if date_val[1] == 0:
277 return year
278 else:
279 return u"%s %d" % (self.french[date_val[1]], year)
280
281 elif date_val[2] == 0 and date_val[1] == 13:
282
283 return self._bce_str % year
284
285 elif date_val[2] < 0:
286 return self._bce_str % year
287
288 else:
289 return u"%s %s %d" % (date_val[0], self.french[date_val[1]], year)
290
292 """
293 Return a text string representing the date.
294 """
295 mod = date.get_modifier()
296 cal = date.get_calendar()
297 qual = date.get_quality()
298 start = date.get_start_date()
299
300 qual_str = self._qual_str[qual]
301
302 if mod == Date.MOD_TEXTONLY:
303 return date.get_text()
304 elif start == Date.EMPTY:
305 return ""
306 elif mod == Date.MOD_SPAN:
307 d1 = self.display_cal[cal](start)
308 d2 = self.display_cal[cal](date.get_stop_date())
309 return "%s%s %s %s %s%s" % (qual_str, u'de', d1, u'à', d2, self.calendar[cal])
310 elif mod == Date.MOD_RANGE:
311 d1 = self.display_cal[cal](start)
312 d2 = self.display_cal[cal](date.get_stop_date())
313 return "%s%s %s %s %s%s" % (qual_str, u'entre', d1, u'et', d2, self.calendar[cal])
314 else:
315 text = self.display_cal[date.get_calendar()](start)
316 return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, self.calendar[cal])
317
318
319
320
321
322
323
324 register_datehandler(
325 ('fr_FR', 'fr', 'french', 'fr_CA', 'fr_BE', 'fr_CH'),
326 DateParserFR, DateDisplayFR)
327