added and/or clarified various date handler comments

also slightly reformatted a few date handler lines
and fixed one (locale-specific) date handler typo


svn: r22672
This commit is contained in:
Paul Franklin 2013-07-13 18:01:08 +00:00
parent c7ad6127da
commit e4cbeaef19
25 changed files with 152 additions and 94 deletions

View File

@ -168,7 +168,7 @@ class DateParserBG(DateParser):
_span_2 = ['до'] _span_2 = ['до']
_range_1 = ['между'] _range_1 = ['между']
_range_2 = ['и'] _range_2 = ['и']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1), '|'.join(_span_2)), ('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE) re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
@ -211,6 +211,8 @@ class DateDisplayBG(DateDisplay):
formats = ( formats = (
"ГГГГ-ММ-ДД (ISO)", "Числов", "Месец Ден, Година", "Мес. Ден, Година", "Ден Месец Година", "Ден Мес. Година" "ГГГГ-ММ-ДД (ISO)", "Числов", "Месец Ден, Година", "Мес. Ден, Година", "Ден Месец Година", "Ден Мес. Година"
) )
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
hebrew = ( "", hebrew = ( "",
"Тишрей", "Тишрей",

View File

@ -102,7 +102,7 @@ class DateParserCA(DateParser):
_span_2 = ['fins a'] _span_2 = ['fins a']
_range_1 = ['entre', 'ent\.', 'ent'] _range_1 = ['entre', 'ent\.', 'ent']
_range_2 = ['i'] _range_2 = ['i']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1), '|'.join(_span_2)), ('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE) re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
@ -156,6 +156,8 @@ class DateDisplayCA(DateDisplay):
"AAAA-MM-DD (ISO)", "Numèrica", "Mes Dia, Any", "AAAA-MM-DD (ISO)", "Numèrica", "Mes Dia, Any",
"MES Dia, Any", "Dia Mes, Any", "Dia MES, Any" "MES Dia, Any", "Dia Mes, Any", "Dia MES, Any"
) )
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
def display(self, date): def display(self, date):
""" """

View File

@ -218,7 +218,8 @@ class DateDisplayCZ(DateDisplay):
"den. měsíc rok", "den. měsíc rok",
"den. měs rok" "den. měs rok"
) )
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
def display(self, date): def display(self, date):
""" """

View File

@ -121,6 +121,8 @@ class DateDisplayDa(DateDisplay):
"Dag måned år", "Dag måned år",
"Dag md År", "Dag md År",
) )
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
calendar = ( calendar = (
"", "",

View File

@ -221,12 +221,18 @@ class DateDisplayDE(DateDisplay):
"JJJJ-MM-DD (ISO)", "Numerisch", "Monat Tag Jahr", "JJJJ-MM-DD (ISO)", "Numerisch", "Monat Tag Jahr",
"MONAT Tag Jahr", "Tag. Monat Jahr", "Tag. MONAT Jahr" "MONAT Tag Jahr", "Tag. Monat Jahr", "Tag. MONAT Jahr"
) )
# this definition must agree with its "_display_gregorian" method
def _display_gregorian(self, date_val): def _display_gregorian(self, date_val):
"""
display gregorian calendar date in different format
"""
# this must agree with its locale-specific "formats" definition
year = self._slash_year(date_val[2], date_val[3]) year = self._slash_year(date_val[2], date_val[3])
if self.format == 0: if self.format == 0:
return self.display_iso(date_val) return self.display_iso(date_val)
elif self.format == 1: elif self.format == 1:
# day.month_number.year
if date_val[3]: if date_val[3]:
return self.display_iso(date_val) return self.display_iso(date_val)
else: else:
@ -237,7 +243,7 @@ class DateDisplayDE(DateDisplay):
value = value.replace('%d', str(date_val[0])) value = value.replace('%d', str(date_val[0]))
value = value.replace('%Y', str(date_val[2])) value = value.replace('%Y', str(date_val[2]))
elif self.format == 2: elif self.format == 2:
# Month Day, Year # month_name day, year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
@ -247,7 +253,7 @@ class DateDisplayDE(DateDisplay):
value = "%s %d, %s" % (self.long_months[date_val[1]], value = "%s %d, %s" % (self.long_months[date_val[1]],
date_val[0], year) date_val[0], year)
elif self.format == 3: elif self.format == 3:
# MON Day, Year # month_abbreviation day, year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
@ -257,7 +263,7 @@ class DateDisplayDE(DateDisplay):
value = "%s %d, %s" % (self.short_months[date_val[1]], value = "%s %d, %s" % (self.short_months[date_val[1]],
date_val[0], year) date_val[0], year)
elif self.format == 4: elif self.format == 4:
# Day Month Year # day. month_name year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
@ -267,7 +273,7 @@ class DateDisplayDE(DateDisplay):
value = "%d. %s %s" % (date_val[0], value = "%d. %s %s" % (date_val[0],
self.long_months[date_val[1]], year) self.long_months[date_val[1]], year)
else: else:
# Day MON Year # day. month_abbreviation year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year

