payroll.overtime
Pay for the time worked in a period split into multiplier bands: basic, time and a half after 40 hours, double time.
1.0.0 (not the latest) · published 2026-10-03 by charlie · Anterra
Pinned by 11 tests, run in TypeScript, Python and Rust.
Not professional advice. This capability calculates payroll figures from published rules. It is a software component for developers, not tax or legal advice. Rules change and every rate here has an effective date. Check that the dates cover your case. Verify results against the official sources listed in its README, and have a payroll specialist review how you use it, before anyone relies on the output. Provided “as is” under its licence, without warranty.
What it does
Splits the minutes worked in a period across multiplier bands and prices each band: with bands `[{0, 10000}, {2400, 15000}]` the first 40 hours are paid at the basic rate and every minute after that at time and a half.
- Time is in whole **minutes**, so 37 hours 20 minutes is 2240, and no fractional hours ever reach the arithmetic. - Each line is `hourlyRate x minutes x multiplier / 60`, rounded half-up to the penny once per line (math.round-div), and the total is the sum of the lines, so the payslip adds up to what it shows. - Bands must start at 0 and ascend strictly; a band list that leaves the first minutes unpriced or overlaps itself is an error rather than a guess. - Only bands the worker reached produce a line.
For example
overtimePay(2,700, £12.71, bands ×2)→ lines ×2, total £603.73 45 hours with time and a half after 40: the half penny rounds upovertimePay(2,400, £12.71, bands ×2)→ lines ×1, total £508.40 exactly 40 hours never reaches the overtime bandovertimePay(3,300, £10.00, bands ×3)→ lines ×3, total £650.00 three bands: basic, time and a half, double time
The function
The same function in TypeScript, Python and Rust, pinned by the same tests. Pick your language; the choice follows you around the registry.
export function overtimePay(minutesWorked: number, hourlyRate: Money, bands: readonly OvertimeBand[]): OvertimePay
| minutesWorked | int | total time worked in the period, in minutes |
| hourlyRate | Money | basic hourly rate |
| bands | OvertimeBand[] | ascending thresholds; the first must start at 0 minutes |
| returns | OvertimePay |
The types it declares, generated into your project
/** From this many minutes worked, every further minute is paid at this multiplier. */
export interface OvertimeBand {
/** 2400 = after 40 hours */
readonly fromMinutes: number;
/** 10000 = basic rate, 15000 = time and a half */
readonly multiplierBasisPoints: number;
}
/** One payslip line. */
export interface OvertimeLine {
readonly minutes: number;
readonly multiplierBasisPoints: number;
readonly pay: Money;
}
export interface OvertimePay {
/** one per band actually reached, in band order */
readonly lines: readonly OvertimeLine[];
/** the sum of the lines */
readonly total: Money;
}
Your code names it in one line, in the file that uses it
import { overtimePay } from "#fune/payroll.overtime@^1";
Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.
import { roundDiv } from "./math_round_div.ts"; ← from math.round-div ^1.0.0 · built alongside by fune
import { type Money, money } from "./money_amount.ts"; ← from money.amount ^1.0.0 · built alongside by fune
import { sumMoney } from "./money_sum.ts"; ← from money.sum ^1.0.0 · built alongside by fune
import { type OvertimeBand, type OvertimeLine, type OvertimePay } from "./payroll_overtime_types.ts";
/** Price the minutes worked band by band, rounding once per payslip line. */
export function overtimePay(minutesWorked: number, hourlyRate: Money, bands: readonly OvertimeBand[]): OvertimePay {
if (!Number.isInteger(minutesWorked) || minutesWorked < 0) {
throw new RangeError(`minutesWorked must be a whole number of minutes, not negative, received ${minutesWorked}`);
}
if (bands.length === 0) throw new RangeError("overtime needs at least one band");
if (bands[0].fromMinutes !== 0) throw new RangeError("the first band must start at 0 minutes");
for (let i = 1; i < bands.length; i++) {
if (bands[i].fromMinutes <= bands[i - 1].fromMinutes) {
throw new RangeError("bands must be in strictly ascending order of fromMinutes");
}
}
const lines: OvertimeLine[] = [];
for (let i = 0; i < bands.length; i++) {
const from = bands[i].fromMinutes;
const to = i + 1 < bands.length ? Math.min(bands[i + 1].fromMinutes, minutesWorked) : minutesWorked;
const minutes = to - from;
if (minutes <= 0) break;
const multiplier = bands[i].multiplierBasisPoints;
if (!Number.isInteger(multiplier) || multiplier < 0) {
throw new RangeError(`multiplierBasisPoints must be a whole number, not negative, received ${multiplier}`);
}
const pay = money(roundDiv(hourlyRate.minor * minutes * multiplier, 60 * 10000, "half-up"), hourlyRate.currency);
lines.push({ minutes, multiplierBasisPoints: multiplier, pay });
}
return { lines, total: sumMoney(lines.map((l) => l.pay), hourlyRate.currency) };
}Install
fune build
With that line in your source, in a TypeScript project (language typescript in fune.project), fune build resolves it and its 3 dependencies, pins them in fune.lock, downloads only the TypeScript package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. Or pin a range in fune.project and build in one step:
fune add payroll.overtime
The manifest, vectors and README with only the TypeScript implementation. Install it without the registry with fune add ./payroll.overtime-1.0.0-typescript.fune, or fetch it from a terminal with fune pull payroll.overtime@1.0.0:typescript.
The whole function, every language, is one file too: payroll.overtime-1.0.0.fune, 14,951 bytes, sha256 a3757217ab546dc163afe8a24fdfabba76475e58753b695aa9809c730d45d41a. It installs into a project of any language.
Customise it in your app
The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.
before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.
// fune: before payroll.overtime
after — your function gets the result and the arguments, and returns the final result.
// fune: after payroll.overtime
replace — inside this capability’s code only, calls to a dependency go to your function, with the same signature. Other capabilities that use it are unaffected; write in * to replace it everywhere.
// fune: replace math.round-div in payroll.overtime
// fune: replace money.amount in payroll.overtime
// fune: replace money.sum in payroll.overtime
step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show payroll.overtime --steps.
// fune: step payroll.overtime after <n|label>
Tests
A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript, Python and Rust, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json.
| Case | Arguments | Expected | |
|---|---|---|---|
| 45 hours with time and a half after 40: the half penny rounds up | 2,700, £12.71, bands ×2 | → | lines ×2, total £603.73 |
| exactly 40 hours never reaches the overtime band | 2,400, £12.71, bands ×2 | → | lines ×1, total £508.40 |
| three bands: basic, time and a half, double time | 3,300, £10.00, bands ×3 | → | lines ×3, total £650.00 |
| 37 hours 20 minutes at one rate | 2,240, £12.71, bands ×1 | → | lines ×1, total £474.51 |
| no time worked | 0, £12.71, bands ×1 | → | lines , total £0.00 |
| one minute into the overtime band | 2,401, £12.00, bands ×2 | → | lines ×2, total £480.30 |
| bands that do not start at zero are an error | 2,700, £12.71, bands ×1 | → | error: must start at 0 minutes |
| bands out of order are an error | 2,700, £12.71, bands ×3 | → | error: strictly ascending |
| no bands is an error | 2,700, £12.71, | → | error: at least one band |
| negative minutes are an error | -60, £12.71, bands ×1 | → | error: not negative |
Show the other 1 test
| Case | Arguments | Expected | |
|---|---|---|---|
| fractional minutes are an error | 90.5, £12.71, bands ×1 | → | error: whole number of minutes |
More from the author
Overtime rules come from contracts, not statute, so the bands are the caller's. Premiums by day (Sunday double time) are separate calls with that day's minutes. Check the result with payroll.minimum-wage-check: overtime premiums above the basic rate do not count towards the minimum wage.
Files
| Path | Bytes |
|---|---|
| README.md | 1,047 |
| impl/python.py | 1,868 |
| impl/rust.rs | 3,074 |
| impl/typescript.ts | 1,805 |
| vectors.json | 3,655 |