Say, I have an event that starts at 1:30 and ends at 6:30 (for example, it could be any time). The event is recurrent that is it's repeating. In this example, it repeats every second day but it can be 2, 3 and any other number.
I need to figure out if the given datetime is inside of any such slots.
Say, the Nov, 16th 4:17 am is out, but Nov, 17th 4:17 is in.
Maybe, there are libraries for Python that can do it? Or there is some simple approach to calculate it?
Using dateutil.rrule, I probably can calculate dates but I can't figure out how to apply this knowledge to solve the task.
So it should be a function of this signature:
def inside_slot(start_datetime, end_datetime, interval, given_datetime):
'''
Returns True if the given_datetime inside of a recurring
slot, else False.
'''
pass
You can use datetime to compare the given datetime with the start and end times of the event, and then check if it falls within any recurring slots.
Here's an example code using datetime:
Keep in mind that you need to modify the format strings in the
strptime
method according to your specific date and time format. Additionally, you need to handle the case when the given time is before the first recurring slot.