Skip to content

Commit

Permalink
Merge pull request #35 from pganssle/rrule-fix
Browse files Browse the repository at this point in the history
RRULE fix for 2.4.0 ByNWeekday issue.
  • Loading branch information
jarondl committed Feb 12, 2015
2 parents 0b5771a + a7213cb commit 06a5058
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
33 changes: 20 additions & 13 deletions dateutil/rrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,11 @@ def __init__(self, freq, dtstart=None,
self._byweekday = None
self._bynweekday = None
else:
if isinstance(byweekday, integer_types):
# If it's one of the valid non-sequence types, convert to a
# single-element sequence before the iterator that builds the
# byweekday set.
if isinstance(byweekday, integer_types) or hasattr(byweekday, "n"):
byweekday = (byweekday,)
elif hasattr(byweekday, "n"):
byweekday = (byweekday.weekday,)

self._byweekday = set()
self._bynweekday = set()
Expand Down Expand Up @@ -794,10 +795,13 @@ def __construct_byset(self, start, byxxx, base):
BYHOUR would be {21, 1, 5, 9, 13, 17}, because 4 and 24 are not
coprime.
:param:`start` specifies the starting position.
:param:`byxxx` is an iterable containing the list of allowed values.
:param:`base` is the largest allowable value for the specified
frequency (e.g. 24 hours, 60 minutes).
:param start:
Specifies the starting position.
:param byxxx:
An iterable containing the list of allowed values.
:param base:
The largest allowable value for the specified frequency (e.g.
24 hours, 60 minutes).
This does not preserve the type of the iterable, returning a set, since
the values should be unique and the order is irrelevant, this will
Expand Down Expand Up @@ -830,12 +834,15 @@ def __mod_distance(self, value, byxxx, base):
specified along with a `BYXXX` parameter at the same "level"
(e.g. `HOURLY` specified with `BYHOUR`).
:param:`value` is the old value of the component.
:param:`byxxx` is the `BYXXX` set, which should have been generated
by `rrule._construct_byset`, or something else which
checks that a valid rule is present.
:param:`base` is the largest allowable value for the specified
frequency (e.g. 24 hours, 60 minutes).
:param value:
The old value of the component.
:param byxxx:
The `BYXXX` set, which should have been generated by
`rrule._construct_byset`, or something else which checks that a
valid rule is present.
:param base:
The largest allowable value for the specified frequency (e.g.
24 hours, 60 minutes).
If a valid value is not found after `base` iterations (the maximum
number before the sequence would start to repeat), this raises a
Expand Down
10 changes: 10 additions & 0 deletions dateutil/test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,16 @@ def testMonthlyByNWeekDay(self):
datetime(1997, 9, 25, 9, 0),
datetime(1997, 10, 7, 9, 0)])

# Third Monday of the month
self.assertEqual(rrule(MONTHLY,
byweekday=(MO(+3)),
dtstart=datetime(1997, 9, 1)).between(datetime(1997, 9, 1),
datetime(1997, 12, 1)),
[datetime(1997, 9, 15, 0, 0),
datetime(1997, 10, 20, 0, 0),
datetime(1997, 11, 17, 0, 0)])


def testMonthlyByNWeekDayLarge(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
Expand Down

0 comments on commit 06a5058

Please sign in to comment.