keep.is_business_hours#
Location: keep/functions/__init__.py
keep.is_business_hours is a built-in Keep function that returns True if a given time falls within configured business hours on a business day. It is most commonly used in workflow if conditions to gate action execution — for example, suppressing off-hours notifications or routing alerts differently depending on the time of day.
Parameters#
| Parameter | Type | Default | Notes |
|---|---|---|---|
time_to_check | str | datetime | None | None (current UTC time) | ISO 8601 strings accepted; invalid strings return False |
start_hour | int | 8 | 24-hour format; must be 0–23 |
end_hour | int | 20 | 24-hour format; must be 0–23 |
business_days | tuple[int] | (0,1,2,3,4) | Mon=0 … Sun=6 |
timezone | str | "UTC" | Any pytz timezone name |
The function raises ValueError for out-of-range hours (outside 0–23), invalid day numbers (outside 0–6), non-iterable business_days, or unrecognized timezone strings.
The boundary condition is inclusive start, exclusive end: start_hour <= hour < end_hour. So end_hour=20 means 20:00 (8 PM) is not considered business hours.
Known Limitation: No Overnight Window Support#
The hour check is a simple start_hour <= hour < end_hour comparison. If start_hour > end_hour (e.g., 22–06 for a night shift), the condition will always be False — the function does not wrap around midnight.
Workaround: split the window into two separate is_business_hours calls (one for the pre-midnight segment and one for the post-midnight segment) and OR them together in the workflow condition.
Usage in Workflows#
is_business_hours is called via the keep.<function>() syntax inside workflow YAML, either in if conditions on actions or embedded in template strings processed by the IOHandler.
Minimal — check current time in a specific timezone:
actions:
- name: dismiss-alert
if: "keep.is_business_hours(timezone='America/New_York')"
With full keyword arguments:
if: "keep.is_business_hours(time_to_check='{{ steps.start_time }}', start_hour=9, end_hour=17, business_days=(0,1,2,3,4), timezone='Europe/London')"
With positional arguments (IOHandler):
keep.is_business_hours('2024-03-20T10:00:00+02:00', 8, 20, (0, 1, 2, 3, 6), 'Asia/Jerusalem')
business_days can be used to model non-standard work weeks. For example, (0, 1, 2, 3, 6) covers Mon–Thu + Sun (common in Middle Eastern locales).
Related Files#
| File | Purpose |
|---|---|
keep/functions/__init__.py | Implementation |
tests/test_functions.py | Unit tests (default hours, custom hours, timezones, invalid inputs, edge cases) |
tests/test_iohandler.py | Integration tests for positional/keyword call styles via IOHandler |
examples/workflows/businesshours.yml | Minimal real-world workflow example |
docs/workflows/examples/buisnesshours.mdx | Documentation example |
docs/workflows/syntax/functions.mdx | Function reference docs |