From c551d6beb1f1891484cf2637d31548d5e88eb9a0 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Sun, 4 Apr 2010 12:10:12 +0000 Subject: [PATCH] Newyear import/export changes and fix svn: r15027 --- src/DateEdit.py | 2 +- src/gen/lib/date.py | 11 +++++++---- src/plugins/export/ExportXml.py | 6 +++--- src/plugins/import/ImportXml.py | 12 ++++++++++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/DateEdit.py b/src/DateEdit.py index 3e908f24b..b63709971 100644 --- a/src/DateEdit.py +++ b/src/DateEdit.py @@ -340,7 +340,7 @@ class DateEditorDialog(ManagedWindow.ManagedWindow): self.start_year.get_value_as_int(), self.dual_dated.get_active()) calendar = self.calendar_box.get_active() - newyear = self.date.newyear_to_code(self.new_year.get_text()) + newyear = Date.newyear_to_code(self.new_year.get_text()) return (quality, modifier, calendar, value, text, newyear) def switch_type(self, obj): diff --git a/src/gen/lib/date.py b/src/gen/lib/date.py index 30a6dcd24..e353902e8 100644 --- a/src/gen/lib/date.py +++ b/src/gen/lib/date.py @@ -1062,18 +1062,20 @@ class Date(object): ny = "Err" return ny - def newyear_to_code(self, string): + @staticmethod + def newyear_to_code(string): """ - Return the code of a newyear string. + Return newyear code of string, where string is: + '', 'Jan1', 'Mar1', '3-25', '9-1', etc. """ string = string.strip().lower() if string == "" or string == "jan1": code = Date.NEWYEAR_JAN1 elif string == "mar1": code = Date.NEWYEAR_MAR1 - elif self.newyear == "mar25": + elif string == "mar25": code = Date.NEWYEAR_MAR25 - elif self.newyear == "sep1": + elif string == "sep1": code = Date.NEWYEAR_SEP1 elif "-" in string: try: @@ -1762,3 +1764,4 @@ def lookup_calendar(calendar): if calendar.lower() == calendar_name.lower(): return pos raise AttributeError("invalid calendar: '%s'" % calendar) + diff --git a/src/plugins/export/ExportXml.py b/src/plugins/export/ExportXml.py index f1dd45165..201665c52 100644 --- a/src/plugins/export/ExportXml.py +++ b/src/plugins/export/ExportXml.py @@ -804,9 +804,9 @@ class GrampsXmlWriter(UpdateCallback): else: dualdated_str = '' - newyear = date.get_new_year() - if newyear != gen.lib.Date.NEWYEAR_JAN1: - newyear_str = ' newyear="%d"' % newyear + newyear = date.newyear_to_str() + if newyear: + newyear_str = ' newyear="%s"' % newyear else: newyear_str = '' diff --git a/src/plugins/import/ImportXml.py b/src/plugins/import/ImportXml.py index 1ea4dfe5f..749dc3c97 100644 --- a/src/plugins/import/ImportXml.py +++ b/src/plugins/import/ImportXml.py @@ -1771,7 +1771,11 @@ class GrampsParser(UpdateCallback): newyear = gen.lib.Date.NEWYEAR_JAN1 if 'newyear' in attrs: - newyear = int(attrs['newyear']) + newyear = attrs['newyear'] + if newyear.isdigit(): + newyear = int(newyear) + else: + newyear = gen.lib.Date.newyear_to_code(newyear) date_value.set(qual, mode, cal, (day, month, year, dualdated, @@ -1848,7 +1852,11 @@ class GrampsParser(UpdateCallback): newyear = gen.lib.Date.NEWYEAR_JAN1 if 'newyear' in attrs: - newyear = int(attrs['newyear']) + newyear = attrs['newyear'] + if newyear.isdigit(): + newyear = int(newyear) + else: + newyear = gen.lib.Date.newyear_to_code(newyear) date_value.set(qual, mod, cal, (day, month, year, dualdated), newyear=newyear)