Skip to content

feat(cron): cron expression explainer with next-run preview#86

Merged
lyfuci merged 3 commits into
mainfrom
feat/cron-explainer
May 31, 2026
Merged

feat(cron): cron expression explainer with next-run preview#86
lyfuci merged 3 commits into
mainfrom
feat/cron-explainer

Conversation

@lyfuci

@lyfuci lyfuci commented May 31, 2026

Copy link
Copy Markdown
Owner

What

A new Cron tool under Convert: paste a cron expression → get a plain-language description and a preview of the next fire times. Fully client-side, no network.

How

  • src/lib/cron.tsanalyzeCron() wraps two pure-JS libraries:
    • cronstrue for the human sentence (has a built-in zh_CN locale).
    • cron-parser v5 (CronExpressionParser.parse.next().toDate()) for upcoming run times.
    • Requires both to accept the expression before calling it valid, so the description and the run list can't disagree.
  • Generated sentence follows the app language (en / zh_CN); static UI labels are normal i18n keys in both locales.
  • Timezone is explicit: next runs are computed in a selectable IANA timezone (defaults to the browser's local TZ), and each row shows both the TZ-local time and the absolute ISO instant — so "next run" is never ambiguous.
  • Quick presets, a 5-field breakdown, and an inline error branch for malformed input.
  • Registered in router.tsx + tools.ts (Convert category, CalendarClock icon).

Tests / verification

  • 13 unit tests: steps (*/15), ranges (1-5), lists, the @daily macro, day-of-week vs day-of-month, TZ offsets (Asia/Shanghai midnight = 16:00 UTC prior day), and invalid / out-of-range input.
  • pnpm typecheck / pnpm lint / pnpm build clean; 224 tests green.
  • Headless-Chrome (both locales): en → "Every 15 minutes…", zh_CN → Chinese description with no English leak; 6 next-run rows; the invalid-input branch — no raw i18n keys, zero page errors.

🤖 Generated with Claude Code

lyfuci and others added 3 commits May 31, 2026 12:17
New tool under Convert: paste a cron line, get a plain-language
description plus the next fire times. Everything runs client-side.

- src/lib/cron.ts: analyzeCron() wraps cronstrue (human description, with
  built-in zh_CN locale) and cron-parser v5 (CronExpressionParser.parse ->
  next fire times). Requires BOTH to accept the expression before calling it
  valid, so the description and the run list never disagree.
- The generated sentence follows the app language (en / zh_CN); static UI
  labels are normal i18n keys in both locales.
- Next runs are computed in a selectable IANA timezone (defaults to the
  user's local TZ); each row shows both the TZ-local time and the absolute
  ISO instant, so "next run" is never ambiguous.
- Quick presets, a 5-field breakdown, and an inline error branch for
  malformed input.
- Registered in router + tools.ts (Convert, CalendarClock icon).

Tests: 13 unit tests cover steps/ranges/lists, @daily macro, dow-vs-dom,
TZ offsets, and invalid/out-of-range input. Verified: typecheck/lint/build
clean, 224 tests green, and headless-Chrome (en + zh_CN) confirmed the
descriptions, next-run rows, preset switching, and the invalid-input branch
-- no raw i18n keys, zero page errors.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The initial cron commit landed the page, lib, route and registry but the
i18n catalog edits only partially applied (zh pages.cron made it; en
tools.cron/pages.cron and zh tools.cron did not), so the tool name and
labels rendered as raw keys. This adds the three missing blocks.

- en.json: tools.cron + pages.cron (description, expression, meaning,
  enterHint, invalid, timezone, nextRuns, fields.*, presets.*)
- zh-CN.json: tools.cron
- Verified: both catalogs parse, all four cron key-groups present, the
  image-editor blocks are untouched (184 keys, 0 deletions in the diff),
  typecheck/lint/build clean, 224 tests green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The earlier i18n commits' zh tools.cron edit silently failed to apply, so
the Cron tool's sidebar/home name fell back to its raw key in the Chinese
locale. Insert it (description mirrors the en entry). All four cron
key-groups (en/zh x tools/pages) are now present; image-editor catalog
untouched (0 deletions), typecheck/lint/build clean, 224 tests green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lyfuci lyfuci merged commit 422fd39 into main May 31, 2026
2 checks passed
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