Skip to content

Routing: rule condition "time" with a weekday and time-of-day editor - #314

Closed
fylorn wants to merge 1 commit into
devfrom
feat/rule-time-condition
Closed

fylorn wants to merge 1 commit into
devfrom
feat/rule-time-condition

Conversation

@fylorn

@fylorn fylorn commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

What

A rule can be limited to time windows of the gateway machine's local clock (contract A, lite side).

  • Rule editor: a new condition kind 「时段」 / "Time" with seven weekday toggles (Monday first, all on by default) and start / end time inputs (09:00–18:00 by default). Each window becomes one value in core's grammar — mon-fri 09:00-18:00, sat,sun 00:00-24:00, 22:00-06:00; consecutive days collapse into a range (three or more; two days stay sat,sun), ranges may wrap (fri-mon), the day part is omitted when all seven are on. "Add time window" adds another value; several windows are matched like the other multi-value conditions. Existing values are parsed back into the picker (case-insensitive, lenient whitespace, 9:00); a value that does not parse is shown as raw text that can still be edited or removed. Overnight windows show 「次日」 / "next day" beside the end time.
  • Validation: no day selected or a malformed time is reported beside the save button (条件「时段」须选择至少一天,时间写成 HH:MM,示例:09:00), never silently written as "every day". 9:00 is normalised to 09:00 on blur; 24:00 is accepted as an end.
  • Summaries: route-dialog rule rows and dry-run mismatch lines read the value as a sentence — 时段 周一至周五 09:00–18:00 或 22:00–次日 06:00 / Time Mon–Fri 09:00–18:00 or 22:00–06:00 next day. The dry run's "actual" value is read the same way when core sends it as <day> HH:MM (e.g. fri 16:42 → 周五 16:42); any other form is shown as is.
  • Pure module src/routing/timeWindow.ts (parse / format / describe) with tests: grammar round trips, normalisation, wrapping day ranges, overnight, 24:00, malformed input, zh / en wording.

Depends on

The core PR for the time condition (contract A): ConditionField::Time, the local-time fact in RequestFacts, and the config.rule_time_syntax validation. Until it lands, saving a rule with this condition is refused by core as an unknown field.

src/generated/tw-api.ts gains "time" in ConditionField by hand (and nothing else); the file is regenerated as usual when the core tag is moved.

Verified

  • pnpm typecheck — passes.
  • pnpm test — 103 files, 1076 tests pass (31 new in timeWindow.test.ts, 2 new cases in labels.test.ts).
  • Isolated preview harness, headless Chromium: add a rule with a time condition in zh and en (two windows, weekend off, overnight), save it and read the rule row (时段 周一至周五 09:00–18:00 或 22:00–次日 06:00), the no-day error in the footer, blur normalisation and the invalid marking of a half-typed time.

Not covered

  • No screenshot regeneration (docs/screenshots); the dry-run dialog has no time input since core evaluates with the current time.
  • The dry-run "actual" format (fri 16:42) is an assumption about the core PR; other forms fall back to the raw string.

🤖 Generated with Claude Code

…ditor

A rule can now be limited to time windows of the gateway machine's
local clock: the new condition kind "Time" in the rule editor has
seven weekday toggles (Monday first, all on by default) and a start
and end time (09:00–18:00 by default), and each window becomes one
value in core's grammar (`mon-fri 09:00-18:00`, `sat,sun 00:00-24:00`,
`22:00-06:00`). Several windows are several values, matched like the
other multi-value conditions.

Values written by hand are parsed back into the editor; one that does
not parse is shown as raw text that can still be edited or removed.
The editor keeps its rows as its own state and derives the values
from them, rather than re-parsing on every change: a half-typed time
would otherwise fail to parse and turn the row into the raw fallback
mid-edit. A row with no day selected or an unparseable time writes a
value that does not parse on purpose, so the save button reports it
instead of silently meaning "every day".

Wherever conditions are summarised (route rules, dry-run mismatches)
the value reads as a sentence: 周一至周五 09:00–18:00 / Mon–Fri
09:00–18:00, with overnight windows marked (22:00–次日 06:00 /
22:00–06:00 next day). The dry run's "actual" value (`fri 16:42`) is
read the same way.

`src/generated/tw-api.ts` gains `"time"` in `ConditionField` by hand;
the file is regenerated when the core tag is moved.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@fylorn

fylorn commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #315, which merged this branch together with the core v0.69.0 pin and the regenerated bindings; released in 2026.10.13. The red checks here were the control-plane tests running against the previously pinned core.

@fylorn fylorn closed this Oct 10, 2026
@fylorn
fylorn deleted the feat/rule-time-condition branch October 10, 2026 12:40
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