Functional Weave
Code in TypeScript

form.iso-date

Check a date picker value (YYYY-MM-DD) against required, past/future and min/max rules, timezone-safe.

1.0.0 · published 2026-10-10 by charlie · Anterra

Pinned by 24 tests, run in TypeScript, Python and Rust.

What it does

The server-side twin of a date picker (`<input type="date">`, or `react.form.date-field`): the browser submits `YYYY-MM-DD`, and this checks it again with the same rules and the GOV.UK Design System's wording, in TypeScript, Python and Rust.

## What it checks, in order

For example

  • validateIsoDate(2024-02-29, Start date, true, today —, timing —, not before —, not after —) → valid true, date 2024-02-29, message — a leap day from the picker
  • validateIsoDate(2023-02-29, Start date, true, today —, timing —, not before —, not after —) → valid false, date —, message Start date must be a real date 29 February 2023 does not exist
  • validateIsoDate(, Start date, true, today —, timing —, not before —, not after —) → valid false, date —, message Enter start date empty and required: GOV.UK's Enter message, label lower-cased

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 validateIsoDate(value: string, label: string, required: boolean, rules: DateRules): IsoDateCheck
valuestringwhat the date picker submitted, YYYY-MM-DD, or what was typed where the browser has no picker
labelstringwhat the date is, as it starts a sentence: "Date of birth", "Start date"
requiredboolan empty value is an error
rulesDateRulesform.date-parts' rules: past/future against today (passed in), earliest and latest
returnsIsoDateCheckvalid with the ISO date (null when empty and not required), or the message

The type it declares, generated into your project

/** The verdict on a date picker's value. */
export interface IsoDateCheck {
  readonly valid: boolean;
  /** the ISO date, when valid and given */
  readonly date: string | null;
  /** the error message to show, when not valid */
  readonly message: string | null;
}

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

import { validateIsoDate } from "#fune/form.iso-date@^1";
impl/typescript.ts · 48 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.

import { validateDateParts, type DateRules } from "./form_date_parts.ts";  ← from form.date-parts ^1.0.0 · built alongside by fune
import type { IsoDateCheck } from "./form_iso_date_types.ts";

// ASCII whitespace only, so all three languages trim the same characters.
function isSpace(ch: string): boolean {
  return ch === " " || ch === "\t" || ch === "\n" || ch === "\r" || ch === "\f" || ch === "\v";
}

function trim(value: string): string {
  let start = 0;
  let end = value.length;
  while (start < end && isSpace(value[start])) start++;
  while (end > start && isSpace(value[end - 1])) end--;
  return value.slice(start, end);
}

// YYYY-MM-DD with ASCII digits: what <input type="date"> submits, and nothing
// else (no time, no offset, no other script's digits).
function isoShape(value: string): boolean {
  if (value.length !== 10) return false;
  for (let i = 0; i < 10; i++) {
    const ch = value[i];
    if (i === 4 || i === 7) {
      if (ch !== "-") return false;
    } else if (ch < "0" || ch > "9") {
      return false;
    }
  }
  return true;
}

/**
 * A date picker's value, checked with form.date-parts' rules and messages.
 * Pure calendar arithmetic on the string: no Date object, so no time zone can
 * move the day; "today" for past/future rules is passed in by the caller.
 */
export function validateIsoDate(value: string, label: string, required: boolean, rules: DateRules): IsoDateCheck {
  // Called with empty boxes first, so a bad label or bad rules throw whatever
  // was typed, and its answer is the "Enter ..." message for a required date.
  const empty = validateDateParts({ day: "", month: "", year: "" }, label, rules);
  const typed = trim(value);
  if (typed === "") {
    return required ? { valid: false, date: null, message: empty.message } : { valid: true, date: null, message: null };
  }
  if (!isoShape(typed)) return { valid: false, date: null, message: `${trim(label)} must be a real date` };
  const check = validateDateParts({ day: typed.slice(8, 10), month: typed.slice(5, 7), year: typed.slice(0, 4) }, label, rules);
  return check.valid ? { valid: true, date: check.date, message: null } : { valid: false, date: null, message: check.message };
}

Install

fune build

With that line in your source, in a TypeScript project (language typescript in fune.project), fune build resolves it and its 1 dependency, 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 form.iso-date
Download for TypeScript form.iso-date-1.0.0-typescript.fune · 14,770 bytes sha256 3d346a2f7022a210135102e1787b3a9ad8137ade68f25c1e447285078a915614

The manifest, vectors and README with only the TypeScript implementation. Install it without the registry with fune add ./form.iso-date-1.0.0-typescript.fune, or fetch it from a terminal with fune pull form.iso-date@1.0.0:typescript.

The whole function, every language, is one file too: form.iso-date-1.0.0.fune, 19,756 bytes, sha256 5756e6138018dc6894f09e20db8f9e15661a733aaacce402d106eafbe29a2f82. 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 form.iso-date

after — your function gets the result and the arguments, and returns the final result.

// fune: after form.iso-date

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 form.date-parts in form.iso-date

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 form.iso-date --steps.