View File

@ -101,7 +101,7 @@ class DateParserES(DateParser):
_span_2 = ['a'] _span_2 = ['a']
_range_1 = ['entre', 'ent\.', 'ent'] _range_1 = ['entre', 'ent\.', 'ent']
_range_2 = ['y'] _range_2 = ['y']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1), '|'.join(_span_2)), ('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE) re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
@ -140,6 +140,8 @@ class DateDisplayES(DateDisplay):
"AAAA-MM-DD (ISO)", "Numérica", "Mes Día, Año", "AAAA-MM-DD (ISO)", "Numérica", "Mes Día, Año",
"MES Día, Año", "Día Mes, Año", "Día MES, Año" "MES Día, Año", "Día Mes, Año", "Día MES, Año"
) )
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
def display(self, date): def display(self, date):
""" """

View File

@ -141,6 +141,8 @@ class DateDisplayFI(DateDisplay):
"VVVV-KK-PP (ISO)", "VVVV-KK-PP (ISO)",
"PP.KK.VVVV" "PP.KK.VVVV"
) )
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
def display(self, date): def display(self, date):
""" """

View File

@ -285,11 +285,13 @@ class DateDisplayFR(DateDisplay):
"Mois Jour, Année", # 6 "Mois Jour, Année", # 6
"MOI Jour, Année", # 7 "MOI Jour, Année", # 7
) )
# this definition must agree with its "_display_gregorian" method
def _display_gregorian(self, date_val): def _display_gregorian(self, date_val):
""" """
display gregorian calendar date in different format display gregorian calendar date in different format
""" """
# this must agree with its locale-specific "formats" definition
year = self._slash_year(date_val[2], date_val[3]) year = self._slash_year(date_val[2], date_val[3])
if self.format == 0: if self.format == 0:
@ -316,7 +318,7 @@ class DateDisplayFR(DateDisplay):
value = value.replace('%Y', str(date_val[2])) value = value.replace('%Y', str(date_val[2]))
elif self.format == 2: elif self.format == 2:
# Day Month Year # day month_name year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
@ -329,7 +331,7 @@ class DateDisplayFR(DateDisplay):
self.long_months[date_val[1]], year) self.long_months[date_val[1]], year)
elif self.format == 3: elif self.format == 3:
# Day MON Year # day month_abbreviation year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
@ -342,7 +344,7 @@ class DateDisplayFR(DateDisplay):
self.short_months[date_val[1]], year) self.short_months[date_val[1]], year)
elif self.format == 4: elif self.format == 4:
# Day. Month Year # day. month_name year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
@ -360,7 +362,7 @@ class DateDisplayFR(DateDisplay):
year) year)
elif self.format == 5: elif self.format == 5:
# Day. MON Year # day. month_abbreviation year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
@ -377,7 +379,7 @@ class DateDisplayFR(DateDisplay):
self.short_months[date_val[1]], year) self.short_months[date_val[1]], year)
elif self.format == 6: elif self.format == 6:
# Month Day, Year # month_name day, year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
@ -389,7 +391,7 @@ class DateDisplayFR(DateDisplay):
date_val[0], year) date_val[0], year)
elif self.format == 7: elif self.format == 7:
# MON Day, Year # month_abbreviation day, year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:

View File

@ -247,6 +247,7 @@ class DateDisplayHR(DateDisplay):
"D. MMMM GGGG.", "D. MMMM GGGG.",
"D. Rb GGGG." "D. Rb GGGG."
) )
# this definition must agree with its "_display_gregorian" method
roman_months = ( roman_months = (
"", "",
@ -268,10 +269,12 @@ class DateDisplayHR(DateDisplay):
""" """
display gregorian calendar date in different format display gregorian calendar date in different format
""" """
# this must agree with its locale-specific "formats" definition
year = self._slash_year(date_val[2], date_val[3]) year = self._slash_year(date_val[2], date_val[3])
if self.format == 0: if self.format == 0:
return self.display_iso(date_val) return self.display_iso(date_val)
elif self.format == 1: elif self.format == 1:
# numerical
if date_val[3]: if date_val[3]:
return self.display_iso(date_val) return self.display_iso(date_val)
else: else:
@ -283,7 +286,7 @@ class DateDisplayHR(DateDisplay):
value = value.replace('%Y', str(abs(date_val[2]))) value = value.replace('%Y', str(abs(date_val[2])))
value = value.replace('-', '/') value = value.replace('-', '/')
elif self.format == 2: elif self.format == 2:
# Day.Month.Year. # day.month_number.year.
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
@ -292,7 +295,7 @@ class DateDisplayHR(DateDisplay):
else: else:
value = "%s.%d.%s." % (date_val[0], date_val[1], year) value = "%s.%d.%s." % (date_val[0], date_val[1], year)
elif self.format == 3: elif self.format == 3:
# Day. MONTH year. # day. month_name year.
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = "%s." % year value = "%s." % year
@ -300,9 +303,9 @@ class DateDisplayHR(DateDisplay):
value = "%s %s." % (self.long_months[date_val[1]], year) value = "%s %s." % (self.long_months[date_val[1]], year)
else: else:
value = "%d. %s %s." % (date_val[0], value = "%d. %s %s." % (date_val[0],
self.long_months[date_val[1]], year) self.long_months[date_val[1]], year)
else: else:
# Day RomanMon Year # day. Roman_number_month year.
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = "%s." % year value = "%s." % year
@ -310,7 +313,7 @@ class DateDisplayHR(DateDisplay):
value = "%s %s." % (self.roman_months[date_val[1]], year) value = "%s %s." % (self.roman_months[date_val[1]], year)
else: else:
value = "%d. %s %s." % (date_val[0], value = "%d. %s %s." % (date_val[0],
self.roman_months[date_val[1]], year) self.roman_months[date_val[1]], year)
if date_val[2] < 0: if date_val[2] < 0:
return self._bce_str % value return self._bce_str % value
else: else:

View File

@ -98,7 +98,7 @@ class DateParserIT(DateParser):
_span_2 = ['al', 'a'] _span_2 = ['al', 'a']
_range_1 = ['tra', 'fra'] _range_1 = ['tra', 'fra']
_range_2 = ['e'] _range_2 = ['e']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1), '|'.join(_span_2)), ('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE) re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
@ -152,6 +152,8 @@ class DateDisplayIT(DateDisplay):
"AAAA-MM-DD (ISO)", "Numerico", "Mese Giorno Anno", "AAAA-MM-DD (ISO)", "Numerico", "Mese Giorno Anno",
"MES Giorno, Anno", "Giorno Mese Anno", "Giorno MES Anno" "MES Giorno, Anno", "Giorno Mese Anno", "Giorno MES Anno"
) )
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
def display(self, date): def display(self, date):
""" """

View File

@ -136,14 +136,12 @@ class DateParserLT(DateParser):
_span_2 = ['iki'] _span_2 = ['iki']
_range_1 = ['tarp'] _range_1 = ['tarp']
_range_2 = ['ir'] _range_2 = ['ir']
self._span = re.compile( self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % ('|'.join(_span_1), '|'.join(_span_2)),
('|'.join(_span_1), '|'.join(_span_2)), re.IGNORECASE)
re.IGNORECASE) self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
self._range = re.compile( ('|'.join(_range_1), '|'.join(_range_2)),
"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % re.IGNORECASE)
('|'.join(_range_1), '|'.join(_range_2)),
re.IGNORECASE)
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -206,32 +204,30 @@ class DateDisplayLT(DateDisplay):
formats = ( formats = (
"mmmm-MM-DD (ISO)", "mmmm m. mėnesio diena d.", "Mėn diena, metai") "mmmm-MM-DD (ISO)", "mmmm m. mėnesio diena d.", "Mėn diena, metai")
# this definition must agree with its "_display_gregorian" method
def _display_gregorian(self, date_val): def _display_gregorian(self, date_val):
""" """
display gregorian calendar date in different format display gregorian calendar date in different format
""" """
# this must agree with its locale-specific "formats" definition
value = self.display_iso(date_val) value = self.display_iso(date_val)
year = self._slash_year(date_val[2], date_val[3]) year = self._slash_year(date_val[2], date_val[3])
if self.format == 0: if self.format == 0:
return self.display_iso(date_val) return self.display_iso(date_val)
elif self.format == 1: elif self.format == 1:
# mmmm m. mėnesio diena d. (year m. month_name day d.)
# mmmm m. mėnesio diena d. (YYYY m. month DD d.)
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
else: else:
value = "%s m. %s" % (year, self.long_months_vardininkas[date_val[1]]) value = "%s m. %s" % (year, self.long_months_vardininkas[date_val[1]])
else: else:
value = "%s m. %s %d d." % (year, self.long_months[date_val[1]], value = "%s m. %s %d d." % (year,
date_val[0]) self.long_months[date_val[1]],
date_val[0])
elif self.format == 2: elif self.format == 2:
# month_abbreviation day, year
# MON Day, Year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
@ -240,8 +236,6 @@ class DateDisplayLT(DateDisplay):
else: else:
value = "%s %d, %s" % (self.short_months[date_val[1]], value = "%s %d, %s" % (self.short_months[date_val[1]],
date_val[0], year) date_val[0], year)
if date_val[2] < 0: if date_val[2] < 0:
return self._bce_str % value return self._bce_str % value
else: else:

