legal.time-billing Unreviewed
Fees from time entries: each rounded to 6-minute (or other) units and priced at the fee earner's hourly rate.
1.0.1 · published 2026-10-03 by charlie · Anterra
Pinned by 15 tests, run in TypeScript, Python and Rust.
Unreviewed. This capability’s implementations agree in every language and pass its published test vectors, which were worked out from the official sources cited. But no qualified solicitor has yet checked those vectors, or confirmed that the capability covers the cases it claims. Treat it as a draft. Do not use it for real people, money or decisions without your own expert review. Once a qualified reviewer signs off, this notice is replaced with their name, qualification and the date. Each new version needs fresh sign-off.
Not professional advice. This capability calculates legal figures from published rules. It is a software component for developers, not 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 solicitor review how you use it, before anyone relies on the output. Provided “as is” under its licence, without warranty.
What it does
The time charges for a bill: every time entry rounded to whole billing units and priced at its fee earner's hourly rate from a rate card.
**Units.** Law firms record and bill in units of 6 minutes (a tenth of an hour), and the usual engagement-letter term is that a part unit is charged as a whole one: a 20-minute call is 4 units, 24 minutes. The unit and the rounding are arguments (`unitMinutes`, `mode`), so 15-minute units or rounding to the nearest unit work too. The rounding is time.round-to-increment's, applied to **each entry**, never to the day's or the matter's total: seven 1-minute emails are seven units, not two. That is what "each item of work is recorded in units" means, and why totalling first gives a smaller, wrong bill.
For example
time_billing(entries ×4, rates ×3, 6, up)→ lines ×4, by fee earner ×3, units 18, billed minutes 108, total £467.00 a matter's time in 6-minute units, part units charged in fulltime_billing(entries ×4, rates ×3, 6, half-up)→ lines ×4, by fee earner ×3, units 15, billed minutes 90, total £375.00 the same time rounded to the nearest unittime_billing(entries ×7, rates ×3, 6, up)→ lines ×7, by fee earner ×1, units 7, billed minutes 42, total £154.00 seven 1-minute emails are seven units, not the two a rounded total gives
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.
pub fn time_billing(entries: &[TimeEntry], rates: &[FeeEarnerRate], unit_minutes: i64, mode: &str) -> TimeBill
| entries | TimeEntry[] | time recorded, in the order it should appear on the bill |
| rates | FeeEarnerRate[] | the rate card: one hourly rate per fee earner, all in one currency |
| unit_minutes | int | the billing unit: 6 for tenths of an hour, 15 for quarter hours |
| mode | RoundingMode | how a part unit is billed: up (the usual engagement-letter term), half-up, half-even or down |
| returns | TimeBill |
The types it declares, generated into your project
/// One piece of recorded time.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TimeEntry {
/// the fee earner's code, as the rate card has it
pub fee_earner: String,
/// time actually spent, 0 or more
pub minutes: i64,
}
/// One line of a rate card.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FeeEarnerRate {
pub fee_earner: String,
pub hourly_rate: Money,
}
/// One time entry, priced.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TimeBillLine {
pub fee_earner: String,
/// as recorded
pub minutes: i64,
/// rounded to whole units
pub billed_minutes: i64,
pub units: i64,
pub hourly_rate: Money,
/// billed minutes at the hourly rate, rounded half-up to the minor unit
pub fee: Money,
}
/// One fee earner's share of the bill.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FeeEarnerTotal {
pub fee_earner: String,
pub units: i64,
pub fee: Money,
}
/// The time charges for a bill.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TimeBill {
/// in entry order
pub lines: Vec<TimeBillLine>,
/// in order of first appearance in the entries
pub by_fee_earner: Vec<FeeEarnerTotal>,
pub units: i64,
pub billed_minutes: i64,
/// the sum of the line fees
pub total: Money,
}
Your code names it in one line, in the file that uses it
fune!(legal.time-billing@^1); // then call time_billing(…)
Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.
use super::funejson::Value; ← the fune runtime: the JSON value the test vectors use; fune build keeps it only where a signature takes one
use super::math_round_div::round_div; ← from math.round-div ^1.0.0 · built alongside by fune
use super::money_amount::{money, money_from_value, money_to_value, Money}; ← from money.amount ^1.0.0 · built alongside by fune
use super::time_round_to_increment::round_to_increment; ← from time.round-to-increment ^1.0.0 · built alongside by fune
/// Price time entries in whole billing units at each fee earner's hourly rate.
///
/// # Panics
/// Panics on an empty, duplicated, negative or mixed-currency rate card, an
/// entry with no rate, negative minutes or a unit below one.
pub fn time_billing(entries: &[TimeEntry], rates: &[FeeEarnerRate], unit_minutes: i64, mode: &str) -> TimeBill {
if rates.is_empty() {
panic!("rates must not be empty");
}
let currency = rates[0].hourly_rate.currency.clone();
let mut card: Vec<(&str, &Money)> = Vec::new();
for rate in rates {
if card.iter().any(|(code, _)| *code == rate.fee_earner) {
panic!("duplicate rate for fee earner \"{}\"", rate.fee_earner);
}
if rate.hourly_rate.currency != currency {
panic!("currency mismatch: {} and {}", currency, rate.hourly_rate.currency);
}
if rate.hourly_rate.minor < 0 {
panic!("hourly rates must not be negative, received {}", rate.hourly_rate.minor);
}
card.push((&rate.fee_earner, &rate.hourly_rate));
}
let mut lines: Vec<TimeBillLine> = Vec::new();
let mut totals: Vec<(String, i64, i64)> = Vec::new();
let mut units = 0;
let mut billed_minutes = 0;
let mut total = 0;
for entry in entries {
let hourly_rate = match card.iter().find(|(code, _)| *code == entry.fee_earner) {
Some((_, rate)) => (*rate).clone(),
None => panic!("no rate for fee earner \"{}\"", entry.fee_earner),
};
// Rounded per entry: seven 1-minute emails are seven units, not two.
let billed = round_to_increment(entry.minutes, unit_minutes, mode);
let line_units = billed / unit_minutes;
let fee = round_div(billed * hourly_rate.minor, 60, "half-up");
match totals.iter_mut().find(|t| t.0 == entry.fee_earner) {
Some(t) => {
t.1 += line_units;
t.2 += fee;
}
None => totals.push((entry.fee_earner.clone(), line_units, fee)),
}
lines.push(TimeBillLine {
fee_earner: entry.fee_earner.clone(),
minutes: entry.minutes,
billed_minutes: billed,
units: line_units,
hourly_rate,
fee: money(fee, ¤cy),
});
units += line_units;
billed_minutes += billed;
total += fee;
}
let by_fee_earner = totals
.into_iter()
.map(|(code, u, fee)| FeeEarnerTotal { fee_earner: code, units: u, fee: money(fee, ¤cy) })
.collect();
TimeBill { lines, by_fee_earner, units, billed_minutes, total: money(total, ¤cy) }
}
pub fn time_entry_from_value(v: &Value) -> TimeEntry {
TimeEntry { fee_earner: v.get("feeEarner").as_str().to_string(), minutes: v.get("minutes").as_i64() }
}
pub fn fee_earner_rate_from_value(v: &Value) -> FeeEarnerRate {
FeeEarnerRate { fee_earner: v.get("feeEarner").as_str().to_string(), hourly_rate: money_from_value(v.get("hourlyRate")) }
}
pub fn time_bill_to_value(b: &TimeBill) -> Value {
Value::obj(vec![
(
"lines",
Value::Arr(
b.lines
.iter()
.map(|l| {
Value::obj(vec![
("feeEarner", Value::str(&l.fee_earner)),
("minutes", Value::Int(l.minutes)),
("billedMinutes", Value::Int(l.billed_minutes)),
("units", Value::Int(l.units)),
("hourlyRate", money_to_value(&l.hourly_rate)),
("fee", money_to_value(&l.fee)),
])
})
.collect(),
),
),
(
"byFeeEarner",
Value::Arr(
b.by_fee_earner
.iter()
.map(|t| {
Value::obj(vec![
("feeEarner", Value::str(&t.fee_earner)),
("units", Value::Int(t.units)),
("fee", money_to_value(&t.fee)),
])
})
.collect(),
),
),
("units", Value::Int(b.units)),
("billedMinutes", Value::Int(b.billed_minutes)),
("total", money_to_value(&b.total)),
])
}
pub fn fune_vector(args: &[Value]) -> Value {
let entries: Vec<TimeEntry> = args[0].as_arr().iter().map(time_entry_from_value).collect();
let rates: Vec<FeeEarnerRate> = args[1].as_arr().iter().map(fee_earner_rate_from_value).collect();
time_bill_to_value(&time_billing(&entries, &rates, args[2].as_i64(), args[3].as_str()))
}Install
fune build
With that line in your source, in a Rust project (language rust in fune.project), fune build resolves it and its 3 dependencies, pins them in fune.lock, downloads only the Rust 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. A crate’s build.rs runs it before every compile. Or pin a range in fune.project and build in one step:
fune add legal.time-billing
The manifest, vectors and README with only the Rust implementation. Install it without the registry with fune add ./legal.time-billing-1.0.1-rust.fune, or fetch it from a terminal with fune pull legal.time-billing@1.0.1:rust.
The whole function, every language, is one file too: legal.time-billing-1.0.1.fune, 36,003 bytes, sha256 6b5652aae439ee26b499cf65290280d902f76bdb479118c9ae9ce73d33fa78ee. 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 legal.time-billing
after — your function gets the result and the arguments, and returns the final result.
// fune: after legal.time-billing
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 legal.time-billing
// fune: replace money.amount in legal.time-billing
// fune: replace time.round-to-increment in legal.time-billing
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 legal.time-billing --steps.
// fune: step legal.time-billing 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 | |
|---|---|---|---|
| a matter's time in 6-minute units, part units charged in full | entries ×4, rates ×3, 6, up | → | lines ×4, by fee earner ×3, units 18, billed minutes 108, total £467.00 |
| the same time rounded to the nearest unit | entries ×4, rates ×3, 6, half-up | → | lines ×4, by fee earner ×3, units 15, billed minutes 90, total £375.00 |
| seven 1-minute emails are seven units, not the two a rounded total gives | entries ×7, rates ×3, 6, up | → | lines ×7, by fee earner ×1, units 7, billed minutes 42, total £154.00 |
| quarter-hour units | entries ×2, rates ×3, 15, up | → | lines ×2, by fee earner ×1, units 5, billed minutes 75, total £437.50 |
| a unit at an odd hourly rate rounds half-up to the penny: 177.77 an hour is 17.78 a unit | entries ×2, rates ×1, 6, up | → | lines ×2, by fee earner ×1, units 2, billed minutes 12, total £35.56 |
| a zero-minute entry is kept as a nil line | entries ×1, rates ×3, 6, up | → | lines ×1, by fee earner ×1, units 0, billed minutes 0, total £0.00 |
| no entries bill nothing, in the rate card's currency | , rates ×1, 6, up | → | lines , by fee earner , units 0, billed minutes 0, total €0.00 |
| a fee earner's summary follows their first entry | entries ×3, rates ×3, 6, up | → | lines ×3, by fee earner ×2, units 4, billed minutes 24, total £80.00 |
| an entry whose fee earner has no rate is an error | entries ×1, rates ×3, 6, up | → | error: no rate for fee earner "XYZ" |
| an empty rate card is an error | , , 6, up | → | error: rates must not be empty |
Show the other 5 tests
| Case | Arguments | Expected | |
|---|---|---|---|
| a fee earner twice on the rate card is an error | , rates ×2, 6, up | → | error: duplicate rate for fee earner "PTN" |
| a rate card in two currencies is an error | , rates ×2, 6, up | → | error: currency mismatch |
| a negative hourly rate is an error | , rates ×1, 6, up | → | error: hourly rates must not be negative |
| negative minutes are an error | entries ×1, rates ×3, 6, up | → | error: minutes must be a non-negative integer |
| a zero-minute unit is an error | entries ×1, rates ×3, 0, up | → | error: increment must be a positive integer |
More from the author
**Fees.** Each line's fee is billed minutes x hourly rate / 60, rounded half-up to the minor unit, and the bill total is the sum of the lines, so the lines on the bill add up to its total exactly. The summary per fee earner (units and fee) is in order of each fee earner's first entry.
**Rate card.** One rate per fee earner code, all in one currency; a duplicate code, an entry with no rate, a negative rate or mixed currencies is an error. A rate card that changes during a matter is the caller's job: split the entries by the date the new rates took effect and bill each part with its own card. VAT is not added here; pass the total to finance.tax.add-vat.
## Before you rely on this
**Not professional advice.** This capability calculates legal figures from published rules. It is a software component for developers, not 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 above, and have a solicitor review how you use it, before anyone relies on the output. Provided "as is" under its licence, without warranty.
**Unreviewed.** This capability's implementations agree in every language and pass its published test vectors, which were worked out from the official sources cited. But no qualified solicitor has yet checked those vectors, or confirmed that the capability covers the cases it claims. Treat it as a draft. Do not use it for real people, money or decisions without your own expert review. Once a qualified reviewer signs off, this notice is replaced with their name, qualification and the date. Each new version needs fresh sign-off.
1.0.1 marks it unreviewed. The code and the tests are unchanged.
Files
| Path | Bytes |
|---|---|
| README.md | 2,497 |
| impl/python.py | 2,664 |
| impl/rust.rs | 4,978 |
| impl/typescript.ts | 2,626 |
| vectors.json | 15,636 |