// fune: step form.iso-date 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
a leap day from the picker 2024-02-29, Start date, true, today —, timing —, not before —, not after — → valid true, date 2024-02-29, message —
29 February 2023 does not exist 2023-02-29, Start date, true, today —, timing —, not before —, not after — → valid false, date —, message Start date must be a real date
empty and required: GOV.UK's Enter message, label lower-cased , Start date, true, today —, timing —, not before —, not after — → valid false, date —, message Enter start date
empty and not required is valid with no date , Start date, false, today —, timing —, not before —, not after — → valid true, date —, message —
only whitespace counts as empty , Start date, false, today —, timing —, not before —, not after — → valid true, date —, message —
surrounding spaces and a trailing newline are trimmed 2024-01-05 , Start date, true, today —, timing —, not before —, not after — → valid true, date 2024-01-05, message —
a UK-style date is not the picker's format 05/01/2024, Start date, true, today —, timing —, not before —, not after — → valid false, date —, message Start date must be a real date
unpadded month and day are not the picker's format 2024-1-5, Start date, true, today —, timing —, not before —, not after — → valid false, date —, message Start date must be a real date
Arabic-Indic digits are not a date ٢٠٢٤-01-05, Start date, true, today —, timing —, not before —, not after — → valid false, date —, message Start date must be a real date
a date and time is not a date 2024-02-29T00:00:00Z, Start date, true, today —, timing —, not before —, not after — → valid false, date —, message Start date must be a real date
Show the other 14 tests
CaseArgumentsExpected
month 13 2024-13-01, Start date, true, today —, timing —, not before —, not after — → valid false, date —, message Start date must be a real date
year 0000 0000-01-01, Start date, true, today —, timing —, not before —, not after — → valid false, date —, message Start date must be a real date
31 April 2025-04-31, Start date, true, today —, timing —, not before —, not after — → valid false, date —, message Start date must be a real date
an acronym label keeps its capitals , UK arrival date, true, today —, timing —, not before —, not after — → valid false, date —, message Enter UK arrival date
past: today itself is not in the past 2026-10-10, Date of birth, true, today 2026-10-10, timing past, not before —, not after — → valid false, date —, message Date of birth must be in the past
past: yesterday is 2026-10-09, Date of birth, true, today 2026-10-10, timing past, not before —, not after — → valid true, date 2026-10-09, message —
future-or-today accepts today 2026-10-10, Start date, true, today 2026-10-10, timing future-or-today, not before —, not after — → valid true, date 2026-10-10, message —
min and max: after the range 2027-01-01, Start date, true, today —, timing —, not before 2026-01-01, not after 2026-12-31 → valid false, date —, message Start date must be between 1 January 2026 and 31 December 2026
min and max are inclusive 2026-12-31, Start date, true, today —, timing —, not before 2026-01-01, not after 2026-12-31 → valid true, date 2026-12-31, message —
min only: the day before 2025-12-31, Start date, true, today —, timing —, not before 2026-01-01, not after — → valid false, date —, message Start date must be the same as or after 1 January 2026
max only: the day after 2026-02-01, End date, true, today —, timing —, not before —, not after 2026-01-31 → valid false, date —, message End date must be the same as or before 31 January 2026
a label is needed even for an empty optional date , , false, today —, timing —, not before —, not after — → error: a date needs a label
a timing rule needs today 2026-01-01, Start date, true, today —, timing past, not before —, not after — → error: rules.today is needed to check that a date is past
min after max is the caller's mistake, whatever was typed , Start date, false, today —, timing —, not before 2026-02-01, not after 2026-01-01 → error: must not be after rules.notAfter

Verification

Verified by the operator, not the sandbox 24 test vectors declared; none run by the registry.

Verified locally by the registry's operator, not by the sandbox. This version was published with FUNE_VERIFY_MODE=inline-dev (the operator's import of the first-party registry, or a development server): the server validated the package - its manifest, signatures, imports, safety lint and test rules - but the registry did not run its test vectors in its sandbox. The operator runs them with `fune verify --all` before importing.

Signed by the registry with key fw-9dc887227da47575 (ed25519), over its integrity and this report's digest. The full report · JSON

More from the author

1. The label and rules, whatever was typed: an empty label, a past/future rule without `today`, a malformed rule date, or `notBefore` after `notAfter` throws (these are the caller's mistakes, as in `form.date-parts`). 2. Empty (after trimming ASCII whitespace): `Enter <label>` when required, otherwise valid with `date: null`. 3. The shape: exactly `YYYY-MM-DD` in ASCII digits. Anything else (`05/01/2024`, `2024-1-5`, a time, other scripts' digits) is `<Label> must be a real date`. 4. Then `form.date-parts`' `validateDateParts` with the three parts: a date that does not exist (31 April, 29 February 2023, month 13, year 0000), then `timing` against `today`, then `notBefore` / `notAfter` (inclusive), with its messages ("must be between 1 January 2026 and 31 December 2026").

## Timezone-safe

No `Date`, `datetime` or clock is used: the value is a calendar date and is compared as one, so no offset or daylight saving change can move it by a day. The one date that depends on a time zone is *today*, and the caller passes it. Work it out in the user's zone, not the server's: in a browser, `new Date().toLocaleDateString("en-CA")` gives today's `YYYY-MM-DD` in the browser's zone; on a server, convert the current instant with the user's IANA zone (`Intl.DateTimeFormat("en-CA", { timeZone })`, Python's `zoneinfo`, or `time.unix-to-iso` with their offset). A date of birth checked "in the past" against the server's UTC date would refuse someone in Auckland born today.

The same `min`/`max` belong on the input as attributes (`min="2026-01-01"`), so the picker greys out what this would refuse.

## Notices

Error message wording follows the GOV.UK Design System. Portions derived from GOV.UK Frontend (https://github.com/alphagov/govuk-frontend), Copyright (c) 2017 Crown Copyright (Government Digital Service), under the MIT License; the full notice is in NOTICE.

Files

PathBytes
NOTICE1,211
README.md2,186
impl/python.py1,795
impl/rust.rs3,002
impl/typescript.ts2,150
vectors.json5,853