Schedule Cron Jobs for Market Hours (09:30–16:00 Mon–Fri in America/New_York)
Why a single cron expression cannot start at 09:30 and end at 16:00 without skipping :00–:29 in later hours, and how to split half-hour trading windows cleanly.
Incident Symptom & Protocol Root Cause
Production Failure Symptom
Trying to run an intraday equity feed or SLA check every 5 minutes during NYSE market hours (09:30 to 16:00 ET, Monday–Friday) using 30-59/5 9-16 * * 1-5 skips the first 30 minutes of EVERY hour from 10:00 through 16:25!
Scheduler Parser & Clock Mechanics
A single cron expression computes the Cartesian product of its Minute set and its Hour set: restricting minutes to 30-59 applies to ALL hours in 9-16, not just hour 9! Any window starting or ending on a half-hour (or quarter-hour) requires splitting the opening partial hour, full middle hours, and closing tick into separate schedule entries.
Broken vs Verified Configuration
# BROKEN: Only runs at :30..:55 of EVERY hour (misses 10:00-10:25, 11:00-11:25...
# and keeps firing until 16:55 after the 16:00 closing bell!)
30-59/5 9-16 * * 1-5 /opt/trading/poll-quotes.sh# GitHub Actions / Multi-rule Cron in America/New_York:
# Rule 1: Opening half-hour (09:30, 09:35, 09:40, 09:45, 09:50, 09:55)
30-59/5 9 * * 1-5 /opt/trading/poll-quotes.sh
# Rule 2: Full trading hours 10:00 through 15:55 (every 5 minutes)
*/5 10-15 * * 1-5 /opt/trading/poll-quotes.sh
# Rule 3: Exact 16:00 closing bell snapshot
0 16 * * 1-5 /opt/trading/poll-quotes.shOperational Deep Dive
Every cron rule evaluates field predicates independently: matches(t) = inMinutes(t.min) AND inHours(t.hour) AND inMonth(t.mon) AND inDay(t). Because there is no conditional coupling between minute and hour inside a single line, rectangular subsets of the (hour, minute) grid fit in one expression (such as 09:00–16:59), whereas ragged start/end boundaries like 09:30–16:00 must be partitioned into disjoint rectangles.
Partitioning 09:30–16:00 into three non-overlapping lines (30-59/5 9, */5 10-15, and 0 16) guarantees zero duplicate triggers at hour boundaries and zero blind spots between 10:00 and 10:29. Always anchor all three rules to timezone: America/New_York (not a fixed UTC offset!) because US Daylight Saving Time shifts relative to UTC on different Sundays than London or Frankfurt—hardcoding 14:30 UTC breaks US market open for three weeks every spring/autumn relative to European servers and for the entire summer unless manually edited!
If your platform enforces a single cron string per job resource (for example a single Kubernetes CronJob object where splitting into three CronJobs would defeat concurrencyPolicy: Forbid), run a single superset schedule */5 9-16 * * 1-5 in America/New_York and start the script with an immediate wall-clock time-of-day guard: hm=$(TZ=America/New_York date +%H%M); [ "$hm" -ge 0930 ] && [ "$hm" -le 1600 ] || exit 0.
Half-Hour Business Window Decomposition Patterns
| Engine / Case | Runtime Behavior | Production Remediation |
|---|---|---|
| 09:30–09:59 opening window | Minutes restricted to 30-59 for hour 9 only. | 30-59/5 9 * * 1-5 (fires 09:30, 09:35 .. 09:55). |
| 10:00–15:59 core trading hours | All 60 minutes active across hours 10, 11, 12, 13, 14, 15. | */5 10-15 * * 1-5 (fires 10:00 .. 15:55). |
| 16:00 exact market close | Single closing tick without running 16:05–16:55. | 0 16 * * 1-5 (fires once at 16:00:00). |
| Single K8s CronJob preserving Forbid lock | Multiple K8s CronJobs cannot share concurrencyPolicy: Forbid. | Use */5 9-16 * * 1-5 with timeZone: America/New_York + [ "$(date +%H%M)" -ge 0930 ] guard. |
Edge Cases & Engineering FAQs
What about NYSE early-close days (13:00 ET on July 3, Black Friday, Christmas Eve)?
Cron expressions have no market holiday or early-close calendar. Query an exchange calendar library (such as exchange_calendars or Polygon/IEX market status API) at startup and exit 0 cleanly when the market is closed.
Does [ "$(date +%H%M)" -ge 0930 ] trigger an octal error in /bin/sh because of leading 0 in 0930?
Great catch! POSIX test [ '0930' -ge '0930' ] parses base-10 decimal strings safely in dash, bash, and BusyBox test ([ ... ]), UNLIKE arithmetic expansion $(( 0930 )) which treats leading zero as octal! To be 100% immune in every shell context, compare fixed-width 4-digit HHMM strings lexicographically in awk or strip leading zero.
How do I write 09:30–16:00 in AWS EventBridge Scheduler?
Create three aws_scheduler_schedule resources with schedule_expression_timezone = 'America/New_York': cron(30/5 9 ? * MON-FRI *), cron(0/5 10-15 ? * MON-FRI *), and cron(0 16 ? * MON-FRI *).
Runtime Dead-Man's-Switch Verification
Dead-man's-switch heartbeat checks that page on-call when a scheduled job skips a DST gap, stalls on a lock, or exits non-zero.