Functional Weave
Code in Python

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

  • overtime_pay(2,700, £12.71, bands ×2) → lines ×2, total £603.73 45 hours with time and a half after 40: the half penny rounds up
  • overtime_pay(2,400, £12.71, bands ×2) → lines ×1, total £508.40 exactly 40 hours never reaches the overtime band
  • overtime_pay(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.

def overtime_pay(minutes_worked: int, hourly_rate: Money, bands: Sequence[OvertimeBand]) -> OvertimePay
minutes_workedinttotal time worked in the period, in minutes
hourly_rateMoneybasic hourly rate
bandsOvertimeBand[]ascending thresholds; the first must start at 0 minutes
returnsOvertimePay

The types it declares, generated into your project

@dataclass(frozen=True)
class OvertimeBand:
    """From this many minutes worked, every further minute is paid at this multiplier."""

    #: 2400 = after 40 hours
    from_minutes: int
    #: 10000 = basic rate, 15000 = time and a half
    multiplier_basis_points: int

@dataclass(frozen=True)
class OvertimeLine:
    """One payslip line."""

    minutes: int
    multiplier_basis_points: int
    pay: Money

@dataclass(frozen=True)
class OvertimePay:
    #: one per band actually reached, in band order
    lines: List[OvertimeLine]
    #: the sum of the lines
    total: Money

Your code names it in one line, in the file that uses it

from fune.payroll.overtime import overtime_pay  # payroll.overtime@^1
impl/python.py · 32 lines · open · raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

from typing import List, Sequence

from .math_round_div import round_div  ← from math.round-div ^1.0.0 · built alongside by fune
from .money_amount import Money, money  ← from money.amount ^1.0.0 · built alongside by fune
from .money_sum import sum_money  ← from money.sum ^1.0.0 · built alongside by fune
from .payroll_overtime_types import OvertimeBand, OvertimeLine, OvertimePay


def overtime_pay(minutes_worked: int, hourly_rate: Money, bands: Sequence[OvertimeBand]) -> OvertimePay:
    """Price the minutes worked band by band, rounding once per payslip line."""
    if isinstance(minutes_worked, bool) or not isinstance(minutes_worked, int) or minutes_worked < 0:
        raise ValueError("minutesWorked must be a whole number of minutes, not negative, received %s" % (minutes_worked,))
    if len(bands) == 0:
        raise ValueError("overtime needs at least one band")
    if bands[0].from_minutes != 0:
        raise ValueError("the first band must start at 0 minutes")
    for i in range(1, len(bands)):
        if bands[i].from_minutes <= bands[i - 1].from_minutes:
            raise ValueError("bands must be in strictly ascending order of fromMinutes")
    lines: List[OvertimeLine] = []
    for i, band in enumerate(bands):
        start = band.from_minutes
        end = min(bands[i + 1].from_minutes, minutes_worked) if i + 1 < len(bands) else minutes_worked
        minutes = end - start
        if minutes <= 0:
            break
        multiplier = band.multiplier_basis_points
        if isinstance(multiplier, bool) or not isinstance(multiplier, int) or multiplier < 0:
            raise ValueError("multiplierBasisPoints must be a whole number, not negative, received %s" % (multiplier,))
        pay = money(round_div(hourly_rate.minor * minutes * multiplier, 60 * 10000, "half-up"), hourly_rate.currency)
        lines.append(OvertimeLine(minutes=minutes, multiplier_basis_points=multiplier, pay=pay))
    return OvertimePay(lines=lines, total=sum_money([l.pay for l in lines], hourly_rate.currency))

Install

fune build

With that line in your source, in a Python project (language python in fune.project), fune build resolves it and its 3 dependencies, pins them in fune.lock, downloads only the Python 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
Download for Python payroll.overtime-1.0.0-python.fune · 9,888 bytes sha256 fd46f016dcdd07b8f38b5d3a610a75de6970ddfb484f0695be751d5020f647e6

The manifest, vectors and README with only the Python implementation. Install it without the registry with fune add ./payroll.overtime-1.0.0-python.fune, or fetch it from a terminal with fune pull payroll.overtime@1.0.0:python.

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.

CaseArgumentsExpected
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
CaseArgumentsExpected
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

PathBytes
README.md1,047
impl/python.py1,868
impl/rust.rs3,074
impl/typescript.ts1,805
vectors.json3,655