Exclusion of calendar holidays from rrule before processing

I am using the rrule method from the python-dateutil package. I would like to create a rule that can ignore the dates that are on the holiday calendar. I know about the exdate () method, but this seems to filter the date from the output list only by the generated one.

from dateutil.rrule import * from datetime import datetime set = rruleset() set.rrule(rrule(MONTHLY, count=4, bysetpos=-1, byweekday=(MO, TU, WE, TH, FR), dtstart=datetime(2013,1,1))) list(set) # outputs 4 dates without an exdate() call > [datetime.datetime(2013, 1, 31, 0, 0), datetime.datetime(2013, 2, 28, 0, 0), datetime.datetime(2013, 3, 29, 0, 0), datetime.datetime(2013, 4, 30, 0, 0)] set.exdate(datetime.datetime(2013, 2, 28, 0, 0)) list(set) # only outputs 3 dates, ignoring the date provided in exdate() > [datetime.datetime(2013, 1, 31, 0, 0), datetime.datetime(2013, 3, 29, 0, 0), datetime.datetime(2013, 4, 30, 0, 0)] 

What I would like to do rrule is not to omit datetime (2013, 2, 28, 0, 0), but instead look back to find the next best date according to the original rules, i.e. in this case datetime (2013 , 2, 27, 0, 0). Any ideas how I could achieve this?

+6
source share

Source: https://habr.com/ru/post/944872/


All Articles