View File

@ -121,6 +121,8 @@ class DateDisplayNb(DateDisplay):
"Dag måned år", "Dag måned år",
"Dag Mån År", "Dag Mån År",
) )
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
calendar = ( calendar = (
"", "",

View File

@ -165,8 +165,13 @@ class DateDisplayNL(DateDisplay):
"JJJJ-MM-DD (ISO)", "Numerisch DD/MM/JJ", "Maand Dag, Jaar", "JJJJ-MM-DD (ISO)", "Numerisch DD/MM/JJ", "Maand Dag, Jaar",
"Mnd. Dag Jaar", "Dag Maand Jaar", "Dag Mnd. Jaar" "Mnd. Dag Jaar", "Dag Maand Jaar", "Dag Mnd. Jaar"
) )
# this definition must agree with its "_display_gregorian" method
def _display_gregorian(self, date_val): def _display_gregorian(self, date_val):
"""
display gregorian calendar date in different format
"""
# this must agree with its locale-specific "formats" definition
year = self._slash_year(date_val[2], date_val[3]) year = self._slash_year(date_val[2], date_val[3])
if self.format == 0: if self.format == 0:
return self.display_iso(date_val) return self.display_iso(date_val)
@ -174,7 +179,7 @@ class DateDisplayNL(DateDisplay):
if date_val[3]: if date_val[3]:
return self.display_iso(date_val) return self.display_iso(date_val)
else: else:
# Numeric # day/month_number/year
if date_val[0] == date_val[1] == 0: if date_val[0] == date_val[1] == 0:
value = str(date_val[2]) value = str(date_val[2])
else: else:
@ -183,7 +188,7 @@ class DateDisplayNL(DateDisplay):
value = value.replace('%Y', str(abs(date_val[2]))) value = value.replace('%Y', str(abs(date_val[2])))
value = value.replace('-', '/') value = value.replace('-', '/')
elif self.format == 2: elif self.format == 2:
# Month Day, Year # month_name day, year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
@ -193,7 +198,7 @@ class DateDisplayNL(DateDisplay):
value = "%s %d, %s" % (self.long_months[date_val[1]], value = "%s %d, %s" % (self.long_months[date_val[1]],
date_val[0], year) date_val[0], year)
elif self.format == 3: elif self.format == 3:
# Mnd Day, Year # month_abbreviation day, year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
@ -203,7 +208,7 @@ class DateDisplayNL(DateDisplay):
value = "%s %d, %s" % (self.short_months[date_val[1]], value = "%s %d, %s" % (self.short_months[date_val[1]],
date_val[0], year) date_val[0], year)
elif self.format == 4: elif self.format == 4:
# Day Month Year # day month_name year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
@ -213,7 +218,7 @@ class DateDisplayNL(DateDisplay):
value = "%d %s %s" % (date_val[0], value = "%d %s %s" % (date_val[0],
self.long_months[date_val[1]], year) self.long_months[date_val[1]], year)
else: else:
# Day Mnd Year # day month_abbreviation year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
@ -221,7 +226,7 @@ class DateDisplayNL(DateDisplay):
value = "%s %s" % (self.short_months[date_val[1]], year) value = "%s %s" % (self.short_months[date_val[1]], year)
else: else:
value = "%d %s %s" % (date_val[0], value = "%d %s %s" % (date_val[0],
self.short_months[date_val[1]], year) self.short_months[date_val[1]], year)
if date_val[2] < 0: if date_val[2] < 0:
return self._bce_str % value return self._bce_str % value
else: else:

View File

