Newyear import/export changes and fix

svn: r15027
This commit is contained in:
Doug Blank 2010-04-04 12:10:12 +00:00
parent e740d374a9
commit c551d6beb1
4 changed files with 21 additions and 10 deletions

View File

@ -340,7 +340,7 @@ class DateEditorDialog(ManagedWindow.ManagedWindow):
self.start_year.get_value_as_int(), self.start_year.get_value_as_int(),
self.dual_dated.get_active()) self.dual_dated.get_active())
calendar = self.calendar_box.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) return (quality, modifier, calendar, value, text, newyear)
def switch_type(self, obj): def switch_type(self, obj):

View File

@ -1062,18 +1062,20 @@ class Date(object):
ny = "Err" ny = "Err"
return ny 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() string = string.strip().lower()
if string == "" or string == "jan1": if string == "" or string == "jan1":
code = Date.NEWYEAR_JAN1 code = Date.NEWYEAR_JAN1
elif string == "mar1": elif string == "mar1":
code = Date.NEWYEAR_MAR1 code = Date.NEWYEAR_MAR1
elif self.newyear == "mar25": elif string == "mar25":
code = Date.NEWYEAR_MAR25 code = Date.NEWYEAR_MAR25
elif self.newyear == "sep1": elif string == "sep1":
code = Date.NEWYEAR_SEP1 code = Date.NEWYEAR_SEP1
elif "-" in string: elif "-" in string:
try: try:
@ -1762,3 +1764,4 @@ def lookup_calendar(calendar):
if calendar.lower() == calendar_name.lower(): if calendar.lower() == calendar_name.lower():
return pos return pos
raise AttributeError("invalid calendar: '%s'" % calendar) raise AttributeError("invalid calendar: '%s'" % calendar)

View File

@ -804,9 +804,9 @@ class GrampsXmlWriter(UpdateCallback):
else: else:
dualdated_str = '' dualdated_str = ''
newyear = date.get_new_year() newyear = date.newyear_to_str()
if newyear != gen.lib.Date.NEWYEAR_JAN1: if newyear:
newyear_str = ' newyear="%d"' % newyear newyear_str = ' newyear="%s"' % newyear
else: else:
newyear_str = '' newyear_str = ''

View File

@ -1771,7 +1771,11 @@ class GrampsParser(UpdateCallback):
newyear = gen.lib.Date.NEWYEAR_JAN1 newyear = gen.lib.Date.NEWYEAR_JAN1
if 'newyear' in attrs: 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, date_value.set(qual, mode, cal,
(day, month, year, dualdated, (day, month, year, dualdated,
@ -1848,7 +1852,11 @@ class GrampsParser(UpdateCallback):
newyear = gen.lib.Date.NEWYEAR_JAN1 newyear = gen.lib.Date.NEWYEAR_JAN1
if 'newyear' in attrs: 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), date_value.set(qual, mod, cal, (day, month, year, dualdated),
newyear=newyear) newyear=newyear)