Leave requests checked before approval
The rule
A leave request is checked against the company’s rules before anyone approves it:
- it may not ask for more paid time off than the person has (counting the requests already made);
- it may not fall in a blackout period (inventory week, the holiday rush);
- it should be asked for so many days ahead; one asked later is flagged for the approver, who may still say yes;
- a long request goes to someone more senior.
A refused request cannot be approved: its approval does not pass however it is decided, and it pays nothing.
Who uses it
Almost every employer with paid time off: retailers with holiday-season blackouts, manufacturers with shutdown and inventory weeks, offices with a two-week notice rule for vacation, and anyone who does not let balances go negative.
How the recipe does it
Configuration only: a package (package.toml) of one layer, with pay
periods of three weeks, balances kept from September 28, 2026, and four
standard steps in the leave stage, one for each rule.
[[layer]]id = "leave"settings = { pay_periods = { every_days = 21, from = "2026-10-05" }, accruals = { since = "2026-09-28" } }[[layer.step]]id = "balance"uses = "standard/leave_balance"params = { balance = { pto = "pto" } }[[layer.step]]id = "blackout"uses = "standard/leave_blackout"params = { blackout = { ranges = [{ from = "2026-10-12", to = "2026-10-16" }] } }[[layer.step]]id = "notice"uses = "standard/leave_notice"params = { days = 14 }[[layer.step]]id = "route"uses = "standard/leave_route"params = { routes = [{ stage = "manager", to = "role:director", over = "24h" }] }A business that wants only some of the rules lists only those steps.
The leave stage runs before a ledger’s other stages, once for each
standing request with a day near its period. Its step sees ctx.request
(id, category, days with each date and time, first, last,
time, recorded, by, comment, state, stage) and asks the engine
what it needs: ctx:period(spec, at) (a span or set of time, such as the
year a date is in), ctx:requests(period) (the person’s other requests
with a day in it), ctx:balance(accrual category) (the balance at the
start of the pay period of the request’s first day, ctx.balance_on),
ctx:balance_after(accrual category) (what the request would leave, the
requests recorded before it counted first) and
ctx:balance_changes(...). It calls ctx:refuse(why), ctx:exception(kind, 0, detail) (about the request, at its first day’s start) and
ctx:route(stage, approver, why). A refused request is refused
wherever it shows (its ledger, the calendar steps read, the leave API, the
leave.decided event); a routed stage names its approver (and the
leave.requested event does).
What your setup needs
Set up before you adopt the recipe; the recipe’s steps read them by name, and adopting it is refused, with a list of what is missing, until they exist.
- A balance called
pto: an accrual category. The recipe earns into it, takes from it or reads it.
The scenarios show each as it was set up for them.
Parameters
| Step | Parameter | Meaning |
|---|---|---|
leave_balance | balance | Each leave category and the accrual category it draws on: { pto = "pto" }. A request that would leave the balance below floor is refused. |
leave_balance | floor | The lowest a request may leave the balance (default 0h; -40h lets it go negative, see balance_below_once_a_year). |
leave_blackout | blackout | A period: a request with a day in it is refused ({ ranges = [{ from, to }] }, dates, weekdays, any combination). |
leave_notice | days | A request recorded fewer days before its first day is flagged leave_short_notice. |
leave_route | routes | Each { stage, to, over }: stage goes to to for a request of more than over (or every request, without it). |
What the scenarios show
no-more-than-the-balance: with 16 hours, an 8-hour request is approved and paid; a 16-hour one asked for after it is refused and pays nothing.a-rejected-request-draws-nothing: with 16 hours, a 16-hour request rejected draws nothing, so a 16-hour one asked for after it fits.blackout-notice-and-routing: a request touching inventory week is refused; one asked three days ahead waits for the manager, flagged; a four-day request waits for the director.
Legal note
This is a common way companies check leave requests; check the rules where you operate. Some leave (sick leave, family and medical leave, jury duty) cannot be refused for notice or blackouts where the law protects it.
Get the recipe
The recipe’s package and its scenarios are in the example packages repository: attendance/leave_rules. Test it, or your own copy of it, with hourctl attend test, and publish it with hourctl attend pkg publish.
The policy package
The package’s layers, with the standard steps each one runs and their settings:
name = "leave_rules"version = "1.0.0"description = "No more leave than the balance, none in a blackout week, short notice flagged, and long requests sent to a director."
# What the tenant must have set up for the recipe: the steps read these by name.[needs]accrual_categories = ["pto"]
# Pay periods of three weeks; balances kept from September 28, 2026. Four# rules, each a step of its own: a leave request is refused for leaving# the balance of its accrual category below nothing, or for a day of# inventory week; it is flagged when asked less than 14 days ahead; and# one of more than 24 hours goes to the director at the manager's stage.[[layer]]id = "leave"settings = { pay_periods = { every_days = 21, from = "2026-10-05" }, accruals = { since = "2026-09-28" } }[[layer.step]]id = "balance"uses = "standard/leave_balance"params = { balance = { pto = "pto" } }[[layer.step]]id = "blackout"uses = "standard/leave_blackout"params = { blackout = { ranges = [{ from = "2026-10-12", to = "2026-10-16" }] } }[[layer.step]]id = "notice"uses = "standard/leave_notice"params = { days = 14 }[[layer.step]]id = "route"uses = "standard/leave_route"params = { routes = [{ stage = "manager", to = "role:director", over = "24h" }] }Scenarios
Each scenario gives a person’s punches and setup and the timecard they must produce, worked out with this package adopted (the format).
16 hours of paid time off at the start of the week. Monday and Tuesday's 16 hours, asked for first, were rejected: they draw nothing, so Wednesday and Thursday's 16 hours, asked for after them, fit
description = "16 hours of paid time off at the start of the week. Monday and Tuesday's 16 hours, asked for first, were rejected: they draw nothing, so Wednesday and Thursday's 16 hours, asked for after them, fit"
[policy]zone = "America/Chicago"
[[category]]id = "pto"worked = false
[[accrual_category]]id = "pto"uses = ["pto"]
[[accrual_adjustment]]category = "pto"workday = "2026-10-01"amount = "16h"
[[leave]]id = "v1"category = "pto"days = { "2026-10-05" = "8h", "2026-10-06" = "8h" }recorded = "2026-09-20 09:00"
[[approval]]subject = "leave:v1:2026-10-05"stage = "approval"decision = "reject"recorded = "2026-09-20 09:00"
[[leave]]id = "v2"category = "pto"days = { "2026-10-07" = "8h", "2026-10-08" = "8h" }recorded = "2026-09-21 09:00"
[[approval]]subject = "leave:v2:2026-10-07"stage = "approval"decision = "approve"recorded = "2026-09-21 09:00"
[expect.period]day = "2026-10-05"allocations = ["2026-10-07 untimed pto 8.00", "2026-10-08 untimed pto 8.00"]leave = ["v1 rejected approval", "v2 approved"]balances = { pto = "0s" }Vacation is approved by the manager. Inventory week (October 12 to 16) is a blackout: a request with a day in it is refused. A request asked for three days ahead, under the two weeks' notice, is flagged for the manager to see, not refused. A request of more than three days goes to the director instead
description = "Vacation is approved by the manager. Inventory week (October 12 to 16) is a blackout: a request with a day in it is refused. A request asked for three days ahead, under the two weeks' notice, is flagged for the manager to see, not refused. A request of more than three days goes to the director instead"
[policy]zone = "America/Chicago"
[[category]]id = "vacation"worked = false
[[approval_rule]]subject = "leave"stages = ["manager"]
[[leave]]id = "v1"category = "vacation"days = { "2026-10-09" = "8h", "2026-10-12" = "8h" }recorded = "2026-09-01 09:00"
[[leave]]id = "v2"category = "vacation"days = { "2026-10-07" = "8h" }recorded = "2026-10-04 09:00"
[[leave]]id = "v3"category = "vacation"days = { "2026-10-19" = "8h", "2026-10-20" = "8h", "2026-10-21" = "8h", "2026-10-22" = "8h" }recorded = "2026-09-01 09:00"
[expect.period]day = "2026-10-05"leave = [ "v1 refused: 2026-10-12 is in a blackout, 2026-10-12 to 2026-10-16", "v3 pending manager to role:director", "v2 pending manager",]exceptions = [{ kind = "leave_short_notice", at = "2026-10-07 00:00", detail = "asked less than 14 days ahead" }]16 hours of paid time off at the start of the week. Monday's 8-hour request fits; Wednesday and Thursday's 16 hours, asked for after it, would take the balance below nothing: refused, so its approval cannot pass and it pays nothing. A request recorded first is counted first
description = "16 hours of paid time off at the start of the week. Monday's 8-hour request fits; Wednesday and Thursday's 16 hours, asked for after it, would take the balance below nothing: refused, so its approval cannot pass and it pays nothing. A request recorded first is counted first"
[policy]zone = "America/Chicago"
[[category]]id = "pto"worked = false
[[accrual_category]]id = "pto"uses = ["pto"]
[[accrual_adjustment]]category = "pto"workday = "2026-10-01"amount = "16h"
[[leave]]id = "v1"category = "pto"days = { "2026-10-05" = "8h" }recorded = "2026-09-20 09:00"
[[approval]]subject = "leave:v1:2026-10-05"stage = "approval"decision = "approve"recorded = "2026-09-20 09:00"
[[leave]]id = "v2"category = "pto"days = { "2026-10-07" = "8h", "2026-10-08" = "8h" }recorded = "2026-09-21 09:00"
[[approval]]subject = "leave:v2:2026-10-07"stage = "approval"decision = "approve"recorded = "2026-09-21 09:00"
[expect.period]day = "2026-10-05"allocations = ["2026-10-05 untimed pto 8.00"]leave = ["v1 approved", "v2 refused: it would leave the pto balance below 0h"]balances = { pto = "8h" }