From e4cbeaef19623c94cbf53399b8a965f15b7867a0 Mon Sep 17 00:00:00 2001 From: Paul Franklin Date: Sat, 13 Jul 2013 18:01:08 +0000 Subject: [PATCH] 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 --- gramps/gen/datehandler/_date_bg.py | 4 +++- gramps/gen/datehandler/_date_ca.py | 4 +++- gramps/gen/datehandler/_date_cs.py | 3 ++- gramps/gen/datehandler/_date_da.py | 2 ++ gramps/gen/datehandler/_date_de.py | 14 +++++++---- gramps/gen/datehandler/_date_es.py | 4 +++- gramps/gen/datehandler/_date_fi.py | 2 ++ gramps/gen/datehandler/_date_fr.py | 14 ++++++----- gramps/gen/datehandler/_date_hr.py | 13 +++++++---- gramps/gen/datehandler/_date_it.py | 4 +++- gramps/gen/datehandler/_date_lt.py | 32 +++++++++++--------------- gramps/gen/datehandler/_date_nb.py | 2 ++ gramps/gen/datehandler/_date_nl.py | 17 +++++++++----- gramps/gen/datehandler/_date_pl.py | 16 +++++++++---- gramps/gen/datehandler/_date_pt.py | 14 ++++++----- gramps/gen/datehandler/_date_ru.py | 14 ++++++----- gramps/gen/datehandler/_date_sk.py | 4 +++- gramps/gen/datehandler/_date_sl.py | 8 ++++--- gramps/gen/datehandler/_date_sr.py | 27 +++++++++++----------- gramps/gen/datehandler/_date_sv.py | 2 ++ gramps/gen/datehandler/_date_uk.py | 14 +++++------ gramps/gen/datehandler/_datedisplay.py | 20 ++++++++++++---- gramps/gen/datehandler/_datehandler.py | 1 + gramps/gen/datehandler/_dateparser.py | 7 ++++-- gramps/gen/datehandler/_dateutils.py | 4 ++-- 25 files changed, 152 insertions(+), 94 deletions(-) diff --git a/gramps/gen/datehandler/_date_bg.py b/gramps/gen/datehandler/_date_bg.py index ed10fb934..960e03eb1 100644 --- a/gramps/gen/datehandler/_date_bg.py +++ b/gramps/gen/datehandler/_date_bg.py @@ -168,7 +168,7 @@ class DateParserBG(DateParser): _span_2 = ['до'] _range_1 = ['между'] _range_2 = ['и'] - self._span = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % + self._span = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % ('|'.join(_span_1), '|'.join(_span_2)), re.IGNORECASE) self._range = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % @@ -211,6 +211,8 @@ class DateDisplayBG(DateDisplay): formats = ( "ГГГГ-ММ-ДД (ISO)", "Числов", "Месец Ден, Година", "Мес. Ден, Година", "Ден Месец Година", "Ден Мес. Година" ) + # this must agree with DateDisplayEn's "formats" definition + # (since no locale-specific _display_gregorian exists, here) hebrew = ( "", "Тишрей", diff --git a/gramps/gen/datehandler/_date_ca.py b/gramps/gen/datehandler/_date_ca.py index 548139cb0..d4e3ffa9d 100644 --- a/gramps/gen/datehandler/_date_ca.py +++ b/gramps/gen/datehandler/_date_ca.py @@ -102,7 +102,7 @@ class DateParserCA(DateParser): _span_2 = ['fins a'] _range_1 = ['entre', 'ent\.', 'ent'] _range_2 = ['i'] - self._span = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % + self._span = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % ('|'.join(_span_1), '|'.join(_span_2)), re.IGNORECASE) self._range = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % @@ -156,6 +156,8 @@ class DateDisplayCA(DateDisplay): "AAAA-MM-DD (ISO)", "Numèrica", "Mes Dia, 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): """ diff --git a/gramps/gen/datehandler/_date_cs.py b/gramps/gen/datehandler/_date_cs.py index 2f5cfc79e..0329146f7 100644 --- a/gramps/gen/datehandler/_date_cs.py +++ b/gramps/gen/datehandler/_date_cs.py @@ -218,7 +218,8 @@ class DateDisplayCZ(DateDisplay): "den. měsíc 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): """ diff --git a/gramps/gen/datehandler/_date_da.py b/gramps/gen/datehandler/_date_da.py index bb1ffa9ee..5ad21522f 100644 --- a/gramps/gen/datehandler/_date_da.py +++ b/gramps/gen/datehandler/_date_da.py @@ -121,6 +121,8 @@ class DateDisplayDa(DateDisplay): "Dag måned år", "Dag md År", ) + # this must agree with DateDisplayEn's "formats" definition + # (since no locale-specific _display_gregorian exists, here) calendar = ( "", diff --git a/gramps/gen/datehandler/_date_de.py b/gramps/gen/datehandler/_date_de.py index d73b86229..e7ab3d422 100644 --- a/gramps/gen/datehandler/_date_de.py +++ b/gramps/gen/datehandler/_date_de.py @@ -221,12 +221,18 @@ class DateDisplayDE(DateDisplay): "JJJJ-MM-DD (ISO)", "Numerisch", "Monat Tag 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): + """ + 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]) if self.format == 0: return self.display_iso(date_val) elif self.format == 1: + # day.month_number.year if date_val[3]: return self.display_iso(date_val) else: @@ -237,7 +243,7 @@ class DateDisplayDE(DateDisplay): value = value.replace('%d', str(date_val[0])) value = value.replace('%Y', str(date_val[2])) elif self.format == 2: - # Month Day, Year + # month_name day, year if date_val[0] == 0: if date_val[1] == 0: value = year @@ -247,7 +253,7 @@ class DateDisplayDE(DateDisplay): value = "%s %d, %s" % (self.long_months[date_val[1]], date_val[0], year) elif self.format == 3: - # MON Day, Year + # month_abbreviation day, year if date_val[0] == 0: if date_val[1] == 0: value = year @@ -257,7 +263,7 @@ class DateDisplayDE(DateDisplay): value = "%s %d, %s" % (self.short_months[date_val[1]], date_val[0], year) elif self.format == 4: - # Day Month Year + # day. month_name year if date_val[0] == 0: if date_val[1] == 0: value = year @@ -267,7 +273,7 @@ class DateDisplayDE(DateDisplay): value = "%d. %s %s" % (date_val[0], self.long_months[date_val[1]], year) else: - # Day MON Year + # day. month_abbreviation year if date_val[0] == 0: if date_val[1] == 0: value = year diff --git a/gramps/gen/datehandler/_date_es.py b/gramps/gen/datehandler/_date_es.py index 5c1cfe20c..69728ef9e 100644 --- a/gramps/gen/datehandler/_date_es.py +++ b/gramps/gen/datehandler/_date_es.py @@ -101,7 +101,7 @@ class DateParserES(DateParser): _span_2 = ['a'] _range_1 = ['entre', 'ent\.', 'ent'] _range_2 = ['y'] - self._span = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % + self._span = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % ('|'.join(_span_1), '|'.join(_span_2)), re.IGNORECASE) self._range = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % @@ -140,6 +140,8 @@ class DateDisplayES(DateDisplay): "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" ) + # this must agree with DateDisplayEn's "formats" definition + # (since no locale-specific _display_gregorian exists, here) def display(self, date): """ diff --git a/gramps/gen/datehandler/_date_fi.py b/gramps/gen/datehandler/_date_fi.py index 8f82192dc..ea21c817f 100644 --- a/gramps/gen/datehandler/_date_fi.py +++ b/gramps/gen/datehandler/_date_fi.py @@ -141,6 +141,8 @@ class DateDisplayFI(DateDisplay): "VVVV-KK-PP (ISO)", "PP.KK.VVVV" ) + # this must agree with DateDisplayEn's "formats" definition + # (since no locale-specific _display_gregorian exists, here) def display(self, date): """ diff --git a/gramps/gen/datehandler/_date_fr.py b/gramps/gen/datehandler/_date_fr.py index c045c3cfb..eb2fea214 100644 --- a/gramps/gen/datehandler/_date_fr.py +++ b/gramps/gen/datehandler/_date_fr.py @@ -285,11 +285,13 @@ class DateDisplayFR(DateDisplay): "Mois Jour, Année", # 6 "MOI Jour, Année", # 7 ) + # this definition must agree with its "_display_gregorian" method 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]) if self.format == 0: @@ -316,7 +318,7 @@ class DateDisplayFR(DateDisplay): value = value.replace('%Y', str(date_val[2])) elif self.format == 2: - # Day Month Year + # day month_name year if date_val[0] == 0: if date_val[1] == 0: @@ -329,7 +331,7 @@ class DateDisplayFR(DateDisplay): self.long_months[date_val[1]], year) elif self.format == 3: - # Day MON Year + # day month_abbreviation year if date_val[0] == 0: if date_val[1] == 0: @@ -342,7 +344,7 @@ class DateDisplayFR(DateDisplay): self.short_months[date_val[1]], year) elif self.format == 4: - # Day. Month Year + # day. month_name year if date_val[0] == 0: if date_val[1] == 0: @@ -360,7 +362,7 @@ class DateDisplayFR(DateDisplay): year) elif self.format == 5: - # Day. MON Year + # day. month_abbreviation year if date_val[0] == 0: if date_val[1] == 0: @@ -377,7 +379,7 @@ class DateDisplayFR(DateDisplay): self.short_months[date_val[1]], year) elif self.format == 6: - # Month Day, Year + # month_name day, year if date_val[0] == 0: if date_val[1] == 0: @@ -389,7 +391,7 @@ class DateDisplayFR(DateDisplay): date_val[0], year) elif self.format == 7: - # MON Day, Year + # month_abbreviation day, year if date_val[0] == 0: if date_val[1] == 0: diff --git a/gramps/gen/datehandler/_date_hr.py b/gramps/gen/datehandler/_date_hr.py index a7d05c14b..9b73f56d4 100644 --- a/gramps/gen/datehandler/_date_hr.py +++ b/gramps/gen/datehandler/_date_hr.py @@ -247,6 +247,7 @@ class DateDisplayHR(DateDisplay): "D. MMMM GGGG.", "D. Rb GGGG." ) + # this definition must agree with its "_display_gregorian" method roman_months = ( "", @@ -268,10 +269,12 @@ class DateDisplayHR(DateDisplay): """ 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]) if self.format == 0: return self.display_iso(date_val) elif self.format == 1: + # numerical if date_val[3]: return self.display_iso(date_val) else: @@ -283,7 +286,7 @@ class DateDisplayHR(DateDisplay): value = value.replace('%Y', str(abs(date_val[2]))) value = value.replace('-', '/') elif self.format == 2: - # Day.Month.Year. + # day.month_number.year. if date_val[0] == 0: if date_val[1] == 0: value = year @@ -292,7 +295,7 @@ class DateDisplayHR(DateDisplay): else: value = "%s.%d.%s." % (date_val[0], date_val[1], year) elif self.format == 3: - # Day. MONTH year. + # day. month_name year. if date_val[0] == 0: if date_val[1] == 0: value = "%s." % year @@ -300,9 +303,9 @@ class DateDisplayHR(DateDisplay): value = "%s %s." % (self.long_months[date_val[1]], year) else: value = "%d. %s %s." % (date_val[0], - self.long_months[date_val[1]], year) + self.long_months[date_val[1]], year) else: - # Day RomanMon Year + # day. Roman_number_month year. if date_val[0] == 0: if date_val[1] == 0: value = "%s." % year @@ -310,7 +313,7 @@ class DateDisplayHR(DateDisplay): value = "%s %s." % (self.roman_months[date_val[1]], year) else: 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: return self._bce_str % value else: diff --git a/gramps/gen/datehandler/_date_it.py b/gramps/gen/datehandler/_date_it.py index e13cb77fa..91fef9fcb 100644 --- a/gramps/gen/datehandler/_date_it.py +++ b/gramps/gen/datehandler/_date_it.py @@ -98,7 +98,7 @@ class DateParserIT(DateParser): _span_2 = ['al', 'a'] _range_1 = ['tra', 'fra'] _range_2 = ['e'] - self._span = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % + self._span = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % ('|'.join(_span_1), '|'.join(_span_2)), re.IGNORECASE) self._range = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % @@ -152,6 +152,8 @@ class DateDisplayIT(DateDisplay): "AAAA-MM-DD (ISO)", "Numerico", "Mese Giorno 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): """ diff --git a/gramps/gen/datehandler/_date_lt.py b/gramps/gen/datehandler/_date_lt.py index 0a4a9101f..914a5a90e 100644 --- a/gramps/gen/datehandler/_date_lt.py +++ b/gramps/gen/datehandler/_date_lt.py @@ -136,14 +136,12 @@ class DateParserLT(DateParser): _span_2 = ['iki'] _range_1 = ['tarp'] _range_2 = ['ir'] - self._span = re.compile( - "(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % - ('|'.join(_span_1), '|'.join(_span_2)), - re.IGNORECASE) - self._range = re.compile( - "(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % - ('|'.join(_range_1), '|'.join(_range_2)), - re.IGNORECASE) + self._span = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % + ('|'.join(_span_1), '|'.join(_span_2)), + re.IGNORECASE) + self._range = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % + ('|'.join(_range_1), '|'.join(_range_2)), + re.IGNORECASE) #------------------------------------------------------------------------ # @@ -206,32 +204,30 @@ class DateDisplayLT(DateDisplay): formats = ( "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): """ display gregorian calendar date in different format """ + # this must agree with its locale-specific "formats" definition value = self.display_iso(date_val) year = self._slash_year(date_val[2], date_val[3]) - if self.format == 0: return self.display_iso(date_val) elif self.format == 1: - - # mmmm m. mėnesio diena d. (YYYY m. month DD d.) - + # mmmm m. mėnesio diena d. (year m. month_name day d.) if date_val[0] == 0: if date_val[1] == 0: value = year else: value = "%s m. %s" % (year, self.long_months_vardininkas[date_val[1]]) else: - value = "%s m. %s %d d." % (year, self.long_months[date_val[1]], - date_val[0]) + value = "%s m. %s %d d." % (year, + self.long_months[date_val[1]], + date_val[0]) elif self.format == 2: - - # MON Day, Year - + # month_abbreviation day, year if date_val[0] == 0: if date_val[1] == 0: value = year @@ -240,8 +236,6 @@ class DateDisplayLT(DateDisplay): else: value = "%s %d, %s" % (self.short_months[date_val[1]], date_val[0], year) - - if date_val[2] < 0: return self._bce_str % value else: diff --git a/gramps/gen/datehandler/_date_nb.py b/gramps/gen/datehandler/_date_nb.py index 7f9a77416..35797eb63 100644 --- a/gramps/gen/datehandler/_date_nb.py +++ b/gramps/gen/datehandler/_date_nb.py @@ -121,6 +121,8 @@ class DateDisplayNb(DateDisplay): "Dag måned år", "Dag Mån År", ) + # this must agree with DateDisplayEn's "formats" definition + # (since no locale-specific _display_gregorian exists, here) calendar = ( "", diff --git a/gramps/gen/datehandler/_date_nl.py b/gramps/gen/datehandler/_date_nl.py index 5ad8bc543..1b68e442a 100644 --- a/gramps/gen/datehandler/_date_nl.py +++ b/gramps/gen/datehandler/_date_nl.py @@ -165,8 +165,13 @@ class DateDisplayNL(DateDisplay): "JJJJ-MM-DD (ISO)", "Numerisch DD/MM/JJ", "Maand Dag, 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): + """ + 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]) if self.format == 0: return self.display_iso(date_val) @@ -174,7 +179,7 @@ class DateDisplayNL(DateDisplay): if date_val[3]: return self.display_iso(date_val) else: - # Numeric + # day/month_number/year if date_val[0] == date_val[1] == 0: value = str(date_val[2]) else: @@ -183,7 +188,7 @@ class DateDisplayNL(DateDisplay): value = value.replace('%Y', str(abs(date_val[2]))) value = value.replace('-', '/') elif self.format == 2: - # Month Day, Year + # month_name day, year if date_val[0] == 0: if date_val[1] == 0: value = year @@ -193,7 +198,7 @@ class DateDisplayNL(DateDisplay): value = "%s %d, %s" % (self.long_months[date_val[1]], date_val[0], year) elif self.format == 3: - # Mnd Day, Year + # month_abbreviation day, year if date_val[0] == 0: if date_val[1] == 0: value = year @@ -203,7 +208,7 @@ class DateDisplayNL(DateDisplay): value = "%s %d, %s" % (self.short_months[date_val[1]], date_val[0], year) elif self.format == 4: - # Day Month Year + # day month_name year if date_val[0] == 0: if date_val[1] == 0: value = year @@ -213,7 +218,7 @@ class DateDisplayNL(DateDisplay): value = "%d %s %s" % (date_val[0], self.long_months[date_val[1]], year) else: - # Day Mnd Year + # day month_abbreviation year if date_val[0] == 0: if date_val[1] == 0: value = year @@ -221,7 +226,7 @@ class DateDisplayNL(DateDisplay): value = "%s %s" % (self.short_months[date_val[1]], year) else: 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: return self._bce_str % value else: diff --git a/gramps/gen/datehandler/_date_pl.py b/gramps/gen/datehandler/_date_pl.py index 122dc3720..fd4df0683 100644 --- a/gramps/gen/datehandler/_date_pl.py +++ b/gramps/gen/datehandler/_date_pl.py @@ -199,6 +199,7 @@ class DateDisplayPL(DateDisplay): "RRRR-MM-DD (ISO)", "Numeryczny", "Miesiąc Dzień, Rok", "Dzień.Miesiąc.Rok", "Dzień Miesiąc Rok", "Dzień MieRzym Rok" ) + # this definition must agree with its "_display_gregorian" method roman_months = ( "", @@ -217,10 +218,15 @@ class DateDisplayPL(DateDisplay): ) 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]) if self.format == 0: return self.display_iso(date_val) elif self.format == 1: + # month_number.day.year if date_val[3]: return self.display_iso(date_val) else: @@ -229,9 +235,9 @@ class DateDisplayPL(DateDisplay): else: value = self._tformat.replace('%m', str(date_val[0])) 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: - # Month Day, Year + # month_name day, year if date_val[0] == 0: if date_val[1] == 0: value = year @@ -241,7 +247,7 @@ class DateDisplayPL(DateDisplay): value = "%s %d, %s" % (self.long_months[date_val[1]], date_val[0], year) elif self.format == 3: - # Day. Month. Year + # day. month_number. year if date_val[0] == 0: if date_val[1] == 0: value = year @@ -250,7 +256,7 @@ class DateDisplayPL(DateDisplay): else: value = "%d.%d.%s" % (date_val[0], date_val[1], year) elif self.format == 4: - # Day Month Year + # day month_name year if date_val[0] == 0: if date_val[1] == 0: value = year @@ -260,7 +266,7 @@ class DateDisplayPL(DateDisplay): value = "%d %s %s" % (date_val[0], self.long_months[date_val[1]], year) else: - # Day RomanMon Year + # day Roman_number_month year if date_val[0] == 0: if date_val[1] == 0: value = year diff --git a/gramps/gen/datehandler/_date_pt.py b/gramps/gen/datehandler/_date_pt.py index 4d7c00816..11eb1c68a 100644 --- a/gramps/gen/datehandler/_date_pt.py +++ b/gramps/gen/datehandler/_date_pt.py @@ -106,12 +106,12 @@ class DateParserPT(DateParser): _span_2 = ['a'] _range_1 = ['entre','ent\.','ent'] _range_2 = ['e'] - self._span = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % - ('|'.join(_span_1),'|'.join(_span_2)), - re.IGNORECASE) - self._range = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % - ('|'.join(_range_1),'|'.join(_range_2)), - re.IGNORECASE) + self._span = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % + ('|'.join(_span_1), '|'.join(_span_2)), + re.IGNORECASE) + self._range = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % + ('|'.join(_range_1), '|'.join(_range_2)), + re.IGNORECASE) #------------------------------------------------------------------------- # @@ -143,6 +143,8 @@ class DateDisplayPT(DateDisplay): "AAAA-MM-DD (ISO)", "Numérica", "Mês Dia, 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): """ diff --git a/gramps/gen/datehandler/_date_ru.py b/gramps/gen/datehandler/_date_ru.py index 6fafe190f..da429f812 100644 --- a/gramps/gen/datehandler/_date_ru.py +++ b/gramps/gen/datehandler/_date_ru.py @@ -222,12 +222,12 @@ class DateParserRU(DateParser): _span_2 = ['по'] _range_1 = ['между', 'меж\.', 'меж'] _range_2 = ['и'] - self._span = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % - ('|'.join(_span_1), '|'.join(_span_2)), - re.IGNORECASE) - self._range = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % - ('|'.join(_range_1), '|'.join(_range_2)), - re.IGNORECASE) + self._span = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % + ('|'.join(_span_1), '|'.join(_span_2)), + re.IGNORECASE) + self._range = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % + ('|'.join(_range_1), '|'.join(_range_2)), + re.IGNORECASE) #------------------------------------------------------------------------- # @@ -270,6 +270,8 @@ class DateDisplayRU(DateDisplay): "ГГГГ-ММ-ДД (ISO)", "Численный", "Месяц День, Год", "МЕС ДД, ГГГГ", "День Месяц, Год", "ДД МЕС, ГГГГ" ) + # this must agree with DateDisplayEn's "formats" definition + # (since no locale-specific _display_gregorian exists, here) hebrew = ( "", "тишрея", diff --git a/gramps/gen/datehandler/_date_sk.py b/gramps/gen/datehandler/_date_sk.py index 6c9eb98fe..ee8dd7af1 100644 --- a/gramps/gen/datehandler/_date_sk.py +++ b/gramps/gen/datehandler/_date_sk.py @@ -88,7 +88,7 @@ class DateParserSK(DateParser): _span_2 = ['do'] _range_1 = ['medzi'] _range_2 = ['a'] - self._span = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % + self._span = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % ('|'.join(_span_1), '|'.join(_span_2)), re.IGNORECASE) self._range = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % @@ -125,6 +125,8 @@ class DateDisplaySK(DateDisplay): "RRRR-MM-DD (ISO)", "numerický", "Mesiac Deň, 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): """ diff --git a/gramps/gen/datehandler/_date_sl.py b/gramps/gen/datehandler/_date_sl.py index 4398f8314..f827ec8e6 100644 --- a/gramps/gen/datehandler/_date_sl.py +++ b/gramps/gen/datehandler/_date_sl.py @@ -223,16 +223,18 @@ class DateDisplaySL(DateDisplay): "dan. mes. leto", "dan. mesec leto" ) + # this definition must agree with its "_display_gregorian" method 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]) if self.format == 0: return self.display_iso(date_val) elif self.format == 1: - # D. M. YYYY + # day. month_number. year if date_val[3]: return self.display_iso(date_val) else: @@ -244,7 +246,7 @@ class DateDisplaySL(DateDisplay): value = value.replace('%Y', str(date_val[2])) value = value.replace('-', '. ') elif self.format == 2: - # D. mon. YYYY + # day. month_abbreviation. year if date_val[0] == 0: if date_val[1] == 0: value = year @@ -254,7 +256,7 @@ class DateDisplaySL(DateDisplay): value = "%d. %s. %s" % (date_val[0], self.short_months[date_val[1]], year) else: - # D. month YYYY + # day. month_name year if date_val[0] == 0: if date_val[1] == 0: value = "%s." % year diff --git a/gramps/gen/datehandler/_date_sr.py b/gramps/gen/datehandler/_date_sr.py index fe9ee9192..7b73738f3 100644 --- a/gramps/gen/datehandler/_date_sr.py +++ b/gramps/gen/datehandler/_date_sr.py @@ -220,12 +220,12 @@ class DateParserSR(DateParser): _span_2 = ['do', 'до'] _range_1 = ['između', 'између'] _range_2 = ['i', 'и'] - self._span = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % - ('|'.join(_span_1),'|'.join(_span_2)), - re.IGNORECASE) + self._span = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % + ('|'.join(_span_1), '|'.join(_span_2)), + re.IGNORECASE) self._range = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % - ('|'.join(_range_1),'|'.join(_range_2)), - re.IGNORECASE) + ('|'.join(_range_1), '|'.join(_range_2)), + re.IGNORECASE) #------------------------------------------------------------------------- # @@ -271,17 +271,18 @@ class DateDisplaySR_latin(DateDisplay): "D. Mesec GGGG.", "D. Rb GGGG." ) - + # this definition must agree with its "_display_gregorian" method 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]) if self.format == 0: return self.display_iso(date_val) elif self.format == 1: - ## DD.MM.YYYY. + # day.month_number.year. if date_val[3]: return self.display_iso(date_val) else: @@ -294,7 +295,7 @@ class DateDisplaySR_latin(DateDisplay): #some locale magic already provides the right separator #value = value.replace('/', '.') elif self.format == 2: - # Day. MON Year. + # day. month_abbreviation year. if date_val[0] == 0: if date_val[1] == 0: value = "%s." % year @@ -302,9 +303,9 @@ class DateDisplaySR_latin(DateDisplay): value = "%s %s." % (self.short_months[date_val[1]], year) else: 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: - # Day. MONTH Year. + # day. month_name year. if date_val[0] == 0: if date_val[1] == 0: value = "%s." % year @@ -312,9 +313,9 @@ class DateDisplaySR_latin(DateDisplay): value = "%s %s." % (self.long_months[date_val[1]], year) else: value = "%d. %s %s." % (date_val[0], - self.long_months[date_val[1]], year) + self.long_months[date_val[1]], year) else: - # Day RomanMon Year + # day. Roman_number_month year. if date_val[0] == 0: if date_val[1] == 0: value = "%s." % year @@ -322,7 +323,7 @@ class DateDisplaySR_latin(DateDisplay): value = "%s %s." % (self.roman_months[date_val[1]], year) else: 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: return self._bce_str % value else: diff --git a/gramps/gen/datehandler/_date_sv.py b/gramps/gen/datehandler/_date_sv.py index 2aa3524fe..0c4f2065a 100644 --- a/gramps/gen/datehandler/_date_sv.py +++ b/gramps/gen/datehandler/_date_sv.py @@ -126,6 +126,8 @@ class DateDisplaySv(DateDisplay): "Dag månad år", "DAG MÅN ÅR", ) + # this must agree with DateDisplayEn's "formats" definition + # (since no locale-specific _display_gregorian exists, here) calendar = ( "", diff --git a/gramps/gen/datehandler/_date_uk.py b/gramps/gen/datehandler/_date_uk.py index 42ac98439..281c35643 100644 --- a/gramps/gen/datehandler/_date_uk.py +++ b/gramps/gen/datehandler/_date_uk.py @@ -226,16 +226,14 @@ class DateParserUK(DateParser): _span_1 = ['з', 'від'] # b.c.e. pattern also have "до" so skip "до н." _span_2 = ['по', 'до?!\sн\.'] - self._span = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % - ('|'.join(_span_1), '|'.join(_span_2)), - re.IGNORECASE) _range_1 = ['між'] _range_2 = ['і', 'та'] + self._span = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % + ('|'.join(_span_1), '|'.join(_span_2)), + re.IGNORECASE) self._range = re.compile("(%s)\s+(?P.+)\s+(%s)\s+(?P.+)" % - ('|'.join(_range_1), '|'.join(_range_2)), - re.IGNORECASE) - - + ('|'.join(_range_1), '|'.join(_range_2)), + re.IGNORECASE) #------------------------------------------------------------------------- # @@ -309,6 +307,8 @@ class DateDisplayUK(DateDisplay): "день місяць рік", #4 "дд міс. рррр" #5 ) + # this must agree with DateDisplayEn's "formats" definition + # (since no locale-specific _display_gregorian exists, here) calendar = ( "", "юліанський", "єврейський", "французький республіканський", diff --git a/gramps/gen/datehandler/_datedisplay.py b/gramps/gen/datehandler/_datedisplay.py index 6ec71aed7..71c53cc1d 100644 --- a/gramps/gen/datehandler/_datedisplay.py +++ b/gramps/gen/datehandler/_datedisplay.py @@ -103,19 +103,24 @@ class DateDisplay(object): ) formats = ("YYYY-MM-DD (ISO)", ) + # this will be overridden if a locale-specific date displayer exists calendar = ( "", "Julian", "Hebrew", "French Republican", "Persian", "Islamic", "Swedish" ) + # this will be overridden if a locale-specific date displayer exists newyear = ("", "Mar1", "Mar25", "Sep1") _mod_str = ("", "before ", "after ", "about ", "", "", "") + # this will be overridden if a locale-specific date displayer exists _qual_str = ("", "estimated ", "calculated ") + # this will be overridden if a locale-specific date displayer exists _bce_str = "%s B.C.E." + # this will be overridden if a locale-specific date displayer exists def __init__(self, format=None): self.display_cal = [ @@ -159,6 +164,7 @@ class DateDisplay(object): def display(self, date): """ Return a text string representing the date. + (will be overridden if a locale-specific date displayer exists) """ mod = date.get_modifier() cal = date.get_calendar() @@ -213,10 +219,13 @@ class DateDisplay(object): return value 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]) if self.format == 0: return self.display_iso(date_val) elif self.format == 1: + # numerical if date_val[3]: return self.display_iso(date_val) else: @@ -228,7 +237,7 @@ class DateDisplay(object): value = value.replace('%Y', str(abs(date_val[2]))) value = value.replace('-', '/') elif self.format == 2: - # Month Day, Year + # month_name day, year if date_val[0] == 0: if date_val[1] == 0: value = year @@ -238,7 +247,7 @@ class DateDisplay(object): value = "%s %d, %s" % (self.long_months[date_val[1]], date_val[0], year) elif self.format == 3: - # MON Day, Year + # month_abbreviation day, year if date_val[0] == 0: if date_val[1] == 0: value = year @@ -248,7 +257,7 @@ class DateDisplay(object): value = "%s %d, %s" % (self.short_months[date_val[1]], date_val[0], year) elif self.format == 4: - # Day Month Year + # day month_name year if date_val[0] == 0: if date_val[1] == 0: value = year @@ -257,8 +266,9 @@ class DateDisplay(object): else: value = "%d %s %s" % (date_val[0], self.long_months[date_val[1]], year) + # elif self.format == 5: else: - # Day MON Year + # day month_abbreviation year if date_val[0] == 0: if date_val[1] == 0: value = year @@ -277,6 +287,7 @@ class DateDisplay(object): return self._display_gregorian(date_val) def _display_calendar(self, date_val, month_list): + # used to display non-Gregorian calendars (Hebrew, Islamic, etc.) year = abs(date_val[2]) if self.format == 0 or self.format == 1: return self.display_iso(date_val) @@ -333,6 +344,7 @@ class DateDisplayEn(DateDisplay): "YYYY-MM-DD (ISO)", "Numerical", "Month Day, Year", "MON DAY, YEAR", "Day Month Year", "DAY MON YEAR" ) + # this (English) "formats" must agree with "_display_gregorian" (above) def __init__(self, format=None): """ diff --git a/gramps/gen/datehandler/_datehandler.py b/gramps/gen/datehandler/_datehandler.py index e0f0125cf..941e22454 100644 --- a/gramps/gen/datehandler/_datehandler.py +++ b/gramps/gen/datehandler/_datehandler.py @@ -49,6 +49,7 @@ from ._dateparser import DateParser from ._datedisplay import DateDisplay, DateDisplayEn from ..constfunc import win, cuni from ..const import GRAMPS_LOCALE as glocale + #------------------------------------------------------------------------- # # Constants diff --git a/gramps/gen/datehandler/_dateparser.py b/gramps/gen/datehandler/_dateparser.py index 9c98b86f1..f0bdb2c63 100644 --- a/gramps/gen/datehandler/_dateparser.py +++ b/gramps/gen/datehandler/_dateparser.py @@ -23,8 +23,7 @@ """ Date parsing class. Serves as the base class for any localized -date parsing class. The default, base class provides parsing for -English. +date parsing class. The default base class provides parsing for English. """ #------------------------------------------------------------------------- @@ -145,6 +144,7 @@ class DateParser(object): month_to_int = _grampslocale.month_to_int # modifiers before the date + # (overridden if a locale-specific date parser exists) modifier_to_int = { 'before' : Date.MOD_BEFORE, 'bef' : Date.MOD_BEFORE, '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" ] + # (overridden if a locale-specific date parser exists) calendar_to_int = { 'gregorian' : Date.CAL_GREGORIAN, @@ -245,6 +246,7 @@ class DateParser(object): 'swedish' : Date.CAL_SWEDISH, 's' : Date.CAL_SWEDISH, } + # (probably overridden if a locale-specific date parser exists) newyear_to_int = { "jan1": Date.NEWYEAR_JAN1, @@ -261,6 +263,7 @@ class DateParser(object): 'calc' : Date.QUAL_CALCULATED, 'calculated' : Date.QUAL_CALCULATED, } + # (overridden if a locale-specific date parser exists) def __init__(self): self.init_strings() diff --git a/gramps/gen/datehandler/_dateutils.py b/gramps/gen/datehandler/_dateutils.py index 34147bc77..93b595f8f 100644 --- a/gramps/gen/datehandler/_dateutils.py +++ b/gramps/gen/datehandler/_dateutils.py @@ -30,13 +30,13 @@ Class handling language-specific selection for date parser and displayer. # #------------------------------------------------------------------------- import time -from ..lib.date import Date #------------------------------------------------------------------------- # # GRAMPS modules # #------------------------------------------------------------------------- +from ..lib.date import Date from . import LANG_TO_DISPLAY, LANG, parser, displayer #-------------------------------------------------------------- @@ -46,7 +46,7 @@ from . import LANG_TO_DISPLAY, LANG, parser, displayer #-------------------------------------------------------------- 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: return LANG_TO_DISPLAY[LANG].formats