@ -199,6 +199,7 @@ class DateDisplayPL(DateDisplay):
"RRRR-MM-DD (ISO)", "Numeryczny", "Miesiąc Dzień, Rok", "RRRR-MM-DD (ISO)", "Numeryczny", "Miesiąc Dzień, Rok",
"Dzień.Miesiąc.Rok", "Dzień Miesiąc Rok", "Dzień MieRzym Rok" "Dzień.Miesiąc.Rok", "Dzień Miesiąc Rok", "Dzień MieRzym Rok"
) )
# this definition must agree with its "_display_gregorian" method
roman_months = ( roman_months = (
"", "",
@ -217,10 +218,15 @@ class DateDisplayPL(DateDisplay):
) )
def _display_gregorian(self, date_val): def _display_gregorian(self, date_val):
"""
display gregorian calendar date in different format
"""
# this must agree with its locale-specific "formats" definition
year = self._slash_year(date_val[2], date_val[3]) year = self._slash_year(date_val[2], date_val[3])
if self.format == 0: if self.format == 0:
return self.display_iso(date_val) return self.display_iso(date_val)
elif self.format == 1: elif self.format == 1:
# month_number.day.year
if date_val[3]: if date_val[3]:
return self.display_iso(date_val) return self.display_iso(date_val)
else: else:
@ -229,9 +235,9 @@ class DateDisplayPL(DateDisplay):
else: else:
value = self._tformat.replace('%m', str(date_val[0])) value = self._tformat.replace('%m', str(date_val[0]))
value = value.replace('%d', str(date_val[1])) value = value.replace('%d', str(date_val[1]))
value = value.replace('%y', str(date_val[2])) value = value.replace('%Y', str(date_val[2]))
elif self.format == 2: elif self.format == 2:
# Month Day, Year # month_name day, year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
@ -241,7 +247,7 @@ class DateDisplayPL(DateDisplay):
value = "%s %d, %s" % (self.long_months[date_val[1]], value = "%s %d, %s" % (self.long_months[date_val[1]],
date_val[0], year) date_val[0], year)
elif self.format == 3: elif self.format == 3:
# Day. Month. Year # day. month_number. year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
@ -250,7 +256,7 @@ class DateDisplayPL(DateDisplay):
else: else:
value = "%d.%d.%s" % (date_val[0], date_val[1], year) value = "%d.%d.%s" % (date_val[0], date_val[1], year)
elif self.format == 4: elif self.format == 4:
# Day Month Year # day month_name year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
@ -260,7 +266,7 @@ class DateDisplayPL(DateDisplay):
value = "%d %s %s" % (date_val[0], value = "%d %s %s" % (date_val[0],
self.long_months[date_val[1]], year) self.long_months[date_val[1]], year)
else: else:
# Day RomanMon Year # day Roman_number_month year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year

View File

@ -106,12 +106,12 @@ class DateParserPT(DateParser):
_span_2 = ['a'] _span_2 = ['a']
_range_1 = ['entre','ent\.','ent'] _range_1 = ['entre','ent\.','ent']
_range_2 = ['e'] _range_2 = ['e']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1),'|'.join(_span_2)), ('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE) re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1),'|'.join(_range_2)), ('|'.join(_range_1), '|'.join(_range_2)),
re.IGNORECASE) re.IGNORECASE)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -143,6 +143,8 @@ class DateDisplayPT(DateDisplay):
"AAAA-MM-DD (ISO)", "Numérica", "Mês Dia, Ano", "AAAA-MM-DD (ISO)", "Numérica", "Mês Dia, Ano",
"MÊS Dia, Ano", "Dia Mês, Ano", "Dia MÊS, Ano" "MÊS Dia, Ano", "Dia Mês, Ano", "Dia MÊS, Ano"
) )
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
def display(self,date): def display(self,date):
""" """

View File

@ -222,12 +222,12 @@ class DateParserRU(DateParser):
_span_2 = ['по'] _span_2 = ['по']
_range_1 = ['между', 'меж\.', 'меж'] _range_1 = ['между', 'меж\.', 'меж']
_range_2 = ['и'] _range_2 = ['и']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1), '|'.join(_span_2)), ('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE) re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1), '|'.join(_range_2)), ('|'.join(_range_1), '|'.join(_range_2)),
re.IGNORECASE) re.IGNORECASE)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -270,6 +270,8 @@ class DateDisplayRU(DateDisplay):
"ГГГГ-ММ-ДД (ISO)", "Численный", "Месяц День, Год", "ГГГГ-ММ-ДД (ISO)", "Численный", "Месяц День, Год",
"МЕС ДД, ГГГГ", "День Месяц, Год", "ДД МЕС, ГГГГ" "МЕС ДД, ГГГГ", "День Месяц, Год", "ДД МЕС, ГГГГ"
) )
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
hebrew = ( "", hebrew = ( "",
"тишрея", "тишрея",

View File

@ -88,7 +88,7 @@ class DateParserSK(DateParser):
_span_2 = ['do'] _span_2 = ['do']
_range_1 = ['medzi'] _range_1 = ['medzi']
_range_2 = ['a'] _range_2 = ['a']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1), '|'.join(_span_2)), ('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE) re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
@ -125,6 +125,8 @@ class DateDisplaySK(DateDisplay):
"RRRR-MM-DD (ISO)", "numerický", "Mesiac Deň, Rok", "RRRR-MM-DD (ISO)", "numerický", "Mesiac Deň, Rok",
"MES Deň, Rok", "Deň, Mesiac, Rok", "Deň MES Rok" "MES Deň, Rok", "Deň, Mesiac, Rok", "Deň MES Rok"
) )
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
def display(self, date): def display(self, date):
""" """

View File

