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 German-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"januar"] = 1
55 month_to_int[u"jan"] = 1
56 month_to_int[u"jänner"] = 1
57 month_to_int[u"jän"] = 1
58
59 month_to_int[u"januaris"] = 1
60 month_to_int[u"jenner"] = 1
61 month_to_int[u"feber"] = 2
62 month_to_int[u"februaris"] = 2
63 month_to_int[u"merz"] = 3
64 month_to_int[u"aprilis"] = 4
65 month_to_int[u"maius"] = 5
66 month_to_int[u"junius"] = 6
67 month_to_int[u"julius"] = 7
68 month_to_int[u"augst"] = 8
69 month_to_int[u"7ber"] = 9
70 month_to_int[u"7bris"] = 9
71 month_to_int[u"8ber"] = 10
72 month_to_int[u"8bris"] = 10
73 month_to_int[u"9ber"] = 11
74 month_to_int[u"9bris"] = 11
75 month_to_int[u"10ber"] = 12
76 month_to_int[u"10bris"] = 12
77 month_to_int[u"xber"] = 12
78 month_to_int[u"xbris"] = 12
79
80 modifier_to_int = {
81 u'vor' : Date.MOD_BEFORE,
82 u'nach' : Date.MOD_AFTER,
83 u'gegen' : Date.MOD_ABOUT,
84 u'um' : Date.MOD_ABOUT,
85 u'etwa' : Date.MOD_ABOUT,
86 u'circa' : Date.MOD_ABOUT,
87 u'ca.' : Date.MOD_ABOUT,
88 }
89
90 calendar_to_int = {
91 u'gregorianisch' : Date.CAL_GREGORIAN,
92 u'greg.' : Date.CAL_GREGORIAN,
93 u'julianisch' : Date.CAL_JULIAN,
94 u'jul.' : Date.CAL_JULIAN,
95 u'hebräisch' : Date.CAL_HEBREW,
96 u'hebr.' : Date.CAL_HEBREW,
97 u'islamisch' : Date.CAL_ISLAMIC,
98 u'isl.' : Date.CAL_ISLAMIC,
99 u'französisch republikanisch': Date.CAL_FRENCH,
100 u'franz.' : Date.CAL_FRENCH,
101 u'persisch' : Date.CAL_PERSIAN,
102 }
103
104 quality_to_int = {
105 u'geschätzt' : Date.QUAL_ESTIMATED,
106 u'gesch.' : Date.QUAL_ESTIMATED,
107 u'errechnet' : Date.QUAL_CALCULATED,
108 u'berechnet' : Date.QUAL_CALCULATED,
109 u'ber.' : Date.QUAL_CALCULATED,
110 }
111
112 bce = ["vor unserer Zeitrechnung", "vor unserer Zeit",
113 "vor der Zeitrechnung", "vor der Zeit",
114 "v. u. Z.", "v. d. Z.", "v.u.Z.", "v.d.Z.",
115 "vor Christi Geburt", "vor Christus", "v. Chr."] + DateParser.bce
116
118 DateParser.init_strings(self)
119 self._span = re.compile("(von|vom)\s+(?P<start>.+)\s+(bis)\s+(?P<stop>.+)",
120 re.IGNORECASE)
121 self._range = re.compile("zwischen\s+(?P<start>.+)\s+und\s+(?P<stop>.+)",
122 re.IGNORECASE)
123 self._text2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._mon_str,
124 re.IGNORECASE)
125 self._jtext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._jmon_str,
126 re.IGNORECASE)
127
128
129
130
131
132
134
135 calendar = (
136 "", u" (julianisch)", u" (hebräisch)",
137 u" (französisch republikanisch)", u" (persisch)", u" (islamisch)"
138 )
139
140 _mod_str = ("", u"vor ", u"nach ", u"etwa ", "", "", "")
141
142 _qual_str = ("", u"geschätzt ", u"errechnet ")
143
144 _bce_str = "%s v. u. Z."
145
146 formats = (
147 "JJJJ-MM-DD (ISO)", "Numerisch", "Monat Tag Jahr",
148 "MONAT Tag Jahr", "Tag. Monat Jahr", "Tag. MONAT Jahr"
149 )
150
152 year = self._slash_year(date_val[2], date_val[3])
153 if self.format == 0:
154 return self.display_iso(date_val)
155 elif self.format == 1:
156 if date_val[3]:
157 return self.display_iso(date_val)
158 else:
159 if date_val[0] == 0 and date_val[1] == 0:
160 value = str(date_val[2])
161 else:
162 value = self._tformat.replace('%m', str(date_val[1]))
163 value = value.replace('%d', str(date_val[0]))
164 value = value.replace('%Y', str(date_val[2]))
165 elif self.format == 2:
166
167 if date_val[0] == 0:
168 if date_val[1] == 0:
169 value = year
170 else:
171 value = "%s %s" % (self._months[date_val[1]], year)
172 else:
173 value = "%s %d, %s" % (self._months[date_val[1]], date_val[0], year)
174 elif self.format == 3:
175
176 if date_val[0] == 0:
177 if date_val[1] == 0:
178 value = year
179 else:
180 value = "%s %s" % (self.MONS[date_val[1]], year)
181 else:
182 value = "%s %d, %s" % (self.MONS[date_val[1]], date_val[0], year)
183 elif self.format == 4:
184
185 if date_val[0] == 0:
186 if date_val[1] == 0:
187 value = year
188 else:
189 value = "%s %s" % (self._months[date_val[1]], year)
190 else:
191 value = "%d. %s %s" % (date_val[0], self._months[date_val[1]], year)
192 else:
193
194 if date_val[0] == 0:
195 if date_val[1] == 0:
196 value = year
197 else:
198 value = "%s %s" % (self.MONS[date_val[1]], year)
199 else:
200 value = "%d. %s %s" % (date_val[0], self.MONS[date_val[1]], year)
201 if date_val[2] < 0:
202 return self._bce_str % value
203 else:
204 return value
205
207 """
208 Return a text string representing the date.
209 """
210 mod = date.get_modifier()
211 cal = date.get_calendar()
212 qual = date.get_quality()
213 start = date.get_start_date()
214
215 qual_str = self._qual_str[qual]
216
217 if mod == Date.MOD_TEXTONLY:
218 return date.get_text()
219 elif start == Date.EMPTY:
220 return ""
221 elif mod == Date.MOD_SPAN:
222 d1 = self.display_cal[cal](start)
223 d2 = self.display_cal[cal](date.get_stop_date())
224 return "%s%s %s %s %s%s" % (qual_str, u'von', d1, u'bis', d2, self.calendar[cal])
225 elif mod == Date.MOD_RANGE:
226 d1 = self.display_cal[cal](start)
227 d2 = self.display_cal[cal](date.get_stop_date())
228 return "%szwischen %s und %s%s" % (qual_str, d1, d2, self.calendar[cal])
229 else:
230 text = self.display_cal[date.get_calendar()](start)
231 return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, self.calendar[cal])
232
233
234
235
236
237
238 register_datehandler(('de_DE', 'german', 'de_AT', 'de_CH',
239 'de_LI', 'de_LU', 'de_BE', 'de'),
240 DateParserDE, DateDisplayDE)
241