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 Slovak-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 modifier_to_int = {
53 u'pred' : Date.MOD_BEFORE,
54 u'do' : Date.MOD_BEFORE,
55 u'po' : Date.MOD_AFTER,
56 u'asi' : Date.MOD_ABOUT,
57 u'okolo' : Date.MOD_ABOUT,
58 u'pribl.' : Date.MOD_ABOUT,
59 }
60
61 calendar_to_int = {
62 u'gregoriánsky' : Date.CAL_GREGORIAN,
63 u'g' : Date.CAL_GREGORIAN,
64 u'juliánský' : Date.CAL_JULIAN,
65 u'j' : Date.CAL_JULIAN,
66 u'hebrejský' : Date.CAL_HEBREW,
67 u'h' : Date.CAL_HEBREW,
68 u'islamský' : Date.CAL_ISLAMIC,
69 u'i' : Date.CAL_ISLAMIC,
70 u'republikánsky' : Date.CAL_FRENCH,
71 u'r' : Date.CAL_FRENCH,
72 u'perzský' : Date.CAL_PERSIAN,
73 u'p' : Date.CAL_PERSIAN,
74 }
75
76 quality_to_int = {
77 u'odhadovaný' : Date.QUAL_ESTIMATED,
78 u'odh.' : Date.QUAL_ESTIMATED,
79 u'vypočítaný' : Date.QUAL_CALCULATED,
80 u'vyp.' : Date.QUAL_CALCULATED,
81 }
82
84 DateParser.init_strings(self)
85 _span_1 = [u'od']
86 _span_2 = [u'do']
87 _range_1 = [u'medzi']
88 _range_2 = [u'a']
89 self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
90 ('|'.join(_span_1), '|'.join(_span_2)),
91 re.IGNORECASE)
92 self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
93 ('|'.join(_range_1), '|'.join(_range_2)),
94 re.IGNORECASE)
95
96
97
98
99
100
102
103 calendar = (
104 "", u" (juliánský)", u" (hebrejský)",
105 u" (republikánsky)", u" (perzský)", u" (islamský)"
106 )
107
108 _mod_str = ("", u"pred ", u"po ", u"okolo ", "", "", "")
109
110 _qual_str = ("", "odh. ", "vyp. ")
111
112 formats = (
113 "RRRR-MM-DD (ISO)", "numerický", "Mesiac Deň, Rok",
114 "MES Deň, Rok", "Deň, Mesiac, Rok", "Deň MES Rok"
115 )
116
118 """
119 Return a text string representing the date.
120 """
121 mod = date.get_modifier()
122 cal = date.get_calendar()
123 qual = date.get_quality()
124 start = date.get_start_date()
125
126 qual_str = self._qual_str[qual]
127
128 if mod == Date.MOD_TEXTONLY:
129 return date.get_text()
130 elif start == Date.EMPTY:
131 return ""
132 elif mod == Date.MOD_SPAN:
133 d1 = self.display_cal[cal](start)
134 d2 = self.display_cal[cal](date.get_stop_date())
135 return "%s%s %s %s %s%s" % (qual_str, u'od', d1,
136 u'do', d2, self.calendar[cal])
137 elif mod == Date.MOD_RANGE:
138 d1 = self.display_cal[cal](start)
139 d2 = self.display_cal[cal](date.get_stop_date())
140 return "%s%s %s %s %s%s" % (qual_str, u'medzi',
141 d1, u'a', d2, self.calendar[cal])
142 else:
143 text = self.display_cal[date.get_calendar()](start)
144 return "%s%s%s%s" % (qual_str, self._mod_str[mod],
145 text, self.calendar[cal])
146
147
148
149
150
151
152 register_datehandler(('sk_SK', 'sk', 'SK'), DateParserSK, DateDisplaySK)
153