* 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  <dblank@cs.brynmawr.edu>


svn: r9201
This commit is contained in:
Doug Blank 2007-10-17 04:21:34 +00:00
parent 5d276ee146
commit b4cc165711
3 changed files with 40 additions and 92 deletions

View File

@ -1,3 +1,7 @@
2007-10-17 Douglas S. Blank <dblank@cs.brynmawr.edu>
* 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 <dblank@cs.brynmawr.edu>
* src/gen/lib/date.py: added method Date.offset(value) -> (y,m,d)

View File

@ -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 == "*":

View File

@ -23,51 +23,8 @@
<date name="Daylight Savings ends" value="*/-1/sun/oct" type="informational" />
<date name="Christmas" value="*/12/25" type="national" />
<date name="Boxing Day" value="*/12/26" type="national" />
<date name="Easter" type="religious" value="1980/4/6" />
<date name="Easter" type="religious" value="1981/4/19" />
<date name="Easter" type="religious" value="1982/4/11" />
<date name="Easter" type="religious" value="1983/4/3" />
<date name="Easter" type="religious" value="1984/4/22" />
<date name="Easter" type="religious" value="1985/4/7" />
<date name="Easter" type="religious" value="1986/3/30" />
<date name="Easter" type="religious" value="1987/4/19" />
<date name="Easter" type="religious" value="1988/4/3" />
<date name="Easter" type="religious" value="1989/3/26" />
<date name="Easter" type="religious" value="1990/4/15" />
<date name="Easter" type="religious" value="1991/3/31" />
<date name="Easter" type="religious" value="1992/4/19" />
<date name="Easter" type="religious" value="1993/4/11" />
<date name="Easter" type="religious" value="1994/4/3" />
<date name="Easter" type="religious" value="1995/4/16" />
<date name="Easter" type="religious" value="1996/4/7" />
<date name="Easter" type="religious" value="1997/3/30" />
<date name="Easter" type="religious" value="1998/4/12" />
<date name="Easter" type="religious" value="1999/4/4" />
<date name="Easter" type="religious" value="2000/4/23" />
<date name="Easter" type="religious" value="2001/4/15" />
<date name="Easter" type="religious" value="2002/3/31" />
<date name="Easter" type="religious" value="2003/4/20" />
<date name="Easter" type="religious" value="2004/4/11" />
<date name="Easter" type="religious" value="2005/3/27" />
<date name="Easter" type="religious" value="2006/4/16" />
<date name="Easter" type="religious" value="2007/4/8" />
<date name="Easter" type="religious" value="2008/3/23" />
<date name="Easter" type="religious" value="2009/4/12" />
<date name="Easter" type="religious" value="2010/4/4" />
<date name="Easter" type="religious" value="2011/4/24" />
<date name="Easter" type="religious" value="2012/4/8" />
<date name="Easter" type="religious" value="2013/3/31" />
<date name="Easter" type="religious" value="2014/4/20" />
<date name="Easter" type="religious" value="2015/4/5" />
<date name="Easter" type="religious" value="2016/3/27" />
<date name="Easter" type="religious" value="2017/4/16" />
<date name="Easter" type="religious" value="2018/4/1" />
<date name="Easter" type="religious" value="2019/4/21" />
<date name="Easter" type="religious" value="2020/4/12" />
<date name="Easter" type="religious" value="2021/4/4" />
<date name="Easter" type="religious" value="2022/4/17" />
<date name="Easter" type="religious" value="2023/4/9" />
<date name="Easter" type="religious" value="2024/3/31" />
<date name="Easter" type="religious" value="> easter(y)" />
<date name="Ash Wednesday" type="religious" value="> easter(y) - 46" />
<date name="Passover" value="2005/4/24" type="religious" />
<date name="Passover" value="2006/4/13" type="religious" />
<date name="Passover" value="2007/4/03" type="religious" />
@ -130,51 +87,8 @@
<date name="Income Taxes due" value="*/4/17" type="national"
if="date.weekday() == 0" />
<date name="Daylight Savings ends" value="*/-1/sun/oct" type="informational" />
<date name="Easter" type="religious" value="1980/4/6" />
<date name="Easter" type="religious" value="1981/4/19" />
<date name="Easter" type="religious" value="1982/4/11" />
<date name="Easter" type="religious" value="1983/4/3" />
<date name="Easter" type="religious" value="1984/4/22" />
<date name="Easter" type="religious" value="1985/4/7" />
<date name="Easter" type="religious" value="1986/3/30" />
<date name="Easter" type="religious" value="1987/4/19" />
<date name="Easter" type="religious" value="1988/4/3" />
<date name="Easter" type="religious" value="1989/3/26" />
<date name="Easter" type="religious" value="1990/4/15" />
<date name="Easter" type="religious" value="1991/3/31" />
<date name="Easter" type="religious" value="1992/4/19" />
<date name="Easter" type="religious" value="1993/4/11" />
<date name="Easter" type="religious" value="1994/4/3" />
<date name="Easter" type="religious" value="1995/4/16" />
<date name="Easter" type="religious" value="1996/4/7" />
<date name="Easter" type="religious" value="1997/3/30" />
<date name="Easter" type="religious" value="1998/4/12" />
<date name="Easter" type="religious" value="1999/4/4" />
<date name="Easter" type="religious" value="2000/4/23" />
<date name="Easter" type="religious" value="2001/4/15" />
<date name="Easter" type="religious" value="2002/3/31" />
<date name="Easter" type="religious" value="2003/4/20" />
<date name="Easter" type="religious" value="2004/4/11" />
<date name="Easter" type="religious" value="2005/3/27" />
<date name="Easter" type="religious" value="2006/4/16" />
<date name="Easter" type="religious" value="2007/4/8" />
<date name="Easter" type="religious" value="2008/3/23" />
<date name="Easter" type="religious" value="2009/4/12" />
<date name="Easter" type="religious" value="2010/4/4" />
<date name="Easter" type="religious" value="2011/4/24" />
<date name="Easter" type="religious" value="2012/4/8" />
<date name="Easter" type="religious" value="2013/3/31" />
<date name="Easter" type="religious" value="2014/4/20" />
<date name="Easter" type="religious" value="2015/4/5" />
<date name="Easter" type="religious" value="2016/3/27" />
<date name="Easter" type="religious" value="2017/4/16" />
<date name="Easter" type="religious" value="2018/4/1" />
<date name="Easter" type="religious" value="2019/4/21" />
<date name="Easter" type="religious" value="2020/4/12" />
<date name="Easter" type="religious" value="2021/4/4" />
<date name="Easter" type="religious" value="2022/4/17" />
<date name="Easter" type="religious" value="2023/4/9" />
<date name="Easter" type="religious" value="2024/3/31" />
<date name="Easter" type="religious" value="> easter(y)" />
<date name="Ash Wednesday" type="religious" value="> easter(y) - 46" />
<date name="Passover" value="2005/4/24" type="religious" />
<date name="Passover" value="2006/4/13" type="religious" />
<date name="Passover" value="2007/4/03" type="religious" />