/** * A due as a day and a clock time in a zone, and back: the phone's own rules * (cotton-rules moment_split.rs and zoned_clock.rs, run as WASM), so the * Worker and the phone read every zone from the same tz data. A refusal is a * tool error in the rule's words. */ import { fail } from "../../context.ts"; import { tryRule } from "../../../rules/index.ts"; function said(name: string, input: unknown): T { const out = tryRule(name, input); if ("error" in out) fail(out.error); return out.ok; } export function isKnownZone(zone: string): boolean { return said("zone.known", { zone }); } /** An instant as its day and (unless midnight) its clock time in `zone`. */ export function splitMoment(at: string, zone: string): { date: string; time: string | null } { return said("moment.split", { at, zone }); } /** A day (and an optional clock time) in `zone` as the instant, ISO. */ export function joinMoment(date: string, time: string | null, zone: string): string { return said("moment.join", { date, time, zone }); } export type Part = { kind: "unchanged" } | { kind: "cleared" } | { kind: "set"; value: string }; /** The due after a day/time change, resolved against the todo's current due (`next_moment`). */ export function nextMoment(current: string | null, date: Part, time: Part, zone: string): string | null { return said("moment.next", { current, date, time, zone }); }