New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rrule bug when start date is month end and frequency is monthly #149
Comments
Hi,
The current behaviour respects the RFC. Maybe there might be some parameter added to let the user decides which behaviour s/he's expecting (be strict and exclude, or floor/ceil the occurence). |
@phep Good call. I don't think it's necessary to add any sort of user option for this. If I recall correctly, if you want to get the last day of the month, you can use |
Yes, it is true that one can use rrules to express offset from start or end of month, but this is not necessarily semantically equivalent to the given example. Let's say you sell some online service to which customers may subscribe on a monthly basis and the terms are computed from day of month to day of month, i.e. if a customer subscribes the 15th of October, the next payment will occur on the 15th of November. How to deal with the cases where customers first subscribe on the 29, 30 or 31? Presently we are forced to test this in the code to adjust the term date to the month duration, some way or another. Wouldn't it be nice if we'd just have to write something similar to |
@phep I'll have to think about this. I can't imagine that iCal doesn't have this problem and given that they expressly thought about it, I imagine they have a way to handle it. I'm hesitant to start moving beyond the RFC. It may cause problems with the conversion between rrule and rrulestr. In the relatively simple situation you describe, I'd probably just not use an RRULE at all: from dateutil.relativedelta import relativedelta
from datetime import datetime
from itertools import count
dtstart = datetime(2015, 1, 31)
interval = 1
MONTH = relativedelta(months=1)
rr = (dtstart + x * MONTH for x in count(1, interval))
print([next(rr) for x in range(5)]) Output:
That said, obviously you lose the general functionality of an rrule by doing that, so it's worth thinking about expressing the same thing as an RRULE. |
@pganssle, going back to the problem, I think you nailed it:
"Special cases aren't special enough to break the rules." the zen of Python says. The RFC is not perfect but diverging from it would just bring less perfection, or, in this case, more uncertainty. Yet the strangeness reported by @broncos168 might deserve some nota bene in the documentation. |
Resolved by #213 |
Hi, I've been trying to execute what @pganssle said, it's works when we put as entry january 31, but if I change it to abril it's bring back the errors on the last day of the months: the return is: Can someone help to solve that in a better way? I got how to solve buts it's looks like:
it's gets the list of first days of the month from the period and changes the day for which date using calendar.monthyrange() |
Please bear me. I am new to Python and this is my first time post in github. Thanks.
Code snippet to demo the bug:
In this edge case, outputs are not monthly
Output:
The text was updated successfully, but these errors were encountered: