Skip to content

Attribution by most hours

The rule

A shift from evening to morning crosses the start of a workday. One common rule gives it whole to the workday that holds more of its hours: a 22:00 to 08:00 shift has 2 hours before midnight and 8 after, so it is the morning’s day; a 16:00 to 02:00 shift has 8 before and 2 after, so it is the evening’s.

Who uses it

  • Employers whose roster, pay period or daily overtime follow where the bulk of a shift falls, without splitting it at midnight.

How the recipe does it

Configuration only: a package (package.toml) of one layer with the standard attribute_by_most_hours step, in the attribute stage.

[[layer]]
id = "most-hours-day"
[[layer.step]]
id = "attribute"
uses = "standard/attribute_by_most_hours"
params = { tie = "start" } # or "end", where two days hold the same

The step reads, for each segment, how much of its time falls in each workday it touches (day_times) and attributes it whole to the workday with most, by ctx:attribute(id, { workday = date }). Without this step a segment is in the workday of its start punch, as punched.

Parameters

ParameterMeaning
tieWhere two workdays hold the same time: "start" (default) or "end".
whyOptional words for the ledger’s stamp.

What the scenarios show

  • more-hours-after-midnight-is-the-next-day: 22:00 to 08:00, 2 hours and 8, is Tuesday’s.
  • more-hours-before-midnight-is-the-day-it-starts: 16:00 to 02:00, 8 and 2, is Monday’s.
  • a-tie-goes-to-the-day-the-tie-says: 18:00 to 06:00, 6 and 6: Monday’s by the default.
  • a-tie-with-the-end-day-goes-to-the-end: the same night with tie = "end" is Tuesday’s.

Get the recipe

The recipe’s package and its scenarios are in the example packages repository: attendance/attribute_by_most_hours. 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:

attribute_by_most_hours/package.toml
name = "attribute_by_most_hours"
version = "1.0.0"
description = "A shift across a workday's start belongs to the workday that holds most of its hours."
# The workday with most of a segment's time takes all of it; where two hold the same, `tie` says which.
[[layer]]
id = "most-hours-day"
[[layer.step]]
id = "attribute"
uses = "standard/attribute_by_most_hours"
params = { tie = "start" }

Scenarios

Each scenario gives a person’s punches and setup and the timecard they must produce, worked out with this package adopted (the format).

Monday 18:00 to Tuesday 06:00 has 6 hours in each: the default tie goes to the day it starts in, Monday; a company's layer that sets tie to end puts the same night on Tuesday,
scenarios/a-tie-goes-to-the-day-the-tie-says.toml
description = "Monday 18:00 to Tuesday 06:00 has 6 hours in each: the default tie goes to the day it starts in, Monday; a company's layer that sets tie to end puts the same night on Tuesday,"
punch = [
{ at = "2026-10-05 18:00", kind = "in" }, { at = "2026-10-06 06:00", kind = "out" },
]
[policy]
zone = "America/Chicago"
[expect]
week = "2026-10-05"
days = { "2026-10-05" = "12h" }
The same Monday 18:00 to Tuesday 06:00, 6 hours in each day, with a company's layer that sets tie to end: all 12 hours are Tuesday's
scenarios/a-tie-with-the-end-day-goes-to-the-end.toml
description = "The same Monday 18:00 to Tuesday 06:00, 6 hours in each day, with a company's layer that sets tie to end: all 12 hours are Tuesday's"
punch = [
{ at = "2026-10-05 18:00", kind = "in" }, { at = "2026-10-06 06:00", kind = "out" },
]
[policy]
zone = "America/Chicago"
[[layer]]
id = "tie-to-end"
[[layer.step]]
id = "attribute"
change = "params"
params = { tie = "end" }
[expect]
week = "2026-10-05"
days = { "2026-10-06" = "12h" }
Monday 22:00 to Tuesday 08:00 has 2 hours in Monday and 8 in Tuesday: all 10 hours are Tuesday's
scenarios/more-hours-after-midnight-is-the-next-day.toml
description = "Monday 22:00 to Tuesday 08:00 has 2 hours in Monday and 8 in Tuesday: all 10 hours are Tuesday's"
punch = [
{ at = "2026-10-05 22:00", kind = "in" }, { at = "2026-10-06 08:00", kind = "out" },
]
[policy]
zone = "America/Chicago"
[expect]
week = "2026-10-05"
days = { "2026-10-06" = "10h" }
Monday 16:00 to Tuesday 02:00 has 8 hours in Monday and 2 in Tuesday: all 10 hours are Monday's
scenarios/more-hours-before-midnight-is-the-day-it-starts.toml
description = "Monday 16:00 to Tuesday 02:00 has 8 hours in Monday and 2 in Tuesday: all 10 hours are Monday's"
punch = [
{ at = "2026-10-05 16:00", kind = "in" }, { at = "2026-10-06 02:00", kind = "out" },
]
[policy]
zone = "America/Chicago"
[expect]
week = "2026-10-05"
days = { "2026-10-05" = "10h" }