//! A slip's date said by the core against the instant it is handed, in the//! reader's zone. Every record is invented.use serde_json::{json, Map, Value};usesuper::*;usecrate::definitions::builtin_table_definition;const IST: &str = "Asia/Kolkata";const LA: &str = "America/Los_Angeles";fn at(text: &str) -> chrono::DateTime<chrono::Utc> { chrono::DateTime::parse_from_rfc3339(text).unwrap().with_timezone(&chrono::Utc)}/// 1 Oct 2026, 10:00 in India.fn now() -> chrono::DateTime<chrono::Utc> { at("2026-10-01T10:00:00+05:30") }fn todo(value: Value) -> Map<String, Value> {letmut data = json!({"title": "Invented errand", "status": "open"}); data.as_object_mut().unwrap().extend(value.as_object().unwrap().clone()); data.as_object().unwrap().clone()}fn foot(data: Value) -> Option<(String, bool)> {let todos = builtin_table_definition("todo").unwrap(); upcoming_foot(todos, &todo(data), IST, now(), None, DateWords::shipped()).map(|line| (line.text, line.late))}fn strip(data: Value) -> Option<(String, bool)> {let todos = builtin_table_definition("todo").unwrap(); upcoming_strip(todos, &todo(data), IST, now(), DateWords::shipped()).map(|line| (line.text, line.late))}fn said(text: &str, late: bool) -> Option<(String, bool)> { Some((text.into(), late)) }/// RULE: every relative form is one typed value said in one place; the near/// window decides between a count of days and the short weekday date, and/// the year shows only outside the reader's own.#[test]fn each_relative_form_reads_against_today() {let today = crate::transforms::zoned_clock::day_number(2026, 10, 21);let words = |day: i64, near: i64| RelativeDay::of(today + day, today, near).words(DateWords::shipped()); assert_eq!(words(0, 7), "today"); assert_eq!(words(1, 7), "tomorrow"); assert_eq!(words(-1, 7), "yesterday"); assert_eq!(words(-4, 7), "4 days late"); assert_eq!(words(3, 7), "in 3 days"); assert_eq!(words(7, 7), "in 7 days", "the window's edge is inside it"); assert_eq!(words(8, 7), "Thu 29 Oct", "past the window: the weekday date"); assert_eq!(words(-8, 7), "Tue 13 Oct"); assert_eq!(words(2, 1), "Fri 23 Oct", "a window of one keeps only the three named days"); assert_eq!(words(79, 1), "Fri 8 Jan 2027", "another year says its year"); assert_eq!(DateWords::shipped().days_late(1), "1 day late"); assert_eq!(DateWords::shipped().days_late(0), "late");}/// RULE: under its day heading an open slip's foot says what the heading/// does not — the day gone and how late, in red; the hour, red once passed;/// when a snooze brings it back in its column's reading — and nothing for an/// all-day todo on its day; a done todo has no foot of this kind.#[test]fn the_foot_says_how_late_the_hour_or_when_it_comes_back() { assert_eq!(foot(json!({"due_at": "2026-09-29"})), said("Tue 29 Sep · 2 days late", true)); assert_eq!(foot(json!({"due_at": "2026-10-01T09:30:00+05:30"})), said("9:30 am", true), "an hour passed today reads late"); assert_eq!(foot(json!({"due_at": "2026-10-01T18:00:00+05:30"})), said("6:00 pm", false)); assert_eq!(foot(json!({"due_at": "2026-10-01"})), None, "the heading names the day"); assert_eq!(foot(json!({"due_at": "2026-09-30", "snoozed_until": "2026-10-01T15:00:00+05:30"})), said("Snoozed until 3:00 pm", false)); assert_eq!(foot(json!({"due_at": "2026-10-01", "snoozed_until": "2026-10-02"})), said("Snoozed until Fri 2 Oct", false)); assert_eq!(foot(json!({"due_at": "2026-09-30", "snoozed_until": "2026-10-01"})), said("Snoozed until today", false)); assert_eq!(foot(json!({"due_at": "2026-09-29", "status": "done"})), None); assert_eq!(foot(json!({})), None);}/// RULE: under Later, where no heading names the day, the foot says the day/// and then its hour (R7 d), never the hour alone.#[test]fn a_slip_under_later_says_its_day() { assert_eq!(foot(json!({"due_at": "2026-10-16T09:00:00+05:30"})), said("Fri 16 Oct · 9:00 am", false)); assert_eq!(foot(json!({"due_at": "2026-10-16"})), said("Fri 16 Oct", false)); assert_eq!(foot(json!({"due_at": "2027-01-08"})), said("Fri 8 Jan 2027", false)); assert_eq!(foot(json!({"due_at": "2026-10-08"})), None, "the horizon's last day still stands under its own heading");}/// RULE: a snooze that ended on a day gone is over: the record is late by its/// own day, not the snooze's, and the tile says the same.#[test]fn a_snooze_that_ended_is_over() {let lapsed = json!({"due_at": "2026-09-25", "snoozed_until": "2026-09-28T09:00:00+05:30"}); assert_eq!(foot(lapsed.clone()), said("Fri 25 Sep · 6 days late", true)); assert_eq!(strip(lapsed), said("6 days late", true)); assert_eq!(foot(json!({"snoozed_until": "2026-09-29"})), None); assert_eq!(strip(json!({"snoozed_until": "2026-09-29"})), None); assert_eq!(foot(json!({"due_at": "2026-09-28", "snoozed_until": "2026-10-01T08:00:00+05:30"})), said("Snoozed until 8:00 am", false));}/// RULE: a tile's strip has no heading over it, so it says the day: late in/// red, the hour today, today, tomorrow, the weekday date, or "back" with/// when a snooze ends.#[test]fn the_strip_says_the_day() { assert_eq!(strip(json!({"due_at": "2026-09-30"})), said("1 day late", true)); assert_eq!(strip(json!({"due_at": "2026-10-01"})), said("today", false)); assert_eq!(strip(json!({"due_at": "2026-10-01T09:00:00+05:30"})), said("9:00 am", true)); assert_eq!(strip(json!({"due_at": "2026-10-02T09:00:00+05:30"})), said("tomorrow", false)); assert_eq!(strip(json!({"due_at": "2026-10-05"})), said("Mon 5 Oct", false)); assert_eq!(strip(json!({"due_at": "2026-09-30", "snoozed_until": "2026-10-01T15:00:00+05:30"})), said("back 3:00 pm", false)); assert_eq!(strip(json!({"due_at": "2026-09-30", "snoozed_until": "2026-10-03"})), said("back Sat 3 Oct", false));}/// RULE: a day turns at the reader's own midnight, not UTC's: the same/// instant is today in India and still yesterday in California, and a bare/// date is that calendar day wherever the reader is.#[test]fn midnight_turns_in_the_readers_zone() {let todos = builtin_table_definition("todo").unwrap();let line = |data: Value, zone: &str, now: &str| upcoming_strip(todos, &todo(data), zone, at(now), DateWords::shipped()).map(|line| line.text);// 00:30 on 2 Oct in India is 19:00 on 1 Oct UTC and 12:00 on 1 Oct in LA.let instant = "2026-10-01T19:00:00Z"; assert_eq!(line(json!({"due_at": "2026-10-02"}), IST, instant).as_deref(), Some("today")); assert_eq!(line(json!({"due_at": "2026-10-02"}), LA, instant).as_deref(), Some("tomorrow")); assert_eq!(line(json!({"due_at": "2026-10-01"}), IST, instant).as_deref(), Some("1 day late")); assert_eq!(line(json!({"due_at": "2026-10-01"}), LA, instant).as_deref(), Some("today"));// One minute either side of midnight in India. assert_eq!(line(json!({"due_at": "2026-10-01"}), IST, "2026-10-01T23:59:00+05:30").as_deref(), Some("today")); assert_eq!(line(json!({"due_at": "2026-10-01"}), IST, "2026-10-02T00:00:00+05:30").as_deref(), Some("1 day late"));// A timed instant is read on the reader's wall clock. assert_eq!(line(json!({"due_at": "2026-10-02T03:00:00Z"}), LA, "2026-10-01T12:00:00-07:00").as_deref(), Some("8:00 pm"));}/// RULE: the late occurrences of one series stand as one slip saying how many/// were missed; a record of no series never says it.#[test]fn a_series_says_how_many_it_missed() {let todos = builtin_table_definition("todo").unwrap();let bins = |due: &str, status: &str| todo(json!({"due_at": due, "status": status, "recurrence_id": "series-bins"}));let records = [bins("2026-09-20", "open"), bins("2026-09-27", "open"), bins("2026-10-01", "open"), bins("2026-09-13", "done"), todo(json!({"due_at": "2026-08-03"}))];let missed = missed_by_series(todos, records.iter(), IST, now()); assert_eq!(missed.get("series-bins"), Some(&2));letmut standing = records[1].clone(); attach_dated_lines(todos, &mut standing, IST, now(), &missed, DateWords::shipped()); assert_eq!(standing[SLIP_FOOT_KEY], "Sun 27 Sep · 4 days late · missed 2"); assert_eq!(standing[SLIP_FOOT_LATE_KEY], true); assert_eq!(standing[SLIP_STRIP_KEY], "4 days late");letmut rent = records[4].clone(); attach_dated_lines(todos, &mut rent, IST, now(), &missed, DateWords::shipped()); assert!(!rent[SLIP_FOOT_KEY].as_str().unwrap().contains("missed"));letmut today = records[2].clone(); attach_dated_lines(todos, &mut today, IST, now(), &missed, DateWords::shipped()); assert_eq!(today[SLIP_FOOT_KEY], Value::Null, "an all-day todo on its day has no foot"); assert_eq!(today[SLIP_FOOT_LATE_KEY], false);}/// RULE: a face draws a date the core resolved, never one it spelled itself/// (contract 7, Swift draws): every date column of a record carries its face/// words in `@column_words` — the weekday date (the year only outside the/// reader's), the clock when it states one, a month as month and year, and/// the relative formats against the read's own now.#[test]fn column_words_say_every_date_a_face_draws() {let definition: TableDefinition = serde_json::from_value(json!({"id": "invented", "name": "Invented", "plural": "Invented", "picture": null, "builtin": false, "engine": null,"title": "title", "date": null, "project": null, "order": null,"slip": { "title": "title", "subtitle": null, "trailing": null, "photo": null, "toggle": null },"tile": { "face": "slip-list" }, "page": [], "instructions": "Invented.","columns": [ {"key": "title", "type": "text"}, {"key": "on", "type": "date"}, {"key": "at", "type": "date"}, {"key": "far", "type": "date"}, {"key": "expires", "type": "date", "month": true}, {"key": "seen", "type": "date", "format": "ago"}, {"key": "resets", "type": "date", "format": "countdown"}, {"key": "born", "type": "date", "yearly": true}, {"key": "blank", "type": "date"}, {"key": "took_ms", "type": "number", "format": "duration_ms"} ] })).unwrap();let data = json!({"title": "Invented", "on": "2026-10-02", "at": "2026-10-01T09:30:00+05:30","far": "2027-01-08", "expires": "2027-11", "seen": "2026-10-01T04:27:00Z","resets": "2026-10-01T06:30:00Z", "born": "1990-08-17", "took_ms": 4000 });let words = column_words(&definition, data.as_object().unwrap(), Some(IST), Some(now()), crate::records::page::Words::shipped()); assert_eq!(words["on"], "Fri 2 Oct"); assert_eq!(words["at"], "Thu 1 Oct \u{b7} 9:30 am"); assert_eq!(words["far"], "Fri 8 Jan 2027"); assert_eq!(words["expires"], "Nov 2027"); assert_eq!(words["seen"], "3 min ago"); assert_eq!(words["resets"], "2 h"); assert_eq!(words["blank"], Value::Null); assert_eq!(words["took_ms"], "4 s"); assert!(!words.contains_key("born"), "a yearly day is not read here yet"); assert!(!words.contains_key("title")); assert!(reads_column_words(&definition));}/// GUARD (moved from Swift's MoneyWordsTests, 291 words row 5): an amount is/// kept in minor units and never drawn in them. The face draws the core's/// words for it (`column_words`), so 49900 with no currency is "499", never/// "49,900", and with its row's currency it says that currency.#[test]fn an_amount_face_never_draws_minor_units() {let definition: TableDefinition = serde_json::from_value(json!({"id": "invented_plan", "name": "Plan", "plural": "Plans", "picture": null, "builtin": false, "engine": null,"title": "title", "date": null, "project": null, "order": null,"slip": { "title": "title", "subtitle": null, "trailing": null, "photo": null, "toggle": null },"tile": { "face": "slip-list" }, "page": [], "instructions": "Invented.","columns": [ {"key": "title", "type": "text"}, {"key": "currency", "type": "text"}, {"key": "price", "type": "amount", "currency": "currency"}, {"key": "bare", "type": "amount"} ] })).unwrap();let data = json!({"title": "Invented", "currency": "USD", "price": 49900, "bare": 49900});let words = column_words(&definition, data.as_object().unwrap(), Some(IST), Some(now()), crate::records::page::Words::shipped());for key in ["price", "bare"] {let said = words[key].as_str().unwrap(); assert!(said.contains("499") && !said.contains("49900") && !said.contains("49,900"), "{key} drew minor units: {said}"); } assert_eq!(words["bare"], "499");}/// RULE: a field card's date is the core's typed parts (contract 7): near/// words within a week either side, the dated day past it, the clock when/// it states one, the late words when it is behind, and the leaf's parts —/// so a card draws a date and never reads a calendar for words.#[test]fn day_parts_give_every_surface_every_part_of_its_date() {let today = Moment::now(now(), IST).unwrap();let day = |text: &str| day_part(Moment::parse(text, IST).unwrap(), today, DateWords::shipped());let same = day("2026-10-01"); assert_eq!((same.near.as_deref(), same.dated.as_str(), same.late.as_deref()), (Some("Today"), "1 Oct", None)); assert_eq!((same.leaf_day, same.leaf_month.as_str(), same.day.as_str()), (1, "Oct", "2026-10-01")); assert_eq!(day("2026-10-02").near.as_deref(), Some("Tomorrow")); assert_eq!(day("2026-09-30").near.as_deref(), Some("Yesterday")); assert_eq!(day("2026-10-05").near.as_deref(), Some("Monday")); assert_eq!(day("2026-10-08").near, None, "a week on is dated"); assert_eq!(day("2027-01-08").dated, "8 Jan 2027"); assert_eq!(day("2026-09-30").late.as_deref(), Some("1 day late")); assert_eq!(day("2026-09-27").late.as_deref(), Some("4 days late"));let passed = day("2026-10-01T09:00:00+05:30"); assert_eq!((passed.clock.as_deref(), passed.late.as_deref()), (Some("9:00 am"), Some("late"))); assert_eq!(day("2026-10-01T11:00:00+05:30").late, None, "an hour still ahead is not late"); assert_eq!((same.heading.as_str(), same.recent.as_str(), same.under_day.as_str()), ("Today", "Today", "All day")); assert_eq!((passed.recent.as_str(), passed.under_day.as_str()), ("9:00 am", "9:00 am"));let far = day("2025-09-03"); assert_eq!((far.heading.as_str(), far.recent.as_str(), far.weekday_date.as_str()), ("Wed 3 Sep 2025", "Wed 3 Sep 2025", "Wed 3 Sep 2025")); assert_eq!((far.month.as_str(), far.month_title.as_str(), same.month_title.as_str()), ("2025-09", "September 2025", "October")); assert_eq!(day("2026-09-30T08:00:00+05:30").recent, "Yesterday");let range = |from: &str, until: Option<&str>| day_range(Moment::parse(from, IST).unwrap(), until.map(|until| Moment::parse(until, IST).unwrap()), today, DateWords::shipped()); assert_eq!(range("2026-07-01", Some("2026-07-31")), "1 Jul \u{2013} 31 Jul 2026"); assert_eq!(range("2025-12-20", Some("2026-01-19")), "20 Dec 2025 \u{2013} 19 Jan 2026"); assert_eq!(range("2026-03-14", Some("2026-03-14")), "14 March"); assert_eq!(range("2026-03-14", None), "14 March");let yearly = |text: &str| yearly_parts(text, IST, today, DateWords::shipped()).unwrap();let born = yearly("1992-08-17"); assert_eq!((born.yearly.as_deref(), born.day.as_str()), (Some("Turns 35 on Tue 17 Aug"), "2027-08-17")); assert_eq!(yearly("--10-02").yearly.as_deref(), Some("Birthday Fri 2 Oct")); assert_eq!(yearly("--10-02").yearly_card.as_deref(), Some("tomorrow")); assert_eq!(born.yearly_card.as_deref(), Some("turns 35 in 320 days"));let today_born = yearly("1990-10-01"); assert_eq!((today_born.yearly.as_deref(), today_born.near.as_deref()), (Some("Turns 36 on Thu 1 Oct"), Some("Today")), "today counts as next"); assert_eq!((same.weekday_name.as_str(), same.day_long.as_str(), far.day_long.as_str()), ("Thursday", "1 October", "3 September 2025"));}/// THE FORM KEY (contract 6): a slip's `forms`, its caption's `form` and a/// field card's `form` each say the column in the named form, through the/// line sets — the definition names the form, never a format.#[test]fn a_named_form_says_the_column_in_it() {let definition: TableDefinition = serde_json::from_value(json!({"id": "invented_ledger", "name": "Ledger", "plural": "Ledgers", "picture": null, "builtin": false, "engine": null,"title": "title", "date": null, "project": null, "order": null,"slip": { "title": "title", "subtitle": ["due_at", "visits", "spent"], "trailing": null, "photo": null, "toggle": null,"forms": {"due_at": "late", "visits": "count", "spent": "duration"},"caption": {"dates": ["next_at"], "form": "weekday_date"} },"tile": { "face": "slip-list" }, "page": [], "instructions": "Invented.","columns": [ {"key": "title", "type": "text"}, {"key": "currency", "type": "text"}, {"key": "due_at", "type": "date"}, {"key": "next_at", "type": "date"}, {"key": "born_on", "type": "date", "yearly": true}, {"key": "balance", "type": "amount", "currency": "currency"}, {"key": "visits", "type": "number"}, {"key": "spent", "type": "number"} ] })).unwrap();letmut definition = definition;letmut parts = definition.resolved_parts();let card = |column: &str, form: crate::definitions::Form| crate::definitions::parts::PartsCard { column: Some(column.into()), form: Some(form), ..Default::default() }; parts.cards = Some(vec![card("balance", crate::definitions::Form::MoneySigned), card("born_on", crate::definitions::Form::NextOccurrence)]); parts.strip = None; definition.parts = Some(parts); definition.validate().unwrap();let data = json!({"title": "Invented", "currency": "USD", "due_at": "2026-09-27", "next_at": "2026-10-23","born_on": "--10-13", "balance": 49900, "visits": 1204, "spent": 3840});let data = data.as_object().unwrap();let lines = resolve_slip_lines(&definition, data, Some(IST), Some(now()), false, crate::records::page::Words::shipped()); assert_eq!(lines.subtitle.as_deref(), Some("4 days late · 1,204 · 1 h 4 min")); assert_eq!(lines.caption.as_deref(), Some("Fri 23 Oct"));let words = column_words(&definition, data, Some(IST), Some(now()), crate::records::page::Words::shipped()); assert_eq!(words["balance"], "+$499"); assert_eq!(words["born_on"], "in 12 days");}/// The `since` form says the elapsed span alone — whole weeks behind the/// date, one/other by the count; under a week its relative day — so it reads/// right on any date (a last contact, a last done, a document received); the/// phrase around it is the reading tool's own line.#[test]fn since_says_whole_weeks_gone() {let definition: TableDefinition = serde_json::from_value(json!({"id": "invented_contact", "name": "Contact", "plural": "Contacts", "picture": null, "builtin": false, "engine": null,"title": "title", "date": null, "project": null, "order": null,"slip": { "title": "title", "subtitle": ["last_contact_at"], "trailing": null, "photo": null, "toggle": null,"forms": {"last_contact_at": "since"} },"tile": { "face": "slip-list" }, "page": [], "instructions": "Invented.","columns": [{"key": "title", "type": "text"}, {"key": "last_contact_at", "type": "date"}] })).unwrap(); definition.validate().unwrap();let said = |day: &str| {let data = json!({"title": "Invented", "last_contact_at": day}); resolve_slip_lines(&definition, data.as_object().unwrap(), Some(IST), Some(now()), false, crate::records::page::Words::shipped()).subtitle }; assert_eq!(said("2026-09-24").as_deref(), Some("1 week")); assert_eq!(said("2026-09-10").as_deref(), Some("3 weeks")); assert_eq!(said("2026-09-28").as_deref(), Some("3 days ago"));}/// RULE: a face draws the core's count, size and clock (contract 7): a/// number grouped with its units picked by CLDR, a zero as its zero/// sentence, a `{n}` unit as the whole phrase, a size in bytes, a time on/// the house clock — never a figure the phone spelled.#[test]fn column_words_say_every_count_size_and_clock_a_face_draws() {let definition: TableDefinition = serde_json::from_value(json!({"id": "invented_shop", "name": "Shop", "plural": "Shops", "picture": null, "builtin": false, "engine": null,"title": "title", "date": null, "project": null, "order": null,"slip": { "title": "title", "subtitle": null, "trailing": null, "photo": null, "toggle": null },"tile": { "face": "slip-list" }, "page": [], "instructions": "Invented.","columns": [ {"key": "title", "type": "text"}, {"key": "orders", "type": "number", "units": {"one": "order", "other": "orders", "zero": "Sold out"}}, {"key": "one_order", "type": "number", "units": {"one": "order", "other": "orders"}}, {"key": "repeats", "type": "number", "units": {"one": "done once before", "other": "done {n} times before", "zero": ""}}, {"key": "visits", "type": "number"}, {"key": "size", "type": "bytes"}, {"key": "opens", "type": "time"} ] })).unwrap();let data = json!({"title": "Invented", "orders": 0, "one_order": 1, "repeats": 3, "visits": 1240, "size": 2100000, "opens": "18:30"});let words = column_words(&definition, data.as_object().unwrap(), Some(IST), Some(now()), crate::records::page::Words::shipped()); assert_eq!(words["orders"], "Sold out"); assert_eq!(words["one_order"], "1 order"); assert_eq!(words["repeats"], "done 3 times before"); assert_eq!(words["visits"], "1,240"); assert_eq!(words["size"], "2.1 MB"); assert_eq!(words["opens"], "6:30 pm");let parts = number_parts(&definition, data.as_object().unwrap()); assert_eq!(parts["visits"], json!({"figure": "1.24K", "unit": ""})); assert_eq!(parts["one_order"], json!({"figure": "1", "unit": "order"})); assert_eq!(parts["orders"], json!({"figure": "0", "unit": "Sold out"})); assert_eq!(parts["repeats"], json!({"figure": "3", "unit": "done times before"})); assert_eq!((compact_figure(4200.0), compact_figure(12_000.0), compact_figure(1_500_000.0), compact_figure(999.0)), ("4.2K".into(), "12K".into(), "1.5M".into(), "999".into()));}/// A duration's units are `dates.duration` lines picked by their count: the/// kit keeps the short look ("1 h 4 min"), and "1 hour" is a row, not a build.#[test]fn a_duration_says_its_units_as_lines() {let kit = DateWords::shipped(); assert_eq!(kit.duration(3_840_000).as_deref(), Some("1 h 4 min")); assert_eq!(kit.duration(9_000_000).as_deref(), Some("2 h 30 min")); assert_eq!(kit.duration(42_000).as_deref(), Some("42 s")); assert_eq!(kit.duration(1_500).as_deref(), Some("1.5 s")); assert_eq!(kit.duration(0), None);let row = |line: &str, words: &str| crate::rules::shell_lines::LineRow { set: "dates".into(), line: line.into(), words: words.into() };let reworded = DateWords::of_rows(&[row("duration.hours.one", "{n} hour"), row("duration.hours.other", "{n} hours")]); assert_eq!(reworded.duration(3_600_000).as_deref(), Some("1 hour")); assert_eq!(reworded.duration(9_000_000).as_deref(), Some("2 hours 30 min"));}#[test]fn a_reads_stamps_carry_their_day_parts_beside_them() {let now = chrono::DateTime::parse_from_rfc3339("2026-10-14T10:03:00Z").unwrap().with_timezone(&chrono::Utc);letmut object = json!({"lastSeenAt": "2026-10-14T09:58:00Z","syncedAt": "2026-10-14T07:00:00Z","createdAt": "2026-10-13T08:00:00Z","since": "2026-08-17","name": "not a date", });let object = object.as_object_mut().unwrap(); attach_stamp_parts(object, &["lastSeenAt", "syncedAt", "createdAt", "since", "name", "missing"], "UTC", now, DateWords::shipped());let parts = &object["@day_parts"]; assert_eq!(parts["lastSeenAt"]["ago"], "5 min ago"); assert_eq!(parts["syncedAt"]["ago"], "3 h ago"); assert_eq!(parts["syncedAt"]["full"], "Wed 14 Oct \u{b7} 7:00 am"); assert_eq!(parts["createdAt"]["recent"], "Yesterday"); assert_eq!(parts["since"]["full"], "Mon 17 Aug"); assert!(parts["since"].get("ago").is_none()); assert!(parts.get("name").is_none() && parts.get("missing").is_none());}#[test]fn a_signed_amount_says_who_owes_whom_once_per_currency() {let definition: TableDefinition = serde_json::from_value(json!({"id": "invented_ledger", "name": "Friend", "plural": "Friends", "picture": null, "builtin": false, "engine": null,"title": "title", "date": null, "project": null, "order": null,"slip": { "title": "title", "subtitle": null, "trailing": null, "photo": null, "toggle": null },"tile": { "face": "slip-list" }, "page": [], "instructions": "Invented.","columns": [ {"key": "title", "type": "text"}, {"key": "balance", "type": "amount", "signs": {"positive": "{first} owes you", "negative": "You owe {first}", "zero": "You're square."}} ] })).unwrap();let said = |balance: Value| {let data = json!({"title": "Example Person", "balance": balance}); column_words(&definition, data.as_object().unwrap(), Some(IST), Some(now()), crate::records::page::Words::shipped())["balance"].clone() }; assert_eq!(said(json!({"minor": 120000, "currency": "INR"})), "Example owes you \u{20b9}1,200"); assert_eq!(said(json!([{"minor": -30000, "currency": "INR"}, {"minor": 0, "currency": "EUR"}])), "You owe Example \u{20b9}300 \u{b7} You're square.");}/// THE SHORT REF FORM: a record id is said as "#" and its four Crockford/// characters through the `ident` set — the same id, the same ref.#[test]fn a_short_ref_form_says_the_ids_reference() {let id = "0193f2a4-7c1e-7b2d-9f00-3a4b5c6d7e8f";let reference = crate::transforms::short_ref::short_ref(id);let said = Words::shipped().short_ref(id); assert_eq!(said, format!("#{}", reference.as_str())); assert_eq!(said, Words::shipped().short_ref(id));let definition: TableDefinition = serde_json::from_value(json!({"id": "invented_task", "name": "Task", "plural": "Tasks", "picture": null, "builtin": false, "engine": null,"title": "title", "date": null, "project": null, "order": null,"slip": { "title": "title", "subtitle": ["parent"], "trailing": null, "photo": null, "toggle": null, "forms": {"parent": "short_ref"} },"tile": { "face": "slip-list" }, "page": [], "instructions": "Invented.","columns": [{"key": "title", "type": "text"}, {"key": "parent", "type": "text"}, {"key": "due_at", "type": "date"}] })).unwrap(); definition.validate().unwrap();let data = json!({"title": "Invented", "parent": id});let lines = resolve_slip_lines(&definition, data.as_object().unwrap(), Some(IST), Some(now()), false, Words::shipped()); assert_eq!(lines.subtitle.as_deref(), Some(said.as_str()));letmut wrong = definition.clone(); wrong.slip.forms = Some(serde_json::from_value(json!({"due_at": "short_ref"})).unwrap()); assert!(wrong.validate().is_err(), "a short ref reads an id, not a date");}/// GUARD (database-first, architect 22 Oct): a database's own rewording of/// the clock and duration lines is the one said — on a record named by its/// clock time ("the 7:00 am alarm"), in a receipt, and on a duration/// column's own reading — never the kit's beside it. A reader that took the/// kit's words would leave a person's rewording unseen on that one surface.#[test]fn a_databases_clock_and_duration_lines_are_the_ones_said() {let definition: TableDefinition = serde_json::from_value(json!({"id": "invented_alarm", "name": "Alarm", "plural": "Alarms", "picture": null, "builtin": false, "engine": null,"title": "label", "date": null, "project": null, "order": null,"slip": { "title": "label", "subtitle": "at", "trailing": null, "photo": null, "toggle": null },"tile": { "face": "slip-list" }, "page": [], "instructions": "Invented.","columns": [ {"key": "label", "type": "text"}, {"key": "at", "type": "time"}, {"key": "length", "type": "number", "format": "duration"} ] })).unwrap();let row = |line: &str, words: &str| crate::rules::shell_lines::LineRow { set: "dates".into(), line: line.into(), words: words.into() };let words = Words::of_rows(&[row("clock.am", "{hour}.{minute} in the morning"), row("duration.hours.one", "{n} hour")]);let data = json!({"at": "07:00", "length": 3600}); assert_eq!(crate::records::receipt::record_name(&definition, &data), "the 7:00 am alarm", "the kit, where no database is at hand"); assert_eq!(crate::records::receipt::record_name_in(&definition, &data, &words.dates), "the 7.00 in the morning alarm");let removed = crate::records::receipt::removed(&definition, &data, &words.dates, crate::records::receipt::ReceiptWords::shipped()); assert!(removed.said.contains("7.00 in the morning"), "{}", removed.said);let column = definition.column("length").unwrap(); assert_eq!(fact_words(&definition, column, &data["length"], data.as_object().unwrap(), None, None, &words).as_deref(), Some("1 hour"));}/// RULE: a repeat rule column reads as the core's words in `column_words` — its labels first, else the preset the rule is (Recurrence.presetForRrule's vectors: an RRULE: prefix, any case) — so no face spells an RRULE.#[test]fn column_words_say_a_repeat_rule() {let definition: TableDefinition = serde_json::from_value(json!({"id": "invented_chore", "name": "Chore", "plural": "Chores", "picture": null, "builtin": false, "engine": null,"title": "title", "date": null, "project": null, "order": null,"slip": { "title": "title", "subtitle": null, "trailing": null, "photo": null, "toggle": null },"tile": { "face": "slip-list" }, "page": [], "instructions": "Invented.","columns": [ {"key": "title", "type": "text"}, {"key": "rule", "type": "text", "format": "repeat-rule"}, {"key": "named", "type": "text", "format": "repeat-rule", "labels": {"weekly": "Every Sunday"}} ] })).unwrap(); assert!(reads_column_words(&definition));let said = |rule: &str, column: &str| {let data = json!({"title": "Invented", column: rule}); column_words(&definition, data.as_object().unwrap(), Some(IST), Some(now()), crate::records::page::Words::shipped())[column].clone() };for (rule, words) in [ ("FREQ=DAILY", "Daily"), ("RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR", "Every weekday"), ("freq=weekly", "Weekly"), ("FREQ=WEEKLY;INTERVAL=2", "Every two weeks"), ("FREQ=MONTHLY", "Monthly"), ("FREQ=YEARLY", "Yearly"), ("FREQ=MONTHLY;BYMONTHDAY=2", "Custom"), ] { assert_eq!(said(rule, "rule"), words, "{rule}"); } assert_eq!(said("FREQ=WEEKLY", "named"), "Every Sunday");}/// RULE: their clock is said only when their zone's offset at the instant differs from the reader's.#[test]fn their_time_is_said_only_when_the_offsets_differ() {let dates = DateWords::shipped();// 10:00 in India is 21:30 the evening before in Los Angeles (PDT, 1 Oct). assert_eq!(their_time(LA, IST, now(), dates), Some(dates.clock(21, 30))); assert_eq!(their_time(IST, LA, now(), dates), Some(dates.clock(10, 0)));// One clock under two names says nothing. assert_eq!(their_time("Asia/Calcutta", IST, now(), dates), None); assert_eq!(their_time(IST, IST, now(), dates), None);// London and Lisbon agree; London and New York differ. assert_eq!(their_time("Europe/Lisbon", "Europe/London", now(), dates), None); assert!(their_time("America/New_York", "Europe/London", now(), dates).is_some());// A zone nobody can place, or none, says nothing. assert_eq!(their_time("Invented/Nowhere", IST, now(), dates), None); assert_eq!(their_time(" ", IST, now(), dates), None);}/// RULE: a `zone` column reads in @column_words as their clock, against the ask's zone.#[test]fn a_zone_column_reads_as_their_clock() {letmut definition = builtin_table_definition("person").unwrap().clone();let column = definition.columns.iter_mut().find(|column| column.zone == Some(true)).expect("the person table keeps a zone");let key = column.key.clone();let words = Words::shipped();let data: Map<String, Value> = [(key.clone(), json!(LA))].into_iter().collect();let said = column_words(&definition, &data, Some(IST), Some(now()), words); assert_eq!(said[&key], json!(words.dates.clock(21, 30)));let same = column_words(&definition, &data, Some(LA), Some(now()), words); assert_eq!(same[&key], Value::Null, "their clock is the reader's"); definition.columns.retain(|column| column.key == key); assert!(reads_column_words(&definition));}/// RULE: A quiet day reads an instant in the named zone, a day-only or zoneless value as written, and answers nothing for a value or zone that is not one.#[test]fn a_quiet_day_is_read_in_the_named_zone() {let cases: [(&str, &str, Option<&str>); 9] = [ ("2026-08-20T07:00:00.000Z", "UTC", Some("Thu 20 Aug")), ("2026-08-20T23:30:00.000Z", "Asia/Kolkata", Some("Fri 21 Aug")), ("2026-08-20T02:00:00.000Z", "America/New_York", Some("Wed 19 Aug")), ("2026-01-01", "Pacific/Chatham", Some("Thu 1 Jan")), ("2026-12-31T23:00:00", "Asia/Kolkata", Some("Thu 31 Dec")), ("2026-02-30", "UTC", None), ("yesterday", "UTC", None), ("2026-08-20T07:00:00.000Z", "Mars/Olympus", None), ("2026-08-20", "Mars/Olympus", None), ];for (iso, zone, expected) in cases {let said = day_of_iso(iso, zone).map(|day| DateWords::shipped().weekday_date(day, 2026)); assert_eq!(said.as_deref(), expected, "{iso} in {zone}"); }}