@ -223,16 +223,18 @@ class DateDisplaySL(DateDisplay):
"dan. mes. leto", "dan. mes. leto",
"dan. mesec leto" "dan. mesec leto"
) )
# this definition must agree with its "_display_gregorian" method
def _display_gregorian(self, date_val): def _display_gregorian(self, date_val):
""" """
display gregorian calendar date in different format display gregorian calendar date in different format
""" """
# this must agree with its locale-specific "formats" definition
year = self._slash_year(date_val[2], date_val[3]) year = self._slash_year(date_val[2], date_val[3])
if self.format == 0: if self.format == 0:
return self.display_iso(date_val) return self.display_iso(date_val)
elif self.format == 1: elif self.format == 1:
# D. M. YYYY # day. month_number. year
if date_val[3]: if date_val[3]:
return self.display_iso(date_val) return self.display_iso(date_val)
else: else:
@ -244,7 +246,7 @@ class DateDisplaySL(DateDisplay):
value = value.replace('%Y', str(date_val[2])) value = value.replace('%Y', str(date_val[2]))
value = value.replace('-', '. ') value = value.replace('-', '. ')
elif self.format == 2: elif self.format == 2:
# D. mon. YYYY # day. month_abbreviation. year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
@ -254,7 +256,7 @@ class DateDisplaySL(DateDisplay):
value = "%d. %s. %s" % (date_val[0], value = "%d. %s. %s" % (date_val[0],
self.short_months[date_val[1]], year) self.short_months[date_val[1]], year)
else: else:
# D. month YYYY # day. month_name year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = "%s." % year value = "%s." % year

View File

@ -220,12 +220,12 @@ class DateParserSR(DateParser):
_span_2 = ['do', 'до'] _span_2 = ['do', 'до']
_range_1 = ['između', 'између'] _range_1 = ['između', 'између']
_range_2 = ['i', 'и'] _range_2 = ['i', 'и']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1),'|'.join(_span_2)), ('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE) re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1),'|'.join(_range_2)), ('|'.join(_range_1), '|'.join(_range_2)),
re.IGNORECASE) re.IGNORECASE)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -271,17 +271,18 @@ class DateDisplaySR_latin(DateDisplay):
"D. Mesec GGGG.", "D. Mesec GGGG.",
"D. Rb GGGG." "D. Rb GGGG."
) )
# this definition must agree with its "_display_gregorian" method
def _display_gregorian(self, date_val): def _display_gregorian(self, date_val):
""" """
display gregorian calendar date in different format display gregorian calendar date in different format
""" """
# this must agree with its locale-specific "formats" definition
year = self._slash_year(date_val[2], date_val[3]) year = self._slash_year(date_val[2], date_val[3])
if self.format == 0: if self.format == 0:
return self.display_iso(date_val) return self.display_iso(date_val)
elif self.format == 1: elif self.format == 1:
## DD.MM.YYYY. # day.month_number.year.
if date_val[3]: if date_val[3]:
return self.display_iso(date_val) return self.display_iso(date_val)
else: else:
@ -294,7 +295,7 @@ class DateDisplaySR_latin(DateDisplay):
#some locale magic already provides the right separator #some locale magic already provides the right separator
#value = value.replace('/', '.') #value = value.replace('/', '.')
elif self.format == 2: elif self.format == 2:
# Day. MON Year. # day. month_abbreviation year.
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = "%s." % year value = "%s." % year
@ -302,9 +303,9 @@ class DateDisplaySR_latin(DateDisplay):
value = "%s %s." % (self.short_months[date_val[1]], year) value = "%s %s." % (self.short_months[date_val[1]], year)
else: else:
value = "%d. %s %s." % (date_val[0], value = "%d. %s %s." % (date_val[0],
self.short_months[date_val[1]], year) self.short_months[date_val[1]], year)
elif self.format == 3: elif self.format == 3:
# Day. MONTH Year. # day. month_name year.
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = "%s." % year value = "%s." % year
@ -312,9 +313,9 @@ class DateDisplaySR_latin(DateDisplay):
value = "%s %s." % (self.long_months[date_val[1]], year) value = "%s %s." % (self.long_months[date_val[1]], year)
else: else:
value = "%d. %s %s." % (date_val[0], value = "%d. %s %s." % (date_val[0],
self.long_months[date_val[1]], year) self.long_months[date_val[1]], year)
else: else:
# Day RomanMon Year # day. Roman_number_month year.
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = "%s." % year value = "%s." % year
@ -322,7 +323,7 @@ class DateDisplaySR_latin(DateDisplay):
value = "%s %s." % (self.roman_months[date_val[1]], year) value = "%s %s." % (self.roman_months[date_val[1]], year)
else: else:
value = "%d. %s %s." % (date_val[0], value = "%d. %s %s." % (date_val[0],
self.roman_months[date_val[1]], year) self.roman_months[date_val[1]], year)
if date_val[2] < 0: if date_val[2] < 0:
return self._bce_str % value return self._bce_str % value
else: else:

