Class constructor (initializer for the data type).
rules
list[indie.schedule.ScheduleRule]
required
List of ScheduleRule instances that define the active scheduling rules.
except_once
list[datetime.datetime]
default:[]
List of dates that are excluded from the schedule only once.
except_yearly
list[datetime.datetime]
default:[]
List of dates that are excluded from the schedule every year.
timezone
str
default:"UTC"
Timezone for schedule.
is_empty
() -> bool
Checks if the rules list in Schedule is empty. Returns True if list of rules is empty; otherwise, returns False.
__contains__
(t) -> bool
Checks whether a given timestamp falls within the defined schedule. Returns True if the timestamp falls within the schedule’s active periods, otherwise returns False.
t
float
required
Timestamp to check in defined schedule.
__contains__
(d) -> bool
Checks whether a given timestamp falls within the defined schedule. Returns True if the timestamp falls within the schedule’s active periods, otherwise returns False.
d
datetime.datetime
required
Datetime to check in defined schedule.
is_same_period
(timestamp1, timestamp2) -> bool
Determines whether two timestamps fall within the same schedule period on the same day. Returns True if both timestamps fall within the same period of the schedule, even if they are in different calendar days. False if the timestamps belong to different periods within the schedule.
timestamp1
float
required
First timestamp to check.
timestamp2
float
required
Second timestamp to check.
This method checks if two timestamps, which may belong to different calendar days, are part of the same schedule period. It handles cases where a schedule spans across two consecutive days (e.g., a trading schedule that extends past midnight) and ensures both timestamps belong to the same logical period within the schedule.
Data type to represent a rule for a schedule, specifying the start and end times, along with the weekdays when the rule is active.
Methods
__init__
(start, end, days) -> None
Class constructor (initializer for the data type).
start
datetime.time
required
Start time of the rule.
end
datetime.time
required
End time of the rule.
days
list[int]
default:indie.schedule.ALL_DAYS
List of weekdays when the rule is active.
Example
# this rule applies from 9:00 AM to 6:30 PM (6:30 is not included) on weekdays (Monday through Friday).rule = ScheduleRule(start=time(hour=9), end=time(hour=18, minute=30), days=WORKDAYS)# this overnight_rule applies from 8:15 PM to 7:30 AM on weekdays (Monday through Friday).overnight_rule = ScheduleRule(start=time(hour=20, minute=15), end=time(hour=7, minute=30), days=WORKDAYS)
For rules that span overnight (e.g., from 10:00 PM to 6:00 AM), the end time should be on the day listed in days, while the start time is understood to be on the previous day. This allows the rule to cover activities that occur late in the evening and extend into the early hours of the next day.