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 Finnish-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
50
51
52
54
55
56
57
58
59 modifier_to_int = {
60
61
62
63 u'ennen' : Date.MOD_BEFORE,
64 u'e.' : Date.MOD_BEFORE,
65 u'noin' : Date.MOD_ABOUT,
66 u'n.' : Date.MOD_ABOUT,
67 }
68 modifier_after_to_int = {
69
70
71 u'jälkeen' : Date.MOD_AFTER,
72 u'j.' : Date.MOD_AFTER,
73 }
74
75 bce = [u"ekr.", u"ekr"]
76
77 calendar_to_int = {
78 u'gregoriaaninen' : Date.CAL_GREGORIAN,
79 u'greg.' : Date.CAL_GREGORIAN,
80 u'juliaaninen' : Date.CAL_JULIAN,
81 u'jul.' : Date.CAL_JULIAN,
82 u'heprealainen' : Date.CAL_HEBREW,
83 u'hepr.' : Date.CAL_HEBREW,
84 u'islamilainen' : Date.CAL_ISLAMIC,
85 u'isl.' : Date.CAL_ISLAMIC,
86 u'ranskan vallankumouksen aikainen': Date.CAL_FRENCH,
87 u'ranskan v.' : Date.CAL_FRENCH,
88 u'persialainen' : Date.CAL_PERSIAN,
89 u'pers.' : Date.CAL_PERSIAN,
90 }
91
92 quality_to_int = {
93 u'arviolta' : Date.QUAL_ESTIMATED,
94 u'arv.' : Date.QUAL_ESTIMATED,
95 u'laskettuna' : Date.QUAL_CALCULATED,
96 u'lask.' : Date.QUAL_CALCULATED,
97 }
98
100 DateParser.init_strings(self)
101
102 self._span = re.compile(u"(?P<start>.+)\s+(-)\s+(?P<stop>.+)",
103 re.IGNORECASE)
104 self._range = re.compile(
105 u"(vuosien\s*)?(?P<start>.+)\s+ja\s+(?P<stop>.+)\s+välillä",
106 re.IGNORECASE)
107
108
109
110
111
112
114
115 calendar = ("",
116 u"(juliaaninen)",
117 u"(heprealainen)",
118 u"(ranskan v.)",
119 u"(persialainen)",
120 u"(islamilainen)")
121
122 _qual_str = (u"", u"arviolta", u"laskettuna")
123
124 _bce_str = u"%s ekr."
125
126 formats = (
127 "VVVV-KK-PP (ISO)",
128 "PP.KK.VVVV"
129 )
130
132 """
133 Return a text string representing the date.
134 """
135 mod = date.get_modifier()
136 qual = date.get_quality()
137 cal = date.get_calendar()
138 start = date.get_start_date()
139
140 if mod == Date.MOD_TEXTONLY:
141 return date.get_text()
142 if start == Date.EMPTY:
143 return u""
144
145
146 self.format = 1
147
148 if mod == Date.MOD_SPAN:
149 d1 = self.display_cal[cal](start)
150 d2 = self.display_cal[cal](date.get_stop_date())
151 text = u"%s - %s" % (d1, d2)
152 elif mod == Date.MOD_RANGE:
153 stop = date.get_stop_date()
154 if start[0] == 0 and start[1] == 0 and stop[0] == 0 and stop[1] == 0:
155 d1 = self.display_cal[cal](start)
156 d2 = self.display_cal[cal](stop)
157 text = u"vuosien %s ja %s välillä" % (d1, d2)
158 else:
159 d1 = self.display_cal[cal](start)
160 d2 = self.display_cal[cal](stop)
161 text = u"%s ja %s välillä" % (d1, d2)
162 else:
163 text = self.display_cal[date.get_calendar()](start)
164 if mod == Date.MOD_AFTER:
165 text = text + u" jälkeen"
166 elif mod == Date.MOD_ABOUT:
167 text = u"noin " + text
168 elif mod == Date.MOD_BEFORE:
169 text = u"ennen " + text
170
171 if qual:
172
173 text = u"%s %s" % (self._qual_str[qual], text)
174 if cal:
175
176 text = u"%s %s" % (text, self.calendar[cal])
177
178 return text
179
180
181
182
183
184
185 register_datehandler(('fi_FI', 'fi', 'finnish'), DateParserFI, DateDisplayFI)
186