Skip to content

Make typing dates and times easier: parsers and refusals (#200, 1/3) - #215

Open
NinjaLikesCheez wants to merge 3 commits into
mainfrom
time-input-parsers
Open

NinjaLikesCheez wants to merge 3 commits into
mainfrom
time-input-parsers

Conversation

@NinjaLikesCheez

@NinjaLikesCheez NinjaLikesCheez commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

First PR of the stack for #200 (spec: #200 (comment)). Merges first; PR 2 (live autocomplete preview) and PR 3 (every input on the shared pieces, consistent form text) stack on it.

What changes

More ways to type a moment (src/core/when.ts). This works everywhere parseWhen is used today (/schedule, /admin → Parking):

  • in 30 minutes, in 2 hours, in 3 days (like now+…). in followed by anything other than a duration is read as before (in oct 14).
  • Ordinals: 14th oct, oct 1st, 22nd of october. On its own, the 3rd is the next 3rd: this month's if it's still to come, otherwise the next month that has that day.
  • noon / midday (12:00) and midnight (00:00 at the end of its day, so fri midnight is Sat 00:00).
  • tonight, this evening, fri evening, sat night: 19:00, or the time given read as an evening time (tonight 8 is 20:00). A time outside 17:00–23:59 is refused (tonight 9am, tonight 2), not guessed.
  • Behaviour change: next fri is Friday of next week (weeks start on Monday). fri / this fri is the coming one. next before anything but a weekday is refused.
  • Words for a stretch of time (morning, afternoon, next week, this weekend, later) are refused as too vague.
  • A day and month that don't exist that year are refused with the reason (31 feb: "there's no 31 Feb 2027"). 29 feb is read like any date, this year's or next year's, so it works when that year is a leap year and is otherwise refused.
  • parseTimeOfDay also takes noon, midday and midnight (00:00). This covers poll reminders, the attendance totals time and the parking reset (including resetAt in the spots file).

Why it refused (readWhen): empty, unclear, past (with what it understood), before-start (not after a later reference, such as Until before From), no-such-date (31 Feb 2027), vague, not-evening. parseWhen is now a thin wrapper around it.

How long (src/core/how-long.ts, new): readHowLong reads either a duration (45m, for 2 hours) or an end (until 17:00, till 5pm, to fri, 17:00), after a start. The duration is tried first, so 2h is never a time. Nothing calls it yet: PR 3 moves /park for, /admin parking for and the poll duration onto it.

One refusal message (src/core/time-help.ts, new): the field, the reason when it's known, and examples that work. For example:

When: that's Mon 12 Oct 2026, 09:00, which has already passed. Type a day, a time or both in Europe/Amsterdam, for example 19:00, fri 8pm, 14th oct, tomorrow noon or in 2 hours.

It now replaces the hand-written messages for /schedule When, Remind every day at and Totals so far at, and for /admin → Parking From, Until (that isn't after it starts when Until falls before a later From) and Reset.

Docs: docs/architecture.md (When) and docs/commands.md (/schedule). The changelog has an Added entry and a Changed entry for next fri.

Review

Only src/core/when.ts, plus two new core/ files. Nothing on the rule 14 list is touched, but it's core/ code every time input depends on, so a careful human review is welcome.

Testing

  • just check passes: 3,147 tests, coverage thresholds met (when.ts 99.5% of lines).
  • New tests: tests/core/how-long.test.ts, tests/core/time-help.test.ts, and new cases in tests/core/when.test.ts for every form above, every refusal reason, leap years, month rollovers and next week from a Sunday.
  • Updated tests: the old refusal text in schedules, admin/parking and parking-panel. Two tests used midnight as an invalid reset and now use teatime.

Part of #200.

🤖 Generated with Claude Code

First of a stack for #200. Adds the shared pieces every time input will use:

- core/when.ts reads more forms: "in 30 minutes", ordinals ("14th oct",
  "the 3rd"), noon/midnight, tonight/evening ("tonight 8" is 20:00), and
  "next fri" as Friday of next week. Vague words (morning, next week) are
  refused. readWhen says why it refused.
- core/how-long.ts reads a duration or an end ("until 17:00").
- core/time-help.ts gives one refusal message per kind of input: the
  field, the reason and examples that work. /schedule and /admin parking
  use it now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread src/core/when.ts Resolved
Comment thread src/core/when.ts Resolved
Saves each caller (how long, /admin parking until, the coming suggestions)
mapping it themselves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Merged main (20a167f) into this branch: CHANGELOG.md was the only conflict, and both sides' [Unreleased] entries are kept. Pull before pushing again. GitHub doesn't start CI for this bot's pushes, so CI hasn't run on it: push again, or close and reopen the PR.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant