1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """
24 U.S English date display class. Should serve as the base class for all
25 localized tasks.
26 """
27
28
29
30
31
32
33 import logging
34 log = logging.getLogger(".DateDisplay")
35
36
37
38
39
40
41 from gen.lib import Date
42 import GrampsLocale
43
44
45
46
47
48
50
51 _months = GrampsLocale.long_months
52 MONS = GrampsLocale.short_months
53
54 _tformat = GrampsLocale.tformat
55
56 hebrew = (
57 "", "Tishri", "Heshvan", "Kislev", "Tevet", "Shevat",
58 "AdarI", "AdarII", "Nisan", "Iyyar", "Sivan", "Tammuz",
59 "Av", "Elul"
60 )
61
62 french = (
63 u'',
64 u"Vendémiaire",
65 u'Brumaire',
66 u'Frimaire',
67 u"Nivôse",
68 u"Pluviôse",
69 u"Ventôse",
70 u'Germinal',
71 u"Floréal",
72 u'Prairial',
73 u'Messidor',
74 u'Thermidor',
75 u'Fructidor',
76 u'Extra',
77 )
78
79 persian = (
80 "", "Farvardin", "Ordibehesht", "Khordad", "Tir",
81 "Mordad", "Shahrivar", "Mehr", "Aban", "Azar",
82 "Dey", "Bahman", "Esfand"
83 )
84
85 islamic = (
86 "", "Muharram", "Safar", "Rabi`al-Awwal", "Rabi`ath-Thani",
87 "Jumada l-Ula", "Jumada t-Tania", "Rajab", "Sha`ban",
88 "Ramadan", "Shawwal", "Dhu l-Qa`da", "Dhu l-Hijja"
89 )
90
91 formats = ("YYYY-MM-DD (ISO)", )
92
93 calendar = (
94 "", " (Julian)", " (Hebrew)", " (French Republican)",
95 " (Persian)", " (Islamic)"
96 )
97
98 _mod_str = ("", "before ", "after ", "about ", "", "", "")
99
100 _qual_str = ("", "estimated ", "calculated ")
101
102 _bce_str = "%s B.C.E."
103
105 self.display_cal = [
106 self._display_gregorian,
107 self._display_julian,
108 self._display_hebrew,
109 self._display_french,
110 self._display_persian,
111 self._display_islamic,
112 ]
113
114 self.verify_format(format)
115 if format == None:
116 self.format = 0
117 else:
118 self.format = format
119
122
125
135
159
161 if val < 0:
162 val = - val
163
164 if slash:
165 if val % 100 == 99:
166 year = "%d/%d" % (val, (val%1000)+1)
167 elif val % 10 == 9:
168 year = "%d/%d" % (val, (val%100)+1)
169 else:
170 year = "%d/%d" % (val, (val%10)+1)
171 else:
172 year = "%d" % (val)
173
174 return year
175
177
178 year = self._slash_year(date_val[2], date_val[3])
179
180 if date_val[0] == 0 and date_val[1] == 0:
181
182 value = year
183 else:
184 value = "%s-%02d-%02d" % (year, date_val[1], date_val[0])
185 if date_val[2] < 0:
186 return self._bce_str % value
187 else:
188 return value
189
190 - def text_display(self, date):
191 """
192 Similar to the display task, except that if the value is a text only
193 value, it is enclosed in quotes.
194 """
195 return date.get_text()
196
197
199 year = self._slash_year(date_val[2], date_val[3])
200 if self.format == 0:
201 return self.display_iso(date_val)
202 elif self.format == 1:
203 if date_val[3]:
204 return self.display_iso(date_val)
205 else:
206 if date_val[0] == 0 and date_val[1] == 0:
207 value = str(date_val[2])
208 else:
209 value = self._tformat.replace('%m', str(date_val[1]))
210 value = value.replace('%d', str(date_val[0]))
211 value = value.replace('%Y', str(abs(date_val[2])))
212 value = value.replace('-', '/')
213 elif self.format == 2:
214
215 if date_val[0] == 0:
216 if date_val[1] == 0:
217 value = year
218 else:
219 value = "%s %s" % (self._months[date_val[1]], year)
220 else:
221 value = "%s %d, %s" % (self._months[date_val[1]],
222 date_val[0], year)
223 elif self.format == 3:
224
225 if date_val[0] == 0:
226 if date_val[1] == 0:
227 value = year
228 else:
229 value = "%s %s" % (self.MONS[date_val[1]], year)
230 else:
231 value = "%s %d, %s" % (self.MONS[date_val[1]],
232 date_val[0], year)
233 elif self.format == 4:
234
235 if date_val[0] == 0:
236 if date_val[1] == 0:
237 value = year
238 else:
239 value = "%s %s" % (self._months[date_val[1]], year)
240 else:
241 value = "%d %s %s" % (date_val[0], self._months[date_val[1]],
242 year)
243 else:
244
245 if date_val[0] == 0:
246 if date_val[1] == 0:
247 value = year
248 else:
249 value = "%s %s" % (self.MONS[date_val[1]], year)
250 else:
251 value = "%d %s %s" % (date_val[0], self.MONS[date_val[1]], year)
252 if date_val[2] < 0:
253 return self._bce_str % value
254 else:
255 return value
256
258
259 return self._display_gregorian(date_val)
260
262 year = abs(date_val[2])
263 if self.format == 0 or self.format == 1:
264 return self.display_iso(date_val)
265 else:
266 if date_val[0] == 0:
267 if date_val[1] == 0:
268 value = year
269 else:
270 value = u"%s %d" % (month_list[date_val[1]], year)
271 else:
272 value = u"%s %d, %s" % (month_list[date_val[1]], date_val[0], year)
273 if date_val[2] < 0:
274 return self._bce_str % value
275 else:
276 return value
277
279 year = abs(date_val[2])
280 if self.format == 0 or self.format == 1:
281 return self.display_iso(date_val)
282 else:
283 if date_val[0] == 0:
284 if date_val[1] == 0:
285 value = year
286 else:
287 value = u"%s %d" % (self.french[date_val[1]], year)
288 else:
289 value = u"%d %s %s" % (date_val[0], self.french[date_val[1]], year)
290 if date_val[2] < 0:
291 return self._bce_str % value
292 else:
293 return value
294
296 return self._display_calendar(date_val, self.hebrew)
297
299 return self._display_calendar(date_val, self.persian)
300
302 return self._display_calendar(date_val, self.islamic)
303
305 """
306 English language date display class.
307 """
308
309 formats = (
310 "YYYY-MM-DD (ISO)", "Numerical", "Month Day, Year",
311 "MON DAY, YEAR", "Day Month Year", "DAY MON YEAR"
312 )
313
315 """
316 Create a DateDisplay class that converts a Date object to a string
317 of the desired format. The format value must correspond to the format
318 list value (DateDisplay.format[]).
319 """
320
321 DateDisplay.__init__(self, format)
322
351