> ## Documentation Index
> Fetch the complete documentation index at: https://takeprofit.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Package indie.schedule

> Library reference for indie.schedule package. Covers scheduling rules, weekday enums, and time-based conditions. Includes Schedule, ScheduleRule, and built-in constants

export const Anchor = ({id}) => {
  return <div id={id} style={{
    scrollMarginTop: "var(--scroll-mt)"
  }}></div>;
};

export const Field = ({id, name, type, required, defaultVal, children}) => {
  return <div id={id} style={{
    scrollMarginTop: "var(--scroll-mt)"
  }} className="mt-4">
      <div className="pt-2.5 pb-5 my-2.5 border-gray-50 dark:border-gray-800/50 border-b">
        <div className="flex font-mono text-sm group/param-head param-head">
          <div className="flex-1 flex content-start py-0.5 mr-5">
            <div className="flex items-center flex-wrap gap-2">
              {id && <div className="absolute">
                  <a href={`#${id}`} className="-ml-10 flex items-center opacity-0 border-0 group-hover/param-head:opacity-100 py-2" aria-label={`Navigate to ${id}`}>
                    <div className="w-6 h-6 text-gray-400 rounded-md flex items-center justify-center zinc-box bg-white ring-1 ring-gray-400/30 dark:ring-gray-700/25 hover:ring-gray-400/60 dark:hover:ring-white/20">
                      <svg xmlns="http://www.w3.org/2000/svg" fill="gray" height="12px" viewBox="0 0 576 512">
                        <path d="M0 256C0 167.6 71.6 96 160 96h72c13.3 0 24 10.7 24 24s-10.7 24-24 24H160C98.1 144 48 194.1 48 256s50.1 112 112 112h72c13.3 0 24 10.7 24 24s-10.7 24-24 24H160C71.6 416 0 344.4 0 256zm576 0c0 88.4-71.6 160-160 160H344c-13.3 0-24-10.7-24-24s10.7-24 24-24h72c61.9 0 112-50.1 112-112s-50.1-112-112-112H344c-13.3 0-24-10.7-24-24s10.7-24 24-24h72c88.4 0 160 71.6 160 160zM184 232H392c13.3 0 24 10.7 24 24s-10.7 24-24 24H184c-13.3 0-24-10.7-24-24s10.7-24 24-24z"></path>
                      </svg>
                    </div>
                  </a>
                </div>}
              <div className="font-semibold text-primary dark:text-primary-light">
                {name}
              </div>
              <div className="flex items-center space-x-2 text-xs font-medium">
                <div className="flex items-center px-2 py-0.5 rounded-md bg-gray-100/50 dark:bg-white/5 text-gray-600 dark:text-gray-200 font-medium">
                  {type}
                </div>
                {required && <span className="px-2 py-0.5 rounded-md bg-red-100/50 dark:bg-red-400/10 text-red-600 dark:text-red-300 font-medium">
                    required
                  </span>}
                {defaultVal && <div className="flex items-center px-2 py-0.5 rounded-md bg-gray-100/50 dark:bg-white/5 text-gray-600 dark:text-gray-200 font-medium">
                    <span class="text-gray-400 dark:text-gray-500">default:</span>
                    {defaultVal}
                  </div>}
              </div>
            </div>
          </div>
        </div>
        <div className="mt-4 prose-sm prose-gray dark:prose-invert">
          {children}
        </div>
      </div>
    </div>;
};

Schedule package that contains classes for working with schedules.

***

## Variables

<Steps>
  <Step title="Constants" icon="pi">
    <Field id="const_ALL_DAYS" name="ALL_DAYS" type="list[indie.schedule.week_day]">
      List of `week_day`'s from `week_day.MONDAY` to `week_day.SUNDAY`.
    </Field>

    <Field id="const_WEEKEND" name="WEEKEND" type="list[indie.schedule.week_day]">
      List of `week_day`'s from `week_day.SATURDAY` to `week_day.SUNDAY`.
    </Field>

    <Field id="const_WORKDAYS" name="WORKDAYS" type="list[indie.schedule.week_day]">
      List of `week_day`'s from `week_day.MONDAY` to `week_day.FRIDAY`.
    </Field>
  </Step>
</Steps>

***

## Types

<Anchor id="class_Schedule" />

### `Schedule`

*type*

Data type that manages a collection of scheduling rules, allowing for specific times and exceptions to be defined.

