From a73b2da699fc86396fd44a44707f2d9ec86368dc Mon Sep 17 00:00:00 2001 From: Peter Landgren Date: Mon, 19 Jan 2009 20:09:19 +0000 Subject: [PATCH] Swedish calendar added. svn: r11665 --- src/DateEdit.py | 3 +- src/DateHandler/_DateDisplay.py | 12 ++++++- src/DateHandler/_DateParser.py | 49 ++++++++++++++++++++++++++-- src/DateHandler/_Date_sv.py | 5 ++- src/Filters/Rules/Person/Makefile.am | 1 + src/Filters/Rules/Person/__init__.py | 2 ++ src/gen/lib/calendar.py | 28 ++++++++++++++++ src/gen/lib/date.py | 21 ++++++++---- src/plugins/import/Makefile.am | 1 + 9 files changed, 110 insertions(+), 12 deletions(-) diff --git a/src/DateEdit.py b/src/DateEdit.py index c6a289c23..98fffb35d 100644 --- a/src/DateEdit.py +++ b/src/DateEdit.py @@ -95,7 +95,8 @@ CAL_TO_MONTHS_NAMES = { Date.CAL_HEBREW : DateHandler.displayer.hebrew, Date.CAL_FRENCH : DateHandler.displayer.french, Date.CAL_PERSIAN : DateHandler.displayer.persian, - Date.CAL_ISLAMIC : DateHandler.displayer.islamic } + Date.CAL_ISLAMIC : DateHandler.displayer.islamic, + Date.CAL_SWEDISH : DateHandler.displayer.swedish } WIKI_HELP_PAGE = 'Gramps_3.0_Wiki_Manual_-_Entering_and_Editing_Data:_Detailed' WIKI_HELP_SEC = _('manual|Editing_Dates') diff --git a/src/DateHandler/_DateDisplay.py b/src/DateHandler/_DateDisplay.py index a47a66416..98a5964f5 100644 --- a/src/DateHandler/_DateDisplay.py +++ b/src/DateHandler/_DateDisplay.py @@ -88,6 +88,13 @@ class DateDisplay: "Ramadan", "Shawwal", "Dhu l-Qa`da", "Dhu l-Hijja" ) + swedish = ( + "", "Januari", "Februari", "Mars", + "April", "Maj", "Juni", + "Juli", "Augusti", "September", + "Oktober", "November", "December" + ) + formats = ("YYYY-MM-DD (ISO)", ) calendar = ( @@ -111,7 +118,7 @@ class DateDisplay: self._display_french, self._display_persian, self._display_islamic, - ] + self._display_swedish] self.verify_format(format) if format is None: @@ -321,6 +328,9 @@ class DateDisplay: def _display_islamic(self, date_val): return self._display_calendar(date_val, self.islamic) + def _display_swedish(self, date_val): + return self._display_calendar(date_val, self.swedish) + class DateDisplayEn(DateDisplay): """ English language date display class. diff --git a/src/DateHandler/_DateParser.py b/src/DateHandler/_DateParser.py index 89416950e..5826a7244 100644 --- a/src/DateHandler/_DateParser.py +++ b/src/DateHandler/_DateParser.py @@ -75,6 +75,20 @@ def gregorian_valid(date_tuple): valid = False return valid +def swedish_valid(date_tuple): + valid = gregorian_valid(date_tuple) + # not sure how <= and >= works with tuples??? + date_tuple = (date_tuple[2], date_tuple[1], date_tuple[0]) + if date_tuple <= (1700,2,28): + valid = False + if date_tuple == (1700,2,29): # leapday 1700 was skipped + valid = False + if date_tuple == (1712,2,30): # extra day was inserted 1712 + valid = True + if date_tuple >= (1712,3,1): # back to julian + valid = False + return valid + #------------------------------------------------------------------------- # # Parser class @@ -156,6 +170,16 @@ class DateParser: "bahman" : 11, "esfand" : 12, } + swedish_to_int = { + "januari" : 1, "februari" : 2, + "mars" : 3, "april" : 4, + "maj" : 5, "juni" : 6, + "juli" : 7, "augisti" : 8, + "september" : 9, "oktober" : 10, + "november" : 11, "december" : 12, + } + + bce = ["B.C.E.", "B.C.E", "BCE", "B.C.", "B.C", "BC" ] calendar_to_int = { @@ -171,7 +195,9 @@ class DateParser: 'french republican': Date.CAL_FRENCH, 'f' : Date.CAL_FRENCH, 'persian' : Date.CAL_PERSIAN, - 'p' : Date.CAL_PERSIAN, + 'p' : Date.CAL_PERSIAN, + 'swedish' : Date.CAL_SWEDISH, + 's' : Date.CAL_SWEDISH, } newyear_to_int = { @@ -199,6 +225,7 @@ class DateParser: Date.CAL_PERSIAN : self._parse_persian, Date.CAL_HEBREW : self._parse_hebrew, Date.CAL_ISLAMIC : self._parse_islamic, + Date.CAL_SWEDISH : self._parse_swedish, } fmt = GrampsLocale.tformat @@ -246,6 +273,7 @@ class DateParser: self._fmon_str = self.re_longest_first(self.french_to_int.keys()) self._pmon_str = self.re_longest_first(self.persian_to_int.keys()) self._imon_str = self.re_longest_first(self.islamic_to_int.keys()) + self._smon_str = self.re_longest_first(self.swedish_to_int.keys()) self._cal_str = self.re_longest_first(self.calendar_to_int.keys()) self._ny_str = self.re_longest_first(self.newyear_to_int.keys()) @@ -293,6 +321,10 @@ class DateParser: re.IGNORECASE) self._itext2 = re.compile('(\d+)?\s+?%s\s*((\d+)(/\d+)?)?\s*$' % self._imon_str, re.IGNORECASE) + self._stext = re.compile('%s\.?\s+(\d+)?\s*,?\s*((\d+)(/\d+)?)?\s*$' % self._smon_str, + re.IGNORECASE) + self._stext2 = re.compile('(\d+)?\s+?%s\.?\s*((\d+)(/\d+)?)?\s*$' % self._smon_str, + re.IGNORECASE) self._numeric = re.compile("((\d+)[/\.]\s*)?((\d+)[/\.]\s*)?(\d+)\s*$") self._iso = re.compile("(\d+)(/(\d+))?-(\d+)-(\d+)\s*$") self._rfc = re.compile("(%s,)?\s+(\d|\d\d)\s+%s\s+(\d+)\s+\d\d:\d\d(:\d\d)?\s+(\+|-)\d\d\d\d" @@ -327,6 +359,10 @@ class DateParser: def _parse_greg_julian(self, text): return self._parse_calendar(text, self._text, self._text2, self.month_to_int, gregorian_valid) + def _parse_swedish(self, text): + return self._parse_calendar(text, self._stext, self._stext2, + self.swedish_to_int,swedish_valid) + def _parse_calendar(self, text, regex1, regex2, mmap, check=None): match = regex1.match(text.lower()) @@ -390,13 +426,20 @@ class DateParser: if subparser == self._parse_greg_julian: check = gregorian_valid + if subparser == self._parse_swedish: + check = swedish_valid else: check = None - + value = subparser(text) if value != Date.EMPTY: return value - + # if 8 digits are entered and month and day in range + # assume yyyymmdd and convert to yyyy-mm-dd + if len(text) == 8 and text.isdigit() \ + and (int(text[4:6]) in range(1,13)) \ + and (int(text[6:8]) in range(1,32)): + text = text[0:4] + "-" + text[4:6] + "-" + text[6:8] match = self._iso.match(text) if match: groups = match.groups() diff --git a/src/DateHandler/_Date_sv.py b/src/DateHandler/_Date_sv.py index 2fba5b55e..a6fcc4140 100644 --- a/src/DateHandler/_Date_sv.py +++ b/src/DateHandler/_Date_sv.py @@ -81,6 +81,8 @@ class DateParserSv(DateParser): u'f' : Date.CAL_FRENCH, u'persisk' : Date.CAL_PERSIAN, u'p' : Date.CAL_PERSIAN, + u'svensk' : Date.CAL_SWEDISH, + u's' : Date.CAL_SWEDISH, } quality_to_int = { @@ -124,7 +126,8 @@ class DateDisplaySv(DateDisplay): " (hebreisk)", " (fransk republikansk)", " (persisk)", - " (islamisk)" + " (islamisk)", + " (svensk)" ) _mod_str = ("", u"före ", u"efter ", u"c:a ", "", "", "") diff --git a/src/Filters/Rules/Person/Makefile.am b/src/Filters/Rules/Person/Makefile.am index b1906d279..c2eb111c3 100644 --- a/src/Filters/Rules/Person/Makefile.am +++ b/src/Filters/Rules/Person/Makefile.am @@ -59,6 +59,7 @@ pkgdata_PYTHON = \ _MultipleMarriages.py \ _NeverMarried.py \ _NoBirthdate.py \ + _NoDeathdate.py \ _PeoplePrivate.py \ _PersonWithIncompleteEvent.py \ _ProbablyAlive.py \ diff --git a/src/Filters/Rules/Person/__init__.py b/src/Filters/Rules/Person/__init__.py index e492240e2..153a50b13 100644 --- a/src/Filters/Rules/Person/__init__.py +++ b/src/Filters/Rules/Person/__init__.py @@ -88,6 +88,7 @@ from _MissingParent import MissingParent from _MultipleMarriages import MultipleMarriages from _NeverMarried import NeverMarried from _NoBirthdate import NoBirthdate +from _NoDeathdate import NoDeathdate from _PeoplePrivate import PeoplePrivate from _PersonWithIncompleteEvent import PersonWithIncompleteEvent from _ProbablyAlive import ProbablyAlive @@ -135,6 +136,7 @@ editor_rule_list = [ NeverMarried, MultipleMarriages, NoBirthdate, + NoDeathdate, PersonWithIncompleteEvent, FamilyWithIncompleteEvent, ProbablyAlive, diff --git a/src/gen/lib/calendar.py b/src/gen/lib/calendar.py index 666e62377..f1c65f3e2 100644 --- a/src/gen/lib/calendar.py +++ b/src/gen/lib/calendar.py @@ -539,3 +539,31 @@ def islamic_ymd(sdn): month = int(min(12, math.ceil((sdn-(29+islamic_sdn(year, 1, 1)))/29.5) + 1)) day = int((sdn - islamic_sdn(year, month, 1)) + 1) return (year, month, day) + +def swedish_sdn(year, month, day): + """Convert a Swedish (almost Julian) date to an SDN number.""" + return julian_sdn(year, month, day)-1 + +def swedish_ymd(sdn): + """Convert an SDN number to a Swedish (almost Julian) calendar date.""" + if sdn == 2346425: + return (1712,2,30) + return julian_ymd(sdn+1) +""" +print "1700-02-28J=", julian_sdn(1700,2,28) +print "1700-02-29S=", swedish_sdn(1700,2,29) +print "1700-03-01S=", swedish_sdn(1700,3,1) +print +print "1712-02-29S=", swedish_sdn(1712,2,29) +print "1712-02-30S=", swedish_sdn(1712,2,30) +print "1712-03-01J=", julian_sdn(1712,3,1) +print +print "1753-02-17J=", julian_sdn(1753,2,17) +print "1753-03-01G=", gregorian_sdn(1753,3,1) +print +print "2346424S=", swedish_ymd(2346424) +print "2346425S=", swedish_ymd(2346425) +print "2346426J=", julian_ymd(2346426) +print +quit() +""" \ No newline at end of file diff --git a/src/gen/lib/date.py b/src/gen/lib/date.py index eab56170e..435dd1e25 100644 --- a/src/gen/lib/date.py +++ b/src/gen/lib/date.py @@ -1,4 +1,4 @@ -# + # # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2000-2007 Donald N. Allingham @@ -53,8 +53,10 @@ log = logging.getLogger(".Date") #------------------------------------------------------------------------ from gen.lib.calendar import (gregorian_sdn, julian_sdn, hebrew_sdn, french_sdn, persian_sdn, islamic_sdn, + swedish_sdn, gregorian_ymd, julian_ymd, hebrew_ymd, - french_ymd, persian_ymd, islamic_ymd) + french_ymd, persian_ymd, islamic_ymd, + swedish_ymd) import Config #------------------------------------------------------------------------- @@ -601,6 +603,7 @@ class Date: CAL_FRENCH = 3 CAL_PERSIAN = 4 CAL_ISLAMIC = 5 + CAL_SWEDISH = 6 NEWYEAR_JAN1 = 0 # CODE NEWYEAR_MAR1 = 1 @@ -625,6 +628,7 @@ class Date: french_sdn, persian_sdn, islamic_sdn, + swedish_sdn, ] _calendar_change = [ @@ -634,6 +638,7 @@ class Date: french_ymd, persian_ymd, islamic_ymd, + swedish_ymd, ] calendar_names = ["Gregorian", @@ -641,7 +646,8 @@ class Date: "Hebrew", "French Republican", "Persian", - "Islamic"] + "Islamic", + "Swedish"] ui_calendar_names = [_("Gregorian"), @@ -649,7 +655,8 @@ class Date: _("Hebrew"), _("French Republican"), _("Persian"), - _("Islamic")] + _("Islamic"), + _("Swedish")] def __init__(self, *source, **kwargs): """ @@ -1099,6 +1106,7 @@ class Date: CAL_FRENCH - French Republican calendar CAL_PERSIAN - Persian calendar CAL_ISLAMIC - Islamic calendar + CAL_SWEDISH - Swedish calendar 1700-03-01 -> 1712-02-30! """ return self.calendar @@ -1107,7 +1115,7 @@ class Date: Set the calendar selected for the date. """ if val not in (Date.CAL_GREGORIAN, Date.CAL_JULIAN, Date.CAL_HEBREW, - Date.CAL_FRENCH, Date.CAL_PERSIAN, Date.CAL_ISLAMIC): + Date.CAL_FRENCH, Date.CAL_PERSIAN, Date.CAL_ISLAMIC, Date-CAL_SWEDISH): raise DateError("Invalid calendar") self.calendar = val @@ -1399,7 +1407,8 @@ class Date: raise DateError("Invalid quality") if calendar not in (Date.CAL_GREGORIAN, Date.CAL_JULIAN, Date.CAL_HEBREW, Date.CAL_FRENCH, - Date.CAL_PERSIAN, Date.CAL_ISLAMIC): + Date.CAL_PERSIAN, Date.CAL_ISLAMIC, + Date.CAL_SWEDISH): raise DateError("Invalid calendar") self.quality = quality diff --git a/src/plugins/import/Makefile.am b/src/plugins/import/Makefile.am index 394fc29cc..b8a772796 100644 --- a/src/plugins/import/Makefile.am +++ b/src/plugins/import/Makefile.am @@ -10,6 +10,7 @@ pkgdata_PYTHON = \ ImportGedcom.py \ ImportGeneWeb.py \ ImportGrdb.py \ + ImportGpkg.py \ ImportProGen.py \ ImportVCard.py