Skip to content

Commit

Permalink
Fix previous_months_iterator. Addresses #356
Browse files Browse the repository at this point in the history
Avoid rrule when possibly iterating forward from days 29-31 of months,
rrule simply skip month if it tries to iterate to e.g., February 30.

previous_months_iterator start num_months -1 back to incl. current

Since changing the method of providing a previous months generator, we
need to start one fewer months back or we lose the current month in
the output.  current_month should be last month returned in history
  • Loading branch information
bryanlandia committed Jun 8, 2021
1 parent 519b6fb commit 69d6377
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions figures/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,10 @@ def previous_months_iterator(month_for, months_back):
# TODO make sure we've got just two values in the tuple
month_for = datetime.date(year=month_for[0], month=month_for[1], day=1)
if isinstance(month_for, (datetime.datetime, datetime.date)):
start_month = month_for - relativedelta(months=months_back)
start_month = month_for - relativedelta(months=(months_back - 1))

for dt in rrule(freq=MONTHLY, dtstart=start_month, until=month_for):
for n_months in range(months_back):
dt = start_month + relativedelta(months=n_months)
last_day_of_month = days_in_month(month_for=dt)
yield (dt.year, dt.month, last_day_of_month)

Expand Down

0 comments on commit 69d6377

Please sign in to comment.