<Steps>
  <Step title="Methods" icon="function">
    <Field id="method_Schedule_init" name="__init__" type="(rules, except_once, except_yearly, timezone) -> None">
      Class constructor (initializer for the data type).

      <Expandable title="parameters info">
        <Field name="rules" type="list[indie.schedule.ScheduleRule]" required>
          List of ScheduleRule instances that define the active scheduling rules.
        </Field>

        <Field name="except_once" type="list[datetime.datetime]" defaultVal="[]">
          List of dates that are excluded from the schedule only once.
        </Field>

        <Field name="except_yearly" type="list[datetime.datetime]" defaultVal="[]">
          List of dates that are excluded from the schedule every year.
        </Field>

        <Field name="timezone" type="str" defaultVal="&#x22;UTC&#x22;">
          Timezone for schedule.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_Schedule_is_empty" name="is_empty" type="() -> bool">
      Checks if the rules list in Schedule is empty. Returns `True` if list of rules is empty; otherwise, returns `False`.
    </Field>

    <Field id="method_Schedule_contains" name="__contains__" type="(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`.

      <Expandable title="parameters info">
        <Field name="t" type="float" required>
          Timestamp to check in defined schedule.
        </Field>
      </Expandable>
    </Field>

    <Field name="__contains__" type="(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`.

      <Expandable title="parameters info">
        <Field name="d" type="datetime.datetime" required>
          Datetime to check in defined schedule.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_Schedule_is_same_period" name="is_same_period" type="(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.

      <Expandable title="parameters info">
        <Field name="timestamp1" type="float" required>
          First timestamp to check.
        </Field>

        <Field name="timestamp2" type="float" required>
          Second timestamp to check.
        </Field>
      </Expandable>

      <Note>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.</Note>
    </Field>
  </Step>
</Steps>

<Info>See also: [`TradingSession`](/indie/Library-reference/package-indie#class_TradingSession) [`ScheduleRule`](/indie/Library-reference/package-indie-schedule#class_ScheduleRule)</Info>

***

<Anchor id="class_ScheduleRule" />

### `ScheduleRule`

*type*

Data type to represent a rule for a schedule, specifying the start and end times, along with the weekdays when the rule is active.

<Steps>
  <Step title="Methods" icon="function">
    <Field id="method_ScheduleRule_init" name="__init__" type="(start, end, days) -> None">
      Class constructor (initializer for the data type).

      <Expandable title="parameters info">
        <Field name="start" type="datetime.time" required>
          Start time of the rule.
        </Field>

        <Field name="end" type="datetime.time" required>
          End time of the rule.
        </Field>

        <Field name="days" type="list[indie.schedule.week_day]" defaultVal="indie.schedule.ALL_DAYS">
          List of weekdays when the rule is active.
        </Field>
      </Expandable>
    </Field>
  </Step>
</Steps>

```py Example theme={null}
# 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)
```

<Note>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.</Note>
<Info>See also: [`Schedule`](/indie/Library-reference/package-indie-schedule#class_Schedule) [`TradingSession`](/indie/Library-reference/package-indie#class_TradingSession)</Info>

***

## Enums

<Anchor id="enum_week_day" />

### `week_day`

*enum*

Enum-like class with constants for days of week.

<Steps>
  <Step title="Static fields" icon="cubes">
    <Field id="const_week_day_MONDAY" name="MONDAY" type="indie.schedule.week_day">
      Built-in constants that represent days of week.
    </Field>

    <Field id="const_week_day_TUESDAY" name="TUESDAY" type="indie.schedule.week_day">
      Built-in constants that represent days of week.
    </Field>

    <Field id="const_week_day_WEDNESDAY" name="WEDNESDAY" type="indie.schedule.week_day">
      Built-in constants that represent days of week.
    </Field>

    <Field id="const_week_day_THURSDAY" name="THURSDAY" type="indie.schedule.week_day">
      Built-in constants that represent days of week.
    </Field>

    <Field id="const_week_day_FRIDAY" name="FRIDAY" type="indie.schedule.week_day">
      Built-in constants that represent days of week.
    </Field>

    <Field id="const_week_day_SATURDAY" name="SATURDAY" type="indie.schedule.week_day">
      Built-in constants that represent days of week.
    </Field>

    <Field id="const_week_day_SUNDAY" name="SUNDAY" type="indie.schedule.week_day">
      Built-in constants that represent days of week.
    </Field>
  </Step>
</Steps>

***
