Repository navigation
feat(ui): pick a schedule with times of day and see its next runs - #4532
Merged
Merged
Conversation
Move the zone-free day arithmetic out of task-repeat.ts into lib/shared/calendar.ts so automation schedules can step through the same days a task does: the monthly 31st and yearly February 29 clamps, Monday-first weeks and the rule step. stepAfter is typed over a structural CalendarRule, and the "first named day, step ignored" expression becomes firstRuleDay, which firstTaskRepeatOccurrence now calls. The two dayjs midnights stay in task-repeat.ts; CalendarDate and weekdayOf keep their task-repeat re-exports, so no importer changes. New helpers for schedules: compareDates, monthsBetween, mondayOf, parseIsoDate and formatIsoDate. task-repeat.test.ts and task-repeat.ui-parity.test.ts pass unchanged.
lib/shared/zoned-time.ts turns a calendar day and a time of day into an instant in an IANA zone, the way Temporal's 'compatible' disambiguation and RFC 5545 do: a repeated time is its first instant, and a time the clock skips moves forward by the gap. zonedCandidates lists the 0, 1 or 2 instants a local time names, which the schedule preview marks as clock changes. Wall clocks are read through Intl with one cached formatter per zone; format() split by the positions formatToParts reports is about four times faster than formatToParts in Node. The test holds the resolver to a brute-force oracle (every quarter-hour instant within 15 hours whose wall clock shows the time): the 153 local times where Day.js and Luxon picked the later instant of a repeated hour, every 2020-2030 transition of eight zones with odd rules, and a seeded sample of 200 transition-adjacent times across every zone the runtime ships. A mutation that picks the later instant fails all three. canonicalTimeZone trims and spells a zone the way Intl does and refuses a blank one. task-repeat.ts now takes isTimeZone and localTimeZone from here (the same functions, moved), so its rule and the schedule's agree.
@tale/shared/schemas/schedule-rule is the one zod source for a schedule trigger's repeat rule. Day rules (daily, weekly, monthly, yearly) are the task repeat rule plus 1-12 "HH:MM" times; minutely and hourly are grids with intervals that divide an hour or a day, aligned to local midnight, with an optional window of weekdays and half-open hours that may run overnight (the tail after midnight belongs to its start day; "00:00" runs until midnight). Refusals carry stable dotted codes (schedule.time_format, times_required, times_too_many, interval_unsupported, month_day_impossible, window_hours_equal, window_never_fires), read with scheduleIssueCode; problems of shape keep zod's own code. normalizeScheduleRule gives one spelling per meaning (own keys, sorted unique times and weekdays, an all-day or every-day window dropped) and sameScheduleRule compares by it. The wall-clock grid arithmetic (gridMinuteAtOrAfter/Before, windowRangesOn) lives beside the rule so the never-fires check and the occurrence engine share one copy. Descriptions sit in .meta for the JSON Schema that MCP and OpenAPI will publish.
lib/automations/schedule/occurrences.ts is the one evaluator the scan, the save and the editor's preview will share. A schedule is a repeat rule or a cron expression in an IANA zone, in one of two daylight-saving classes: named times (day rules; cron with minute and hour spelled out) move forward over a gap and start once in a repeated hour, deduplicated when two land on one instant; grids (minutely and hourly rules; cron whose minute or hour starts with *) start at every instant whose local clock is on the grid, aligned to local midnight, so they keep their pace. Day rules jump by period from their first matching day on or after the start date, the task's phase rule, and a seeded property test holds 500 rules to the task series. Grid walks move by elapsed minutes and stop at a clock change found by bisection, so no start is jumped over; windows open up to two ranges per local day, the overnight tail belonging to its start day. upcomingOccurrences marks shiftedForward and repeatedHour starts for the preview; decideDue starts the latest pending occurrence (however late with 'latest', within ten minutes with 'skip') and counts the rest, capped at 1000; scheduleOfTrigger reads a row with a non-empty cron winning over a stored rule. The parse marks starred fields, and cronDstClass sorts an expression into its class. Nothing imports the module outside tests yet. occurrences.bench.ts records the cost per call as a note: means of 0.01-0.08 ms for nextOccurrence across the shapes it covers.
The grid walk jumps by elapsed minutes and, when a clock change falls inside a jump, restarts from the change. Comparing rules with their cron twins could not see that step, since both sides run the same walk. This test reads every whole minute within eight hours of the 2026 changes in Zurich, New York, Lord Howe and Kolkata, keeps those whose wall clock is on the grid and inside the window, and requires the forward and the backward walk to find exactly those, for minute and hour grids and two overnight windows. Every 2 hours in Zurich must start the repeated 02:00 on 25 October; removing either bisection fails the test.
cronToScheduleRule reads a cron expression as the repeat rule that starts at exactly the same instants, or answers null. A grid cron (minute or hour starting with *) becomes a minutely or hourly rule, a minute grid in a range of hours becomes a window that ends on the hour after the last one, and a named cron becomes a day rule with up to twelve times, so both sides stay in one daylight-saving class. A day of the month every Nth month becomes monthly/N phased from January (cronRuleStartDate). scheduleRuleToCron is the inverse and answers null where no single expression says the same: an overnight window or one off the hour, an hourly rule with a window, a day rule stepping more than one period (monthly steps phased from January excepted, given the start date), times that are not every pairing of some minutes and hours, the 29th to 31st every month, and February 29. A seeded property test turns 1,000 lossless rules into cron and holds both to the same starts around each 2026 clock change in Zurich, New York, Lord Howe and Kolkata, and the converted cron to the legacy scan matcher on ordinary days.
lib/automations/trigger-input.ts builds the input a trigger hands its run
from what the trigger knows (a schedule's occurrence, a webhook's body,
an event and its payload) and an optional fixed input, with the trigger's
own fields set over it. Without a fixed input the object equals the three
literals in triggers.ts byte for byte, key order and an event's absent
payload included, which the test pins. sampleTriggerFacts gives the facts
for a preview or Run now (a webhook sends {"example": true}), and
triggerInputIssues runs a compiled inputs check, leaving out problems
inside a webhook's payload since the body is unknown before a delivery.
The module stays free of a runtime Ajv import so the app can bundle it.
event-types.ts gains EventPayloads (what each emitted event carries),
EVENT_PAYLOAD_EXAMPLES, checked against it with satisfies, and
eventProjectId. The scan, the dispatch and the webhook door are not
switched to the builder yet.
fromUtc is only the inverse half of toUtc inside calendar.ts; nothing imports it, and knip reports the export as unused.
TimeField (@tale/ui/time-field) edits a time of day as segmented spin
buttons in the reader's hour cycle: "9:30 AM" in English, "09:30" in
German and French, or the cycle a host fixes. Like NumberStepper it
always holds a valid time. Each part is a tab stop; the arrows step and
wrap without carrying, Page Up/Down take 6 hours or 15 minutes, Home/End
jump to the ends, typing moves on once a part is complete, Backspace
clears a part while it is retyped, and a whole time pasted anywhere
("17:30", "5:30 pm", "17h30") replaces it. The wheel is ignored. The
parts are named and speak their values from the package catalog
(timeField.*), and stay at least 24px at every width.
@tale/ui/time-of-day holds the zone-free helpers it is built on: the
locale's hour cycle, formatting, day period words, part order, the paste
grammar, and comparing and clamping times.
Library gate (design UI §3.8): hand-rolled. A minimal react-aria 3.53.0
useTimeField + useDateSegment probe with react-stately and
@internationalized/date 3.12.4 bundles to 129.8 KB minified, 42.7 KB
gzip (bun build --minify, react external), against the 15 KB budget.
Its segment names and spoken values come from react-aria's own
dictionaries, and its empty-segment, null-value model is the one this
field rejects. Paste and styling would have passed.
The guide (components/time-field) has two live examples and links from
the input guide. The story locale helper moves to src/storybook so the
picker and field stories share it.
@tale/ui/recurrence-schedule is the design system's copy of the platform's schedule rule: a repeat rule plus "HH:MM" times of day, or a minutely or hourly grid with an optional window of weekdays and hours (overnight allowed, "00:00" until midnight). It normalizes and compares rules the way @tale/shared does, reads the six presets off a reference day and time (09:00 when none), says where a grid's first and last start fall inside its hours, or that none does, and holds the editor's draft: both custom views keep their own part, so switching loses nothing, and times stay in the author's order until the rule sorts them. formatSchedule and formatScheduleCompact word a rule as the design's worked examples do in English, German and French, on the locale's hour cycle or one the host fixes; formatOccurrence writes an upcoming start in its schedule's zone. useRecurrenceFormat gains schedule, scheduleCompact, time, occurrence and hourCycle, and the picker guide names them so no surface words a schedule on its own.
ScheduleOccurrenceList (@tale/ui/schedule-occurrence-list) shows the
next starts a host computed for a schedule: each written in the
schedule's zone ("Tue, Oct 13, 9:00 AM") under a heading that names the
zone, the reader's own time and date beside it when their zone reads
differently, or one closing line naming their zone in the compact
variant a popover uses. A start that meets a clock change carries a
Clock change badge and a sentence on the page saying whether the time
moved forward, ran at the first of a repeated hour, or kept its
real-time spacing. Muted rows, a count, the year only when it differs
and an empty state cover the host's other states. It does no zone
arithmetic of its own.
The guide (components/schedule-occurrence-list) shows both variants
around Zurich's 2026 clock changes with a fixed reader zone.
RecurrencePicker gains granularity="time", a discriminated mode for
schedules. Its presets run from every 15 minutes to monthly at the saved
rule's time; Custom interval builds a grid of N minutes or hours with a
minute past the hour, weekdays and optional hours (overnight allowed,
the hint naming the first and last start, Save blocked with its reason
when no start falls inside); Custom times is the day editor plus a list
of TimeFields that keeps the author's order while drafting and saves the
times sorted without repeats. The draft's next runs come from the host
through nextOccurrences and show in a compact ScheduleOccurrenceList.
allowNever={false} drops Never and makes value and onChange non-null
(typed through an AllowNever parameter, because TypeScript cannot narrow
a JSX union on an omitted allowNever). The views fade on switch, opacity
only and not under reduced motion, in time mode only.
Day mode keeps its props, DOM and emits: the session machine moves into
useRecurrenceSession and the trigger, rows and footer into shared parts
both modes draw, and every existing picker and editor test passes
unedited. A one-off DOM recording of the day picker in ten states (closed
with a rule, never, read-only, locked, disabled, outlined; open on the
presets, the Custom view by week and by month, dirty presets) taken
before the change matched after it; task-repeat-field.tsx typechecks
unedited.
The picker guide gains a schedule section with two live examples, the
stories eight schedule cases, and the package catalog the time-mode
strings in English, German and French.
@tale/ui/recurrence-schedule keeps a copy of the schedule rule because the design system cannot import the platform; this suite holds it to @tale/shared/schemas/schedule-rule. It enumerates what the time-mode picker can emit (every Custom interval step, minute past, weekday sample and window shape, every Custom times frequency, step and times list, and every preset off each day of a leap year at three times) and checks the schema stores each rule the picker lets you save, refuses exactly the windows the picker blocks and only as schedule.window_never_fires, never sees equal start and end hours, and receives every rule already normalized. Both sides normalize, compare and read "HH:MM" the same way, offer the same steps and limits, every day rule stays a task rule once its times are stripped, and the two types and the preview's starts are assignable both ways. Breaking the copy's window normalization or its overnight hint fails it.
A grid walk that found nothing left on the wall-clock day jumped to the next day's midnight, past a fall-back later that day, so the second pass of the repeated minutes never started. Zones whose clocks go back at midnight (Cairo, Santiago, Beirut) lost them with no window at all, and a window ending or starting inside a repeated hour lost them everywhere; the backward walk had the mirror fault, so a scan after an outage could neither start nor count them. Both walks now continue from the clock change when one falls inside the rest of the day. The by-definition check gains the midnight zones and windows that cut a repeated hour, cron grids are held to the scan matcher through both passes, and decideDue is pinned for the New York outage case.
A cron expression has no start date, so a rule whose start date is still ahead converted to a cron that would start at once. The Cron view would have offered it as the same schedule and saved it that way. scheduleRuleToCron now takes the start date with the day it is in the rule's zone, and has no cron for a rule that has not started yet; the monthly step keeps reading its phase from the same start date.
A cron such as 0 9 5 */3 * reads as every 3 months on the 5th only from January 1; anchored on the day it is edited, the same rule runs in other months. The test holds the converter's start date to the cron's months, so the editor that saves a converted cron has a contract to keep.
Every 6 hours from 8:00 to 13:00 read "the first run starts at 12:00 PM and the last at 12:00 PM", and every 4 hours from 21:00 to 03:00 called its one midnight start a night of runs. windowStarts now says where the starts fall (the window's own day, both sides of midnight, or only the next morning), and the hint names a single start once, with "the next morning" when it falls after midnight. The German refusal now says "startet kein Lauf" instead of "fällt kein Lauf", which read as a word-for-word copy of the English.
A screen reader heard only the schedule ("Every 6 hours, 8:00 AM to
11:00 AM") while no start fell between the hours, and Enter then did
nothing. The red sentence under the hours reached a time field only
through its description, which is not read again while you change a
part.
When no run falls between the hours, the announced schedule now ends
with that sentence, so the reason Save is blocked is heard where the
person is.
The hours row of Custom interval always carried the row-enter animation, so it slid in on top of the view's own fade every time the view opened on a rule that already had a window. It now drops in only when Only between is turned on, as the minute-past row already does when the step switches to hours.
Each part of a TimeField is its own tab stop, but the focused one was marked only by the accent grey, about 1.1:1 against the field in light and 1.35:1 in dark. Tabbing from the hour to the minutes showed no visible change, so a keyboard user could not tell where a digit would go. The focused part is now filled with the accent colour and its text turns to the accent's foreground, the look of a pressed chip, well over 3:1 against the field in both themes. A browser test measures the fill against the field in light and dark.
A TimeField named by aria-label rendered its bare group, and wrapped it in the label frame as soon as an errorMessage appeared. A host that checks the time while someone types swapped the element around the group, so the field remounted: focus dropped to the page and a part typed halfway was lost. The frame now follows the label and description alone. Without them the field renders the group and its error side by side in a stable fragment, so an error that comes and goes leaves the field in place.
The field's description put its time last, after the host's hint, so entering Until in Custom interval read "Until, Each day, the first run starts at 8:00 AM and the last at 5:45 PM. 6:00 PM": the field's own value came after a sentence holding two other times. The time now leads the description, then the description, the error and the host's ids, so the field says "Until, 6:00 PM" first.
A read-only TimeField kept the field's fill, border and focus ring, so it looked editable while the arrows and typing did nothing. A read-only Input already reads as text in the same footprint. The read-only field now drops the fill, the border and the ring and keeps its size; the focused part is still filled, so focus stays visible. The states demo shows the read-only and the small field apart, and the guide says what read-only looks like.
The guide said the hour wraps "12 to 1" on a 12-hour clock. The field wraps from 11 to 12 within its half of the day and keeps the day period, so 11 PM goes up to 12 PM (noon), not to midnight.
The next-runs list and the Custom times list are styled without markers, and WebKit then exposes them as plain groups, so VoiceOver in Safari never says "list, 3 items" as the guide promises. Both now say role="list", as the search results and the wizard steps already do.
A bare space separated a start from the reader's own time and from the Clock change badge, so a screen reader ran them together: "9:00 AM 3:00 AM in your time zone". The guide promises a comma there. Visually hidden punctuation now joins the parts: a comma before the reader's time and the badge, and a full stop before the clock-change sentence. The flex row still lays them out with its own gap.
The guide described the muted "Would run at" list, the empty list and the repeated-hour line of a grid schedule, but no example showed any of them. A states example now shows an hourly schedule muted on the day the clocks go back in Zurich, with both 2:00 AM runs marked, and a list with no starts.
Time mode shares the day picker's trigger and popover, but nothing proved it in a real browser: a schedule's tail is the longest, and its custom views hold a tab stop per time part. The schedule picker's browser suite now keeps a short tail on the line at 192px, drops a long one whole at 192 and 128px while keeping it in the name, and traps and restores focus inside a Dialog and a vaul Drawer, through Custom interval's time fields as well.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
The building blocks for scheduling automations with the same repeat picker tasks use — with times of day, sub-daily intervals and correct daylight-saving behaviour. This PR adds the shared engine and the reusable
@tale/uiparts; the automation trigger editor, storage and scan switch to them in the follow-up.@tale/uiTimeField(@tale/ui/time-field): segmented hour/minute spinbuttons in the locale's hour cycle (24 h or 12 h with AM/PM), arrow/Page/Home/End keys, typing and pasteHH:MM, read-only and error states; guide + demos + stories.RecurrencePicker granularity="time": presets (every 15 minutes, hourly, daily at …, weekdays at …, weekly, monthly), Custom times (several times a day) and Custom interval (every N minutes/hours with an optional Only between window, overnight windows included), next runs,allowNever={false}, a fade between views in time mode only. The task picker (day mode) is unchanged in props, DOM and emits.ScheduleOccurrenceList(@tale/ui/schedule-occurrence-list): the next runs in the schedule's zone (plus the reader's own time when it differs), clock-change sentences, muted and empty states.@tale/ui/recurrence-schedule): "Every weekday at 09:00 and 17:30", "Every 15 minutes, Mon–Fri, 08:00–18:00" — en/de/fr (+ de-CH).Shared engine (pure)
lib/shared/calendar.ts(behaviour-preserving; the task suites pass unchanged).lib/shared/zoned-time.ts: local time → instant with the RFC 5545/Temporal compatible rule — a time that doesn't exist shifts forward by the gap; a repeated time runs once, at the earlier instant.@tale/shared/schemas/schedule-rule: the schedule rule (a strict superset of the task repeat rule) with its validation codes.lib/automations/schedule/occurrences.ts: next/upcoming/due occurrences for named times and grids (grids run on elapsed time, so "every 15 minutes" keeps its pace through a repeated hour).lib/automations/schedule/cron-rule.ts: lossless cron ⇄ rule conversion (existing cron triggers will open in the picker when they can).lib/automations/trigger-input.ts: one builder for the input a trigger hands a run.Verification
@tale/uiunit 311 files / 3230 and Chromium 45 files / 335 (axe light + dark for every time-mode view and TimeField state, keyboard paths, 24 px targets, reduced motion, no overflow at 320 px in en/de/fr; focus traps inside Dialog and Drawer); ui-docs 106; platform server (automations, shared, guards, i18n) 92 files / 1871 incl. the parity test that holds the@tale/uiand@tale/sharedcopies of the rule together;packages/shared759; typecheck, oxlint, knip,lint:manual,lint:linksclean.Notes