finance.tax.vat-rate
Look up the VAT rate in force for a jurisdiction, category and date.
1.2.0 (not the latest) · published 2026-10-03 by charlie · Anterra
Pinned by 22 tests, run in TypeScript, Python and Rust.
Not professional advice. This capability calculates tax figures from published rules. It is a software component for developers, not tax 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 chartered accountant or tax adviser review how you use it, before anyone relies on the output. Provided “as is” under its licence, without warranty.
What it does
The rate is not a constant in the code. It is a dated row in data/vat-rules.json, and the lookup takes the date of supply.
That is the difference between a system that can still reprint a 2009 invoice correctly and one that silently reprints it at today's rate. UK VAT was 15% in 2009, 17.5% in 2010 and 20% since 2011; UK hospitality was 5% for part of the pandemic; and the Irish tourism rate has moved between 9% and 13.5% four times since 2011.
For example
vatRate(GB, STANDARD, 2026-09-16)→ jurisdiction GB, category STANDARD, rate 20%, valid from 2011-01-04, valid to — UK standard rate todayvatRate(GB, STANDARD, 2009-06-01)→ jurisdiction GB, category STANDARD, rate 15%, valid from 2008-12-01, valid to 2009-12-31 UK standard rate during the 2009 cutvatRate(GB, STANDARD, 2010-06-01)→ jurisdiction GB, category STANDARD, rate 17.5%, valid from 2010-01-01, valid to 2011-01-03 UK standard rate in 2010
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 vatRate(jurisdiction: string, category: string, onDate: string): VatRate
| jurisdiction | string | ISO 3166-1 alpha-2, e.g. GB or IE |
| category | string | STANDARD | REDUCED | ZERO | EXEMPT | HOSPITALITY |
| onDate | date | ISO date the supply took place |
| returns | VatRate |
The type it declares, generated into your project
/** The rate that applied, and the dates it was in force. */
export interface VatRate {
readonly jurisdiction: string;
readonly category: string;
readonly basisPoints: number;
readonly validFrom: string;
/** null while the rate is still in force */
readonly validTo: string | null;
}
Your code names it in one line, in the file that uses it
import { vatRate } from "#fune/finance.tax.vat-rate@^1";
Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.
import { VAT_RULES, VAT_RULES_HISTORY } from "./finance_tax_vat_rate_data.ts"; ← this capability’s own data, compiled from data/vat-rules.json into the same file by fune build
import { type VatRate } from "./finance_tax_vat_rate_types.ts";
const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
/**
* The VAT rate in force for a jurisdiction and category on a given date.
*
* The date matters. A credit note against a 2009 invoice has to use the rate
* that applied in 2009, not the one that applies today, and a system that
* hardcodes 0.20 cannot do that at all.
*
* ISO dates compare correctly as strings, so this needs no date library.
*/
export function vatRate(jurisdiction: string, category: string, onDate: string): VatRate {
if (!ISO_DATE.test(onDate)) {
throw new RangeError(`onDate must be an ISO date (YYYY-MM-DD), received "${onDate}"`);
}
let best: VatRate | null = null;
for (const rule of VAT_RULES) {
if (rule.jurisdiction !== jurisdiction || rule.category !== category) continue;
if (onDate < rule.validFrom) continue;
if (rule.validTo !== null && onDate > rule.validTo) continue;
if (best === null || rule.validFrom > best.validFrom) {
best = {
jurisdiction: rule.jurisdiction,
category: rule.category,
basisPoints: rule.basisPoints,
validFrom: rule.validFrom,
validTo: rule.validTo,
};
}
}
if (best === null) {
// A build installed with history=current carries only the rules still in
// force. Answering an older date with today's rate would be the exact
// failure this capability exists to prevent, so say what happened instead.
// The horizon that matters is this jurisdiction and category's own earliest
// surviving rule, not the registry-wide one.
if (VAT_RULES_HISTORY !== "full") {
let earliest: string | null = null;
for (const rule of VAT_RULES) {
if (rule.jurisdiction !== jurisdiction || rule.category !== category) continue;
if (earliest === null || rule.validFrom < earliest) earliest = rule.validFrom;
}
if (earliest !== null && onDate < earliest) {
throw new RangeError(
`no VAT rule for ${jurisdiction}/${category} on ${onDate}: this build was installed with history=${VAT_RULES_HISTORY}, ` +
`so it only carries rules from ${earliest}. Reinstall with history=full to reprint older invoices.`
);
}
}
throw new RangeError(`no VAT rule for ${jurisdiction}/${category} on ${onDate}`);
}
return best;
}
/** Every category this registry knows a rate for, for a jurisdiction and date. */
export function vatCategories(jurisdiction: string, onDate: string): string[] {
const seen = new Set<string>();
for (const rule of VAT_RULES) {
if (rule.jurisdiction !== jurisdiction) continue;
if (onDate < rule.validFrom) continue;
if (rule.validTo !== null && onDate > rule.validTo) continue;
seen.add(rule.category);
}
return [...seen].sort();
}Install
fune build
With that line in your source, in a TypeScript project (language typescript in fune.project), fune build resolves it and nothing else, 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 finance.tax.vat-rate
The manifest, vectors and README with only the TypeScript implementation. Install it without the registry with fune add ./finance.tax.vat-rate-1.2.0-typescript.fune, or fetch it from a terminal with fune pull finance.tax.vat-rate@1.2.0:typescript.
The whole function, every language, is one file too: finance.tax.vat-rate-1.2.0.fune, 26,789 bytes, sha256 8a75d11902283c7ae2d991659e9066c925d6b740e862a57a5fdab0c185480422. 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 finance.tax.vat-rate
after — your function gets the result and the arguments, and returns the final result.
// fune: after finance.tax.vat-rate
replace — it requires no other capability, so there is no dependency to replace.
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 finance.tax.vat-rate --steps.
// fune: step finance.tax.vat-rate 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 | |
|---|---|---|---|
| UK standard rate today | GB, STANDARD, 2026-09-16 | → | jurisdiction GB, category STANDARD, rate 20%, valid from 2011-01-04, valid to — |
| UK standard rate during the 2009 cut | GB, STANDARD, 2009-06-01 | → | jurisdiction GB, category STANDARD, rate 15%, valid from 2008-12-01, valid to 2009-12-31 |
| UK standard rate in 2010 | GB, STANDARD, 2010-06-01 | → | jurisdiction GB, category STANDARD, rate 17.5%, valid from 2010-01-01, valid to 2011-01-03 |
| the day the rate changed | GB, STANDARD, 2011-01-04 | → | jurisdiction GB, category STANDARD, rate 20%, valid from 2011-01-04, valid to — |
| the day before the rate changed | GB, STANDARD, 2011-01-03 | → | jurisdiction GB, category STANDARD, rate 17.5%, valid from 2010-01-01, valid to 2011-01-03 |
| hospitality during the covid cut | GB, HOSPITALITY, 2020-12-25 | → | jurisdiction GB, category HOSPITALITY, rate 5%, valid from 2020-07-15, valid to 2021-09-30 |
| hospitality during the taper | GB, HOSPITALITY, 2021-11-01 | → | jurisdiction GB, category HOSPITALITY, rate 12.5%, valid from 2021-10-01, valid to 2022-03-31 |
| hospitality back at standard | GB, HOSPITALITY, 2026-09-16 | → | jurisdiction GB, category HOSPITALITY, rate 20%, valid from 2022-04-01, valid to — |
| UK reduced rate | GB, REDUCED, 2026-09-16 | → | jurisdiction GB, category REDUCED, rate 5%, valid from 1997-09-01, valid to — |
| UK zero rate | GB, ZERO, 2026-09-16 | → | jurisdiction GB, category ZERO, rate 0%, valid from 1973-04-01, valid to — |
Show the other 12 tests
| Case | Arguments | Expected | |
|---|---|---|---|
| Ireland standard rate | IE, STANDARD, 2026-09-16 | → | jurisdiction IE, category STANDARD, rate 23%, valid from 2021-03-01, valid to — |
| unknown jurisdiction is an error, not a guess | FR, STANDARD, 2026-09-16 | → | error: no VAT rule |
| a date before the rule existed is an error | GB, STANDARD, 1970-01-01 | → | error: no VAT rule |
| a malformed date is an error | GB, STANDARD, 16/09/2026 | → | error: ISO date |
| Irish hospitality during the 9 percent tourism rate | IE, HOSPITALITY, 2015-06-01 | → | jurisdiction IE, category HOSPITALITY, rate 9%, valid from 2011-07-01, valid to 2018-12-31 |
| Irish hospitality after the 2019 withdrawal | IE, HOSPITALITY, 2019-06-01 | → | jurisdiction IE, category HOSPITALITY, rate 13.5%, valid from 2019-01-01, valid to 2020-10-31 |
| Irish hospitality during the covid 9 percent | IE, HOSPITALITY, 2021-06-01 | → | jurisdiction IE, category HOSPITALITY, rate 9%, valid from 2020-11-01, valid to 2023-08-31 |
| Irish hospitality today | IE, HOSPITALITY, 2026-09-16 | → | jurisdiction IE, category HOSPITALITY, rate 13.5%, valid from 2023-09-01, valid to — |
| the day the covid rate ended | IE, HOSPITALITY, 2023-08-31 | → | jurisdiction IE, category HOSPITALITY, rate 9%, valid from 2020-11-01, valid to 2023-08-31 |
| Irish standard rate during the 2020-21 cut | IE, STANDARD, 2020-12-01 | → | jurisdiction IE, category STANDARD, rate 21%, valid from 2020-09-01, valid to 2021-02-28 |
| Irish standard rate the day before the cut | IE, STANDARD, 2020-08-31 | → | jurisdiction IE, category STANDARD, rate 23%, valid from 2012-01-01, valid to 2020-08-31 |
| Irish standard rate restored on 1 March 2021 | IE, STANDARD, 2021-03-01 | → | jurisdiction IE, category STANDARD, rate 23%, valid from 2021-03-01, valid to — |
More from the author
When a rate changes, publish a new version of this capability's data. Application code does not change at all - that is what 1.1.0 is: 1.0.0 plus the Irish hospitality history, no implementation change. And 1.2.0 is 1.1.0 plus Ireland's temporary 21% standard rate from 1 September 2020 to 28 February 2021, which 1.1.0 missed (source: Revenue, "Current VAT rates", https://www.revenue.ie/en/vat/vat-rates/search-vat-rates/current-vat-rates.aspx).
This version also declares its effective-date columns, so a project can install `history=current` and ship only the rules still in force. A build that does will refuse a date before its horizon rather than answer it with today's rate.
Files
| Path | Bytes |
|---|---|
| README.md | 1,159 |
| data/vat-rules.json | 4,180 |
| impl/python.py | 3,145 |
| impl/rust.rs | 4,807 |
| impl/typescript.ts | 2,902 |
| vectors.json | 6,090 |