Polish on workday/weekend offset
svn: r14164
This commit is contained in:
parent
dd4be4b0e5
commit
ba553eeba6
@ -300,8 +300,8 @@ class _Holidays:
|
|||||||
MONTHS = ['jan', 'feb', 'mar', 'apr', 'may', 'jun',
|
MONTHS = ['jan', 'feb', 'mar', 'apr', 'may', 'jun',
|
||||||
'jul', 'aug', 'sep', 'oct', 'nov', 'dec']
|
'jul', 'aug', 'sep', 'oct', 'nov', 'dec']
|
||||||
DAYS = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']
|
DAYS = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']
|
||||||
WORKDAY = ['mon', 'tue', 'wed', 'thu', 'fri']
|
WORKDAY = range(5) # indexes into above
|
||||||
WEEKEND = ['sat', 'sun']
|
WEEKEND = (5, 6) # indexes into above
|
||||||
def __init__(self, elements, country="US"):
|
def __init__(self, elements, country="US"):
|
||||||
self.debug = 0
|
self.debug = 0
|
||||||
self.elements = elements
|
self.elements = elements
|
||||||
@ -370,7 +370,7 @@ class _Holidays:
|
|||||||
else:
|
else:
|
||||||
# must be a dayname or "workday"
|
# must be a dayname or "workday"
|
||||||
offset = rule["offset"]
|
offset = rule["offset"]
|
||||||
|
|
||||||
if rule["value"].startswith('>'):
|
if rule["value"].startswith('>'):
|
||||||
# eval exp -> year/num[/day[/month]]
|
# eval exp -> year/num[/day[/month]]
|
||||||
y, m, d = date.year, date.month, date.day
|
y, m, d = date.year, date.month, date.day
|
||||||
@ -388,7 +388,7 @@ class _Holidays:
|
|||||||
m = int(mon)
|
m = int(mon)
|
||||||
elif mon == "*":
|
elif mon == "*":
|
||||||
m = date.month
|
m = date.month
|
||||||
else:
|
elif mon in self.MONTHS:
|
||||||
m = self.MONTHS.index(mon) + 1
|
m = self.MONTHS.index(mon) + 1
|
||||||
dates_of_dayname = self.get_daynames(y, m, dayname)
|
dates_of_dayname = self.get_daynames(y, m, dayname)
|
||||||
|
|
||||||
@ -426,14 +426,19 @@ class _Holidays:
|
|||||||
if offset[0] == "-":
|
if offset[0] == "-":
|
||||||
direction = -1
|
direction = -1
|
||||||
offset = offset[1:]
|
offset = offset[1:]
|
||||||
|
elif offset[0] == "+":
|
||||||
|
direction = 1
|
||||||
|
offset = offset[1:]
|
||||||
|
|
||||||
if offset == "workday":
|
if offset == "workday":
|
||||||
|
# next workday you come to, including this one
|
||||||
dow = self.WORKDAY
|
dow = self.WORKDAY
|
||||||
ordinal = ndate.toordinal()
|
ordinal = ndate.toordinal()
|
||||||
while ndate.fromordinal(ordinal).weekday() not in dow:
|
while ndate.fromordinal(ordinal).weekday() not in dow:
|
||||||
ordinal += direction
|
ordinal += direction
|
||||||
ndate = ndate.fromordinal(ordinal)
|
ndate = ndate.fromordinal(ordinal)
|
||||||
elif offset == "weekend":
|
elif offset == "weekend":
|
||||||
|
# next weekend you come to, including this one
|
||||||
dow = self.WEEKEND
|
dow = self.WEEKEND
|
||||||
ordinal = ndate.toordinal()
|
ordinal = ndate.toordinal()
|
||||||
while ndate.fromordinal(ordinal).weekday() not in dow:
|
while ndate.fromordinal(ordinal).weekday() not in dow:
|
||||||
@ -446,7 +451,7 @@ class _Holidays:
|
|||||||
while ndate.fromordinal(ordinal).weekday() != dow:
|
while ndate.fromordinal(ordinal).weekday() != dow:
|
||||||
ordinal += direction
|
ordinal += direction
|
||||||
ndate = ndate.fromordinal(ordinal)
|
ndate = ndate.fromordinal(ordinal)
|
||||||
|
|
||||||
if self.debug:
|
if self.debug:
|
||||||
print "ndate:", ndate, "date:", date
|
print "ndate:", ndate, "date:", date
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user