I'm trying to create some date recurrence rules. Based on the issues with dateutil
noted here and here I am trying to use relativedelta
rather than rrule
. However, I am encountering a silly problem that is stumping me and which is illustrated with the following minimal example. Consider this:
MONTH = relativedelta(months=+1)
print(first_date + MONTH, first_date + 2*MONTH)
When first_date
is the last day in a month with 31 days, such as 05/31/2007, the code yield the correct two dates: June 30th and July 31st.
But, when first_date
is the last day in a month with 30 days, such as 04/30/2007, the code yields : May 30th and June 30th. What it should have given is May 31st and June 30th.
Any ideas how I can overcome this issue?
By adding and subtracting one day, the problem gets resolved:
Output: