1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """
23 Czech-specific classes for parsing and displaying dates.
24 """
25
26
27
28
29
30
31 import re
32
33
34
35
36
37
38 from gen.lib import Date
39 from _DateParser import DateParser
40 from _DateDisplay import DateDisplay
41 from _DateHandler import register_datehandler
42
43
44
45
46
47
49
50 modifier_to_int = {
51 u'před' : Date.MOD_BEFORE,
52 u'do' : Date.MOD_BEFORE,
53 u'po' : Date.MOD_AFTER,
54 u'asi' : Date.MOD_ABOUT,
55 u'kolem' : Date.MOD_ABOUT,
56 u'přibl.' : Date.MOD_ABOUT,
57 }
58
59 calendar_to_int = {
60 u'gregoriánský' : Date.CAL_GREGORIAN,
61 u'g' : Date.CAL_GREGORIAN,
62 u'juliánský' : Date.CAL_JULIAN,
63 u'j' : Date.CAL_JULIAN,
64 u'hebrejský' : Date.CAL_HEBREW,
65 u'h' : Date.CAL_HEBREW,
66 u'islámský' : Date.CAL_ISLAMIC,
67 u'i' : Date.CAL_ISLAMIC,
68 u'republikánský' : Date.CAL_FRENCH,
69 u'r' : Date.CAL_FRENCH,
70 u'perský' : Date.CAL_PERSIAN,
71 u'p' : Date.CAL_PERSIAN,
72 }
73
74 quality_to_int = {
75 u'odhadovaný' : Date.QUAL_ESTIMATED,
76 u'odh.' : Date.QUAL_ESTIMATED,
77 u'vypočtený' : Date.QUAL_CALCULATED,
78 u'vyp.' : Date.QUAL_CALCULATED,
79 }
80
82 DateParser.init_strings(self)
83 _span_1 = [u'od']
84 _span_2 = [u'do']
85 _range_1 = [u'mezi']
86 _range_2 = [u'a']
87 self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
88 ('|'.join(_span_1), '|'.join(_span_2)),
89 re.IGNORECASE)
90 self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
91 ('|'.join(_range_1), '|'.join(_range_2)),
92 re.IGNORECASE)
93
94
95
96
97
98
100
101 calendar = (
102 "", u" (juliánský)", u" (hebrejský)",
103 u" (republikánský)", u" (perský)", u" (islámský)"
104 )
105
106 _mod_str = ("", u"před ", u"po ", u"kolem ", "", "", "")
107
108 _qual_str = ("", "odh. ", "vyp. ")
109
110 formats = (
111 "RRRR-MM-DD (ISO)", "numerický", "Měsíc Den, Rok",
112 "MĚS Den, Rok", "Den, Měsíc, Rok", "Den MĚS Rok"
113 )
114
116 """
117 Return a text string representing the date.
118 """
119 mod = date.get_modifier()
120 cal = date.get_calendar()
121 qual = date.get_quality()
122 start = date.get_start_date()
123
124 qual_str = self._qual_str[qual]
125
126 if mod == Date.MOD_TEXTONLY:
127 return date.get_text()
128 elif start == Date.EMPTY:
129 return ""
130 elif mod == Date.MOD_SPAN:
131 d1 = self.display_cal[cal](start)
132 d2 = self.display_cal[cal](date.get_stop_date())
133 return "%s%s %s %s %s%s" % (qual_str, u'od', d1,
134 u'do', d2, self.calendar[cal])
135 elif mod == Date.MOD_RANGE:
136 d1 = self.display_cal[cal](start)
137 d2 = self.display_cal[cal](date.get_stop_date())
138 return "%s%s %s %s %s%s" % (qual_str, u'medzi',
139 d1, u'a', d2, self.calendar[cal])
140 else:
141 text = self.display_cal[date.get_calendar()](start)
142 return "%s%s%s%s" % (qual_str, self._mod_str[mod],
143 text, self.calendar[cal])
144
145
146
147
148
149
150 register_datehandler(('cs_CZ', 'cs', 'CZ'), DateParserCZ, DateDisplayCZ)
151