Punches of unknown direction
The rule
Many clocks only record that someone badged, not whether they came or went. The engine then takes each punch as turning the person in or out, whichever they are not. That works until one punch is missing or extra: from then on every in is read as an out and every out as an in. Two common rules give such punches a direction instead:
- After a gap: a punch more than so many hours after the punch before is an in. Each shift starts from a known point, so a mistake never outlives the day.
- By the schedule: a punch nearer a scheduled shift’s start than its end is an in, nearer an end an out.
Who uses it
Employers with simple badge readers or biometric clocks without keys: small plants, construction sites, schools, kitchens.
How the recipe does it
Configuration only: a package (package.toml) of one layer running the
standard direction step, in the pair stage. A company deciding by the
schedule replaces the step in a layer of its own with
mode = "schedule".
[[layer]]id = "direction"[[layer.step]]id = "direction"uses = "standard/direction"params = { mode = "gap", gap = "10h" } # or mode = "schedule"The step reads each workday’s punches (ctx.punches, with ctx.before, the
punch before the workday’s first) and gives those of unknown direction one
with ctx:direction(id, kind, why); in schedule mode it reads the shifts of
the workday and the next (ctx:day). The engine pairs the punches as
directed and stamps the segments they start.
Parameters
| Parameter | Meaning |
|---|---|
mode | "gap" or "schedule". |
gap | (gap) How long after the punch before a punch is an in ("6h"); one sooner is left to turn the person in or out. |
What the scenarios show
a-new-shift-after-a-gap-is-an-in: with Monday’s out missed, Tuesday’s first punch, 24 hours on, is an in: Monday is flagged for a correction and the days after it pair correctly. Set the gap longer than the longest shift and shorter than the shortest rest between shifts.nearer-the-start-or-the-end: with the 08:00 punch forgotten, the 11:55 punch is an in, so the afternoon is counted, not lost.
Legal note
This is a common way companies read punches without a direction; check the rules where you operate. Whatever the clock records, the time actually worked is what is owed: an exception is a prompt to correct, not a reason not to pay.
Get the recipe
The recipe’s package and its scenarios are in the example packages repository: attendance/unknown_punch_direction. 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 = "unknown_punch_direction"version = "1.0.0"description = "On a clock without in and out keys, a punch after a long gap, or nearer a shift's start, is an in, so one stray or missing punch does not turn the rest around."
# A punch of unknown direction after 10 hours or more with no punch is an# in, starting a new shift; the punches between take turns.[[layer]]id = "direction"[[layer.step]]id = "direction"uses = "standard/direction"params = { mode = "gap", gap = "10h" }Scenarios
Each scenario gives a person’s punches and setup and the timecard they must produce, worked out with this package adopted (the format).
A clock with no in and out keys: every punch is of unknown direction, and each turns the person in or out. Monday's 16:00 punch is missed, which would turn the rest of the week around: Monday 08:00 to Tuesday 08:00 as one 24-hour shift, Tuesday's 16:00 an in, and so on. With the gap rule, a punch more than 10 hours after the one before is an in: Tuesday 08:00 starts a shift, Monday's in is left without its out (missing_out, for a correction), and Tuesday and Wednesday pair as they should
description = "A clock with no in and out keys: every punch is of unknown direction, and each turns the person in or out. Monday's 16:00 punch is missed, which would turn the rest of the week around: Monday 08:00 to Tuesday 08:00 as one 24-hour shift, Tuesday's 16:00 an in, and so on. With the gap rule, a punch more than 10 hours after the one before is an in: Tuesday 08:00 starts a shift, Monday's in is left without its out (missing_out, for a correction), and Tuesday and Wednesday pair as they should"
punch = [ { at = "2026-10-05 08:00" }, { at = "2026-10-06 08:00" }, { at = "2026-10-06 16:00" }, { at = "2026-10-07 08:00" }, { at = "2026-10-07 16:00" },]
[policy]zone = "America/Chicago"
[expect]week = "2026-10-05"days = { "2026-10-06" = "8h", "2026-10-07" = "8h" }segments = [ "work 2026-10-05 08:00-open", "work 2026-10-06 08:00-16:00", "work 2026-10-07 08:00-16:00",]exceptions = [{ kind = "missing_out", at = "2026-10-05 08:00" }]Scheduled 08:00 to 16:00, a clock with no keys: a punch nearer a shift's start is an in, nearer its end an out. Monday the 08:00 punch is forgotten: the 11:55 punch, nearer the start, is an in, so the day is 11:55 to 16:00 and not an out from nowhere. Tuesday's two punches pair as usual
description = "Scheduled 08:00 to 16:00, a clock with no keys: a punch nearer a shift's start is an in, nearer its end an out. Monday the 08:00 punch is forgotten: the 11:55 punch, nearer the start, is an in, so the day is 11:55 to 16:00 and not an out from nowhere. Tuesday's two punches pair as usual"
punch = [ { at = "2026-10-05 11:55" }, { at = "2026-10-05 16:00" }, { at = "2026-10-06 07:58" }, { at = "2026-10-06 16:03" },]
[policy]zone = "America/Chicago"
# A company that decides each punch by its schedule.[[layer]]id = "by-schedule"[[layer.step]]id = "direction"change = "replace"uses = "standard/direction"params = { mode = "schedule" }
[[shift_definition]]id = "days"start = "08:00"end = "16:00"days = ["monday", "tuesday"]
[expect]week = "2026-10-05"segments = ["work 2026-10-05 11:55-16:00", "work 2026-10-06 07:58-16:03"]