Reading — step 1 of 5
Read
~1 min readCron Expression Parser
Tokenizing a Cron Expression
A standard cron expression is 5 whitespace-separated fields:
*/15 9-17 * * 1-5 # Every 15 min, 9am-5pm, weekdays
0 0 1 * * # Midnight on the 1st of every month
30 14 * * 0 # 2:30pm on Sundays
| Field | Meaning | Range |
|---|---|---|
| 1 | minute | 0-59 |
| 2 | hour | 0-23 |
| 3 | day-of-month | 1-31 |
| 4 | month | 1-12 (or JAN-DEC) |
| 5 | day-of-week | 0-6 (or SUN-SAT, 0=Sunday) |
Tokenization is the first step. You split on whitespace, validate the field count,
and map textual aliases (JAN -> 1, MON -> 1, etc.). Special values like @hourly,
@daily, @weekly should expand to their canonical 5-field form before tokenizing.
Your job: read a cron string and output the 5 normalized field strings, one per line.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…