Examples
Natural date input
Built with the mantine-combobox skill
TASK DETAILS
Set a due date
Write it the way you would say it — “next Friday” or “in 3 weeks at noon”.
No due date yet
Selected value
null
Build a due date input for a task app where users type dates in plain English.
Phrases the input understands (case-insensitive, without a parsing library):
- today, tomorrow, yesterday
- weekday names, full or short ("fri", "friday" = the next such day, "next friday" = that day of the next week)
- "in N days / weeks / months", "N days from now"
- "next week" (Monday of the next week), "next month" (the 1st of the next month), "end of week" (Sunday), "end of month"
- dates such as "mar 5", "5 march", "march 5 2027", "2027-03-05" and "3/5" (month/day); a date without a year is the next such date
- an optional time after any of the above: "at 3pm", "3:30pm", "15:30", "noon", "midnight"; without a time the task is due at the end of the day (no time shown)
- weeks start on Monday
Suggestions:
- while typing, up to 5 suggestions complete the text: "ne" suggests "next week", "next month", "next monday"…; "3" suggests "in 3 days", "in 3 weeks", "3pm today"…; "fri 5" suggests "friday at 5pm" and "friday at 5am"
- every suggestion shows the phrase, the date it resolves to ("Fri, Oct 30, 3:00 PM") and how far away it is ("in 4 days")
- focusing the empty input shows presets: Today, Tomorrow, Next week, End of month
- text that does not parse shows "Could not understand “…”" instead of suggestions
Value:
- picking a suggestion, or pressing Enter when the text parses, sets the value; the input then shows the formatted date
- focusing an input that has a value selects its text so the user can type over it
- blur with text that does not parse shows an error and keeps the previous value; blur with empty text clears the value
- a date in the past is allowed but shows a warning under the input ("This date is in the past")
- clear button
- the component takes
value,onChange(Date | null) andlabel; render it with the label "Due date" and show the selected value as an ISO string under it
Write tests for the component and for the parser.