Skip to content
Matching a Field
step 1/5

Reading — step 1 of 5

Read

~1 min readCron Expression Parser

Matching a Field Against a Current Time Component

Once you've expanded a field to its set of allowed values, matching is just membership checking. For a datetime, you check each component against the respective expanded set:

fields = parse("*/15 9-17 * * 1-5")
# => minute={0,15,30,45}, hour={9..17}, dom=*, month=*, dow={1..5}

matches(now, fields) := \
    now.minute in fields.minute and
    now.hour   in fields.hour   and
    now.day    in fields.dom    and
    now.month  in fields.month  and
    now.weekday in fields.dow

The subtle case: when both day-of-month and day-of-week are restricted (neither is *), POSIX cron treats them as OR, not AND.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…