diff --git a/ChangeLog b/ChangeLog index 44ceeda4a..30ed2bf23 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-10-17 Douglas S. Blank + * src/plugins/Calendar.py: changed exp eval char to '>' + * src/plugins/holidays.xml: added easter and ash wed eval's + 2007-10-17 Douglas S. Blank * src/gen/lib/date.py: added method Date.offset(value) -> (y,m,d) diff --git a/src/plugins/Calendar.py b/src/plugins/Calendar.py index f2ca06628..2cb05bb84 100644 --- a/src/plugins/Calendar.py +++ b/src/plugins/Calendar.py @@ -74,7 +74,7 @@ def easter(year): l = i - j month = 3 + (l + 40) / 44 day = l + 28 - 31 * ( month / 4 ) - return "%d/%d/%d" % (year, month, day) + return SDate("%d/%d/%d" % (year, month, day)) def g2iso(dow): """ Converst GRAMPS day of week to ISO day of week """ @@ -82,6 +82,35 @@ def g2iso(dow): # ISO: MON = 1 return (dow + 5) % 7 + 1 +class SDate(str): + """ String date that you can add/subtract to/from. """ + def __init__(self, sdate): + self.sdate = sdate + + def __add__(self, other): + """ Date math: add day to a string date 'y/m/d' """ + dy, dm, dd = map(int, self.sdate.split("/")) + date = gen.lib.Date() + date.set_yr_mon_day(dy, dm, dd) + y,m,d = date.offset(other) + return "%d/%d/%d" % (y,m,d) + + def __radd__(self, other): + """ Date math: add day to a string date 'y/m/d' on right """ + return self.__add__(other) + + def __sub__(self, other): + """ Date math: subtract day to a string date 'y/m/d' """ + return self.__add__(-other) + + def __rsub__(self, other): + """ Date math: subtract day to a string date 'y/m/d' on right """ + return self.__sub__(other) + + def __str__(self): + # Don't need to overload len, split, or count because it uses this + return self.sdate + #------------------------------------------------------------------------ # # Calendar @@ -732,10 +761,11 @@ class Holidays: else: # must be a dayname offset = rule["offset"] - if len(rule["value"]) > 0 and rule["value"][0] == '&': + if len(rule["value"]) > 0 and rule["value"][0] == '>': # eval exp -> year/num[/day[/month]] y, m, d = date.year, date.month, date.day rule["value"] = eval(rule["value"][1:]) + if self.debug: print "rule['value']:", rule["value"] if rule["value"].count("/") == 3: # year/num/day/month, "3rd wednesday in april" y, num, dayname, mon = rule["value"].split("/") if y == "*": diff --git a/src/plugins/holidays.xml b/src/plugins/holidays.xml index 1ddc2f128..5398b243a 100644 --- a/src/plugins/holidays.xml +++ b/src/plugins/holidays.xml @@ -23,51 +23,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -130,51 +87,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +