Functional Weave
Code in TypeScript

form.date-parts@1.0.1

vectors.json

14,750 bytes · view raw

[
  {"name": "a whole date, GOV.UK's example 27 3 2007", "args": [{"day": "27", "month": "3", "year": "2007"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": true, "date": "2007-03-27", "message": null, "fields": []}},
  {"name": "spaces and a trailing newline are trimmed from every box", "args": [{"day": " 27 ", "month": "3 ", "year": "2007\n"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": true, "date": "2007-03-27", "message": null, "fields": []}},
  {"name": "a leading zero or none: 02 and 2 are both February", "args": [{"day": "02", "month": "2", "year": "2024"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": true, "date": "2024-02-02", "message": null, "fields": []}},
  {"name": "29 February in a leap year", "args": [{"day": "29", "month": "2", "year": "2024"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": true, "date": "2024-02-29", "message": null, "fields": []}},
  {"name": "29 February 2023 does not exist: the day is marked", "args": [{"day": "29", "month": "2", "year": "2023"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Date of birth must be a real date", "fields": ["day"]}},
  {"name": "1900 was not a leap year, though 1900 % 4 is 0", "args": [{"day": "29", "month": "02", "year": "1900"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Date of birth must be a real date", "fields": ["day"]}},
  {"name": "2000 was a leap year", "args": [{"day": "29", "month": "2", "year": "2000"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": true, "date": "2000-02-29", "message": null, "fields": []}},
  {"name": "31 April does not exist", "args": [{"day": "31", "month": "4", "year": "2026"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Date of birth must be a real date", "fields": ["day"]}},
  {"name": "31 December is the last day", "args": [{"day": "31", "month": "12", "year": "1999"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": true, "date": "1999-12-31", "message": null, "fields": []}},
  {"name": "nothing entered: Enter, with the label in lower case, and the whole date marked", "args": [{"day": "", "month": " ", "year": ""}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Enter date of birth", "fields": ["day", "month", "year"]}},
  {"name": "a missing month", "args": [{"day": "27", "month": "", "year": "2007"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Date of birth must include a month", "fields": ["month"]}},
  {"name": "a missing day and year", "args": [{"day": "", "month": "3", "year": " "}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Date of birth must include a day and year", "fields": ["day", "year"]}},
  {"name": "a missing day and month, GOV.UK's example", "args": [{"day": "", "month": "", "year": "2007"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Date of birth must include a day and month", "fields": ["day", "month"]}},
  {"name": "a two-digit year is incomplete", "args": [{"day": "27", "month": "3", "year": "07"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Year must include 4 numbers", "fields": ["year"]}},
  {"name": "a five-digit year is not 4 numbers either", "args": [{"day": "27", "month": "3", "year": "20077"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Year must include 4 numbers", "fields": ["year"]}},
  {"name": "missing information comes before an incomplete year", "args": [{"day": "", "month": "3", "year": "07"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Date of birth must include a day", "fields": ["day"]}},
  {"name": "an incomplete year comes before an impossible day", "args": [{"day": "32", "month": "3", "year": "07"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Year must include 4 numbers", "fields": ["year"]}},
  {"name": "month 13 cannot be correct", "args": [{"day": "27", "month": "13", "year": "2007"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Date of birth must be a real date", "fields": ["month"]}},
  {"name": "day 0 cannot be correct", "args": [{"day": "0", "month": "3", "year": "2007"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Date of birth must be a real date", "fields": ["day"]}},
  {"name": "two wrong boxes: the whole date is marked", "args": [{"day": "32", "month": "13", "year": "2007"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Date of birth must be a real date", "fields": ["day", "month", "year"]}},
  {"name": "letters in the year", "args": [{"day": "27", "month": "3", "year": "20o7"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Date of birth must be a real date", "fields": ["year"]}},
  {"name": "year 0000 does not exist", "args": [{"day": "1", "month": "1", "year": "0000"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Date of birth must be a real date", "fields": ["year"]}},
  {"name": "three digits in the day", "args": [{"day": "027", "month": "3", "year": "2007"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Date of birth must be a real date", "fields": ["day"]}},
  {"name": "an Arabic-Indic digit is not a day in any of the languages", "args": [{"day": "٢", "month": "3", "year": "2007"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Date of birth must be a real date", "fields": ["day"]}},
  {"name": "a month name in full, any case", "args": [{"day": "5", "month": "January", "year": "2026"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": true, "date": "2026-01-05", "message": null, "fields": []}},
  {"name": "a short month name", "args": [{"day": "5", "month": "jan", "year": "2026"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": true, "date": "2026-01-05", "message": null, "fields": []}},
  {"name": "SEPT is September", "args": [{"day": "9", "month": "SEPT", "year": "2026"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": true, "date": "2026-09-09", "message": null, "fields": []}},
  {"name": "a month name cut at four letters is not one", "args": [{"day": "5", "month": "Janu", "year": "2026"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Date of birth must be a real date", "fields": ["month"]}},
  {"name": "in the past: today is not in the past", "args": [{"day": "28", "month": "9", "year": "2026"}, "Date of birth", {"today": "2026-09-28", "timing": "past", "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Date of birth must be in the past", "fields": ["day", "month", "year"]}},
  {"name": "in the past: yesterday is", "args": [{"day": "27", "month": "9", "year": "2026"}, "Date of birth", {"today": "2026-09-28", "timing": "past", "notBefore": null, "notAfter": null}], "expect": {"valid": true, "date": "2026-09-27", "message": null, "fields": []}},
  {"name": "today or in the past: today is allowed", "args": [{"day": "28", "month": "9", "year": "2026"}, "Date of birth", {"today": "2026-09-28", "timing": "past-or-today", "notBefore": null, "notAfter": null}], "expect": {"valid": true, "date": "2026-09-28", "message": null, "fields": []}},
  {"name": "today or in the past: tomorrow is not", "args": [{"day": "29", "month": "9", "year": "2026"}, "Date of birth", {"today": "2026-09-28", "timing": "past-or-today", "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Date of birth must be today or in the past", "fields": ["day", "month", "year"]}},
  {"name": "in the future, GOV.UK's example label", "args": [{"day": "28", "month": "9", "year": "2026"}, "The date your course ends", {"today": "2026-09-28", "timing": "future", "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "The date your course ends must be in the future", "fields": ["day", "month", "year"]}},
  {"name": "today or in the future: yesterday is not", "args": [{"day": "27", "month": "9", "year": "2026"}, "The date your course ends", {"today": "2026-09-28", "timing": "future-or-today", "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "The date your course ends must be today or in the future", "fields": ["day", "month", "year"]}},
  {"name": "today or in the future: today is", "args": [{"day": "28", "month": "9", "year": "2026"}, "The date your course ends", {"today": "2026-09-28", "timing": "future-or-today", "notBefore": null, "notAfter": null}], "expect": {"valid": true, "date": "2026-09-28", "message": null, "fields": []}},
  {"name": "timing any ignores today", "args": [{"day": "1", "month": "1", "year": "2099"}, "Date of birth", {"today": "2026-09-28", "timing": "any", "notBefore": null, "notAfter": null}], "expect": {"valid": true, "date": "2099-01-01", "message": null, "fields": []}},
  {"name": "between two dates, GOV.UK's example", "args": [{"day": "1", "month": "10", "year": "2017"}, "The date your contract started", {"today": null, "timing": null, "notBefore": "2017-09-01", "notAfter": "2017-09-30"}], "expect": {"valid": false, "date": null, "message": "The date your contract started must be between 1 September 2017 and 30 September 2017", "fields": ["day", "month", "year"]}},
  {"name": "between is inclusive at both ends", "args": [{"day": "30", "month": "9", "year": "2017"}, "The date your contract started", {"today": null, "timing": null, "notBefore": "2017-09-01", "notAfter": "2017-09-30"}], "expect": {"valid": true, "date": "2017-09-30", "message": null, "fields": []}},
  {"name": "not before a date", "args": [{"day": "31", "month": "8", "year": "2017"}, "The date your course ends", {"today": null, "timing": null, "notBefore": "2017-09-01", "notAfter": null}], "expect": {"valid": false, "date": null, "message": "The date your course ends must be the same as or after 1 September 2017", "fields": ["day", "month", "year"]}},
  {"name": "not after a date", "args": [{"day": "1", "month": "9", "year": "2017"}, "The date of the last exam", {"today": null, "timing": null, "notBefore": null, "notAfter": "2017-08-31"}], "expect": {"valid": false, "date": null, "message": "The date of the last exam must be the same as or before 31 August 2017", "fields": ["day", "month", "year"]}},
  {"name": "a bound on the day itself is allowed", "args": [{"day": "31", "month": "8", "year": "2017"}, "The date of the last exam", {"today": null, "timing": null, "notBefore": null, "notAfter": "2017-08-31"}], "expect": {"valid": true, "date": "2017-08-31", "message": null, "fields": []}},
  {"name": "a real-date problem comes before a rule", "args": [{"day": "31", "month": "4", "year": "2017"}, "The date of the last exam", {"today": null, "timing": null, "notBefore": null, "notAfter": "2017-08-31"}], "expect": {"valid": false, "date": null, "message": "The date of the last exam must be a real date", "fields": ["day"]}},
  {"name": "a label that starts with an acronym keeps its capitals after Enter", "args": [{"day": "", "month": "", "year": ""}, "UK arrival date", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Enter UK arrival date", "fields": ["day", "month", "year"]}},
  {"name": "the label is trimmed", "args": [{"day": "", "month": "3", "year": "2007"}, "  Date of birth ", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expect": {"valid": false, "date": null, "message": "Date of birth must include a day", "fields": ["day"]}},
  {"name": "a timing rule needs today", "args": [{"day": "1", "month": "1", "year": "2000"}, "Date of birth", {"today": null, "timing": "past", "notBefore": null, "notAfter": null}], "expectError": "rules.today is needed to check that a date is past"},
  {"name": "a malformed bound is refused", "args": [{"day": "1", "month": "1", "year": "2000"}, "Date of birth", {"today": null, "timing": null, "notBefore": "2017-9-1", "notAfter": null}], "expectError": "\"2017-9-1\" is not an ISO date"},
  {"name": "a bound that cannot exist is refused", "args": [{"day": "1", "month": "1", "year": "2000"}, "Date of birth", {"today": null, "timing": null, "notBefore": null, "notAfter": "2017-02-30"}], "expectError": "\"2017-02-30\" is not a real calendar date"},
  {"name": "notBefore after notAfter is refused", "args": [{"day": "1", "month": "1", "year": "2000"}, "Date of birth", {"today": null, "timing": null, "notBefore": "2018-01-01", "notAfter": "2017-01-01"}], "expectError": "rules.notBefore (2018-01-01) must not be after rules.notAfter (2017-01-01)"},
  {"name": "an empty label is refused", "args": [{"day": "1", "month": "1", "year": "2000"}, " ", {"today": null, "timing": null, "notBefore": null, "notAfter": null}], "expectError": "a date needs a label"}
]