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 Lithuanian-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'prieš' : Date.MOD_BEFORE,
54 u'po' : Date.MOD_AFTER,
55 u'apie' : Date.MOD_ABOUT,
56 }
57
58 calendar_to_int = {
59 u'grigaliaus' : Date.CAL_GREGORIAN,
60 u'g' : Date.CAL_GREGORIAN,
61 u'julijaus' : Date.CAL_JULIAN,
62 u'j' : Date.CAL_JULIAN,
63 u'hebrajų' : Date.CAL_HEBREW,
64 u'h' : Date.CAL_HEBREW,
65 u'islamo' : Date.CAL_ISLAMIC,
66 u'i' : Date.CAL_ISLAMIC,
67 u'prancuzų respublikos': Date.CAL_FRENCH,
68 u'r' : Date.CAL_FRENCH,
69 u'persų' : Date.CAL_PERSIAN,
70 u'p' : Date.CAL_PERSIAN,
71 }
72
73 quality_to_int = {
74 u'apytikriai' : Date.QUAL_ESTIMATED,
75 u'apskaičiuota' : Date.QUAL_CALCULATED,
76 }
77
79 DateParser.init_strings(self)
80 _span_1 = [u'nuo']
81 _span_2 = [u'iki']
82 _range_1 = [u'tarp']
83 _range_2 = [u'ir']
84 self._span = re.compile(
85 "(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
86 ('|'.join(_span_1), '|'.join(_span_2)),
87 re.IGNORECASE)
88 self._range = re.compile(
89 "(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
90 ('|'.join(_range_1), '|'.join(_range_2)),
91 re.IGNORECASE)
92
93
94
95
96
97
99
100 calendar = (
101 u"", u" (julijaus)",
102 u" (hebrajų)",
103 u" (prancuzų respublikos)",
104 u" (persų)",
105 u" (islamo)"
106 )
107
108 _mod_str = (u"",
109 u"prieš ",
110 u"po ",
111 u"apie ",
112 u"", u"", u"")
113
114 _qual_str = (u"", u"apytikriai ", u"apskaičiuota ")
115
116 formats = (
117 "YYYY-MM-DD (ISO)", "Skaitmeninis", "Mėnuo Diena, Metai",
118 "Mėn DD, YYYY", "Diena Mėnuo Metai", "DD Mėn YYYY"
119 )
120
122 """
123 Return a text string representing the date.
124 """
125 mod = date.get_modifier()
126 cal = date.get_calendar()
127 qual = date.get_quality()
128 start = date.get_start_date()
129
130 qual_str = self._qual_str[qual]
131
132 if mod == Date.MOD_TEXTONLY:
133 return date.get_text()
134 elif start == Date.EMPTY:
135 return ""
136 elif mod == Date.MOD_SPAN:
137 d1 = self.display_cal[cal](start)
138 d2 = self.display_cal[cal](date.get_stop_date())
139 return "%s%s %s %s %s%s" % (qual_str, u'nuo', d1, u'iki',
140 d2, self.calendar[cal])
141 elif mod == Date.MOD_RANGE:
142 d1 = self.display_cal[cal](start)
143 d2 = self.display_cal[cal](date.get_stop_date())
144 return "%s%s %s %s %s%s" % (qual_str, u'tarp', d1, u'ir',
145 d2, self.calendar[cal])
146 else:
147 text = self.display_cal[date.get_calendar()](start)
148 return "%s%s%s%s" % (qual_str, self._mod_str[mod], text,
149 self.calendar[cal])
150
151
152
153
154
155
156 register_datehandler(('lt_LT', 'lt', 'lithuanian'), DateParserLT, DateDisplayLT)
157