Was hoping to get a bit of feedback on designing a
rrule. I'm wondering what the best way to create a minutely rule is but omit entire days. So for example get 5 minute intervals every weekday between some time but omit certain holidays. I thought of using something like
INTERVAL = 5 BUCKETS = int(60 / INTERVAL * 24) WEEKDAYS = (MO, TU, WE, TH, FR) nyd = rrule(MONTHLY, dtstart=datetime(2019, 1, 1, 0, 0), bymonth=1, byminute=range(0, 59, INTERVAL), byhour=range(0,24), bysetpos=range(1, BUCKETS + 1), byweekday=WEEKDAYS, count=300)
which works, but I'm wondering if this is some non recommended hackery. The reason I ask is because
bysetpos only supports values up until 366. For minutely and secondly data you could have situations where you want to use
bysetpos up to 1440 and 86400 respectively, so I'm wondering if
bysetpos is not intended for this use?
INTERVAL = 5 BUCKETS = int(60 / INTERVAL * 24) WEEKDAYS = (MO, TU, WE, TH, FR) rrule_base = rrule(MINUTELY, dtstart=datetime(2019, 1, 1, 0, 0), count=300, byweekday=WEEKDAYS) rrset = rruleset() rrset.rrule(rrule_base) for dt in holidays: rrset.exrule(rrule_base.replace(dtstart=dt, until=(dt + timedelta(days=1)), count=None))
for dt in holidays: for inst in rrule_base.between(dt, dt + timedelta(days=1)): rrset.exdate(inst)
Following up on your comments about
bysetpos and the RFC, I don't see any mention of restricting this. My guess is that it was implemented with DAILY frequency in mind? The docstrings also don't mention anything
If given, it must be either an integer, or a sequence of integers,
positive or negative. Each given integer will specify an occurrence
number, corresponding to the nth occurrence of the rule inside the
frequency period. For example, a bysetpos of -1 if combined with a
MONTHLY frequency, and a byweekday of (MO, TU, WE, TH, FR), will
result in the last work day of every month.
list(rrule(MINUTELY, dtstart=datetime(2019, 1, 1, 0, 0), bysetpos=367, count=3, byweekday=MO))
In addition in playing around with this I think there may be an issue more broadly with
bysetpos when using
MINUTELY. This runs fine
In : list(rrule(MINUTELY, dtstart=datetime(2019, 1, 1, 0, 0), bysetpos=1, count=1, byweekday=MO)) Out: [datetime.datetime(2019, 1, 7, 0, 0)]
but this seems to run indefinitely
list(rrule(MINUTELY, dtstart=datetime(2019, 1, 1, 0, 0), bysetpos=2, count=1, byweekday=MO))
yieldstatement is never reached? Or else the algorithm is just taking a very long time, still haven't fully grokked how
bysetposmay be an exception here), I can transform the inputs the the rule to some canonicalization so that
freq=HOURLY, interval=1"compile down" to the same thing, which I can then optimize.
.whl) for both dateutil and six, you shouldn't have to download anything to install them
pip download python-dateutilshould download all the files.
(easter.easter(y, easter.EASTER_ORTHODOX) for y in range(y_start, y_end))should be a good start.
.betweenyou can create an
rrule.rrulset()and then add all the easters as
rruleis an interesting and complicated module, Part of my Pycon 2019 tutorial covers
rruleand might help you find some workarounds: https://youtu.be/Xt8age1Be4E?t=7189 (starts at the part where I discuss rrule)