View File

@ -126,6 +126,8 @@ class DateDisplaySv(DateDisplay):
"Dag månad år", "Dag månad år",
"DAG MÅN ÅR", "DAG MÅN ÅR",
) )
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
calendar = ( calendar = (
"", "",

View File

@ -226,16 +226,14 @@ class DateParserUK(DateParser):
_span_1 = ['з', 'від'] _span_1 = ['з', 'від']
# b.c.e. pattern also have "до" so skip "до н." # b.c.e. pattern also have "до" so skip "до н."
_span_2 = ['по', 'до?!\\.'] _span_2 = ['по', 'до?!\\.']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE)
_range_1 = ['між'] _range_1 = ['між']
_range_2 = ['і', 'та'] _range_2 = ['і', 'та']
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE)
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1), '|'.join(_range_2)), ('|'.join(_range_1), '|'.join(_range_2)),
re.IGNORECASE) re.IGNORECASE)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -309,6 +307,8 @@ class DateDisplayUK(DateDisplay):
"день місяць рік", #4 "день місяць рік", #4
"дд міс. рррр" #5 "дд міс. рррр" #5
) )
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
calendar = ( calendar = (
"", "юліанський", "єврейський", "французький республіканський", "", "юліанський", "єврейський", "французький республіканський",

View File

@ -103,19 +103,24 @@ class DateDisplay(object):
) )
formats = ("YYYY-MM-DD (ISO)", ) formats = ("YYYY-MM-DD (ISO)", )
# this will be overridden if a locale-specific date displayer exists
calendar = ( calendar = (
"", "Julian", "Hebrew", "French Republican", "", "Julian", "Hebrew", "French Republican",
"Persian", "Islamic", "Swedish" "Persian", "Islamic", "Swedish"
) )
# this will be overridden if a locale-specific date displayer exists
newyear = ("", "Mar1", "Mar25", "Sep1") newyear = ("", "Mar1", "Mar25", "Sep1")
_mod_str = ("", "before ", "after ", "about ", "", "", "") _mod_str = ("", "before ", "after ", "about ", "", "", "")
# this will be overridden if a locale-specific date displayer exists
_qual_str = ("", "estimated ", "calculated ") _qual_str = ("", "estimated ", "calculated ")
# this will be overridden if a locale-specific date displayer exists
_bce_str = "%s B.C.E." _bce_str = "%s B.C.E."
# this will be overridden if a locale-specific date displayer exists
def __init__(self, format=None): def __init__(self, format=None):
self.display_cal = [ self.display_cal = [
@ -159,6 +164,7 @@ class DateDisplay(object):
def display(self, date): def display(self, date):
""" """
Return a text string representing the date. Return a text string representing the date.
(will be overridden if a locale-specific date displayer exists)
""" """
mod = date.get_modifier() mod = date.get_modifier()
cal = date.get_calendar() cal = date.get_calendar()
@ -213,10 +219,13 @@ class DateDisplay(object):
return value return value
def _display_gregorian(self, date_val): def _display_gregorian(self, date_val):
# this one must agree with DateDisplayEn's "formats" definition
# (it may be overridden if a locale-specific date displayer exists)
year = self._slash_year(date_val[2], date_val[3]) year = self._slash_year(date_val[2], date_val[3])
if self.format == 0: if self.format == 0:
return self.display_iso(date_val) return self.display_iso(date_val)
elif self.format == 1: elif self.format == 1:
# numerical
if date_val[3]: if date_val[3]:
return self.display_iso(date_val) return self.display_iso(date_val)
else: else:
@ -228,7 +237,7 @@ class DateDisplay(object):
value = value.replace('%Y', str(abs(date_val[2]))) value = value.replace('%Y', str(abs(date_val[2])))
value = value.replace('-', '/') value = value.replace('-', '/')
elif self.format == 2: elif self.format == 2:
# Month Day, Year # month_name day, year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
@ -238,7 +247,7 @@ class DateDisplay(object):
value = "%s %d, %s" % (self.long_months[date_val[1]], value = "%s %d, %s" % (self.long_months[date_val[1]],
date_val[0], year) date_val[0], year)
elif self.format == 3: elif self.format == 3:
# MON Day, Year # month_abbreviation day, year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
@ -248,7 +257,7 @@ class DateDisplay(object):
value = "%s %d, %s" % (self.short_months[date_val[1]], value = "%s %d, %s" % (self.short_months[date_val[1]],
date_val[0], year) date_val[0], year)
elif self.format == 4: elif self.format == 4:
# Day Month Year # day month_name year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
@ -257,8 +266,9 @@ class DateDisplay(object):
else: else:
value = "%d %s %s" % (date_val[0], value = "%d %s %s" % (date_val[0],
self.long_months[date_val[1]], year) self.long_months[date_val[1]], year)
# elif self.format == 5:
else: else:
# Day MON Year # day month_abbreviation year
if date_val[0] == 0: if date_val[0] == 0:
if date_val[1] == 0: if date_val[1] == 0:
value = year value = year
@ -277,6 +287,7 @@ class DateDisplay(object):
return self._display_gregorian(date_val) return self._display_gregorian(date_val)
def _display_calendar(self, date_val, month_list): def _display_calendar(self, date_val, month_list):
# used to display non-Gregorian calendars (Hebrew, Islamic, etc.)
year = abs(date_val[2]) year = abs(date_val[2])
if self.format == 0 or self.format == 1: if self.format == 0 or self.format == 1:
return self.display_iso(date_val) return self.display_iso(date_val)
@ -333,6 +344,7 @@ class DateDisplayEn(DateDisplay):
"YYYY-MM-DD (ISO)", "Numerical", "Month Day, Year", "YYYY-MM-DD (ISO)", "Numerical", "Month Day, Year",
"MON DAY, YEAR", "Day Month Year", "DAY MON YEAR" "MON DAY, YEAR", "Day Month Year", "DAY MON YEAR"
) )
# this (English) "formats" must agree with "_display_gregorian" (above)
def __init__(self, format=None): def __init__(self, format=None):
""" """

View File

@ -49,6 +49,7 @@ from ._dateparser import DateParser
from ._datedisplay import DateDisplay, DateDisplayEn from ._datedisplay import DateDisplay, DateDisplayEn
from ..constfunc import win, cuni from ..constfunc import win, cuni
from ..const import GRAMPS_LOCALE as glocale from ..const import GRAMPS_LOCALE as glocale
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Constants # Constants

View File

@ -23,8 +23,7 @@
""" """
Date parsing class. Serves as the base class for any localized Date parsing class. Serves as the base class for any localized
date parsing class. The default, base class provides parsing for date parsing class. The default base class provides parsing for English.
English.
""" """
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -145,6 +144,7 @@ class DateParser(object):
month_to_int = _grampslocale.month_to_int month_to_int = _grampslocale.month_to_int
# modifiers before the date # modifiers before the date
# (overridden if a locale-specific date parser exists)
modifier_to_int = { modifier_to_int = {
'before' : Date.MOD_BEFORE, 'bef' : Date.MOD_BEFORE, 'before' : Date.MOD_BEFORE, 'bef' : Date.MOD_BEFORE,
'bef.' : Date.MOD_BEFORE, 'after' : Date.MOD_AFTER, 'bef.' : Date.MOD_BEFORE, 'after' : Date.MOD_AFTER,
@ -227,6 +227,7 @@ class DateParser(object):
bce = ["B.C.E.", "B.C.E", "BCE", "B.C.", "B.C", "BC" ] bce = ["B.C.E.", "B.C.E", "BCE", "B.C.", "B.C", "BC" ]
# (overridden if a locale-specific date parser exists)
calendar_to_int = { calendar_to_int = {
'gregorian' : Date.CAL_GREGORIAN, 'gregorian' : Date.CAL_GREGORIAN,
@ -245,6 +246,7 @@ class DateParser(object):
'swedish' : Date.CAL_SWEDISH, 'swedish' : Date.CAL_SWEDISH,
's' : Date.CAL_SWEDISH, 's' : Date.CAL_SWEDISH,
} }
# (probably overridden if a locale-specific date parser exists)
newyear_to_int = { newyear_to_int = {
"jan1": Date.NEWYEAR_JAN1, "jan1": Date.NEWYEAR_JAN1,
@ -261,6 +263,7 @@ class DateParser(object):
'calc' : Date.QUAL_CALCULATED, 'calc' : Date.QUAL_CALCULATED,
'calculated' : Date.QUAL_CALCULATED, 'calculated' : Date.QUAL_CALCULATED,
} }
# (overridden if a locale-specific date parser exists)
def __init__(self): def __init__(self):
self.init_strings() self.init_strings()

View File

@ -30,13 +30,13 @@ Class handling language-specific selection for date parser and displayer.
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import time import time
from ..lib.date import Date
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from ..lib.date import Date
from . import LANG_TO_DISPLAY, LANG, parser, displayer from . import LANG_TO_DISPLAY, LANG, parser, displayer
#-------------------------------------------------------------- #--------------------------------------------------------------
@ -46,7 +46,7 @@ from . import LANG_TO_DISPLAY, LANG, parser, displayer
#-------------------------------------------------------------- #--------------------------------------------------------------
def get_date_formats(): def get_date_formats():
""" """
Return the lists supported formats for date parsers and displayers. Return the list of supported formats for date parsers and displayers.
""" """
try: try:
return LANG_TO_DISPLAY[LANG].formats return LANG_TO_DISPLAY[LANG].formats