Add toHuman: describe a cron expression in English#4
Merged
Conversation
Reverse direction (readback) of toCron. Parses a 5- or 6-field node-cron expression and renders a readable English sentence phrased so that toCron parses it back to the same expression: toCron(toHuman(cron)) === cron. - frequency (every minute, every 5 minutes, every hour) - clock times (at 9am, at 2:30pm, at noon, at midnight) - field values/lists/ranges (at minute 0, 15, 30 and 45; between 9am and 5pm) - ordinals (last friday of the month, first monday of the month, last day) - month/weekday names accepted in input (MON-FRI, JAN) Adds test/to-human.test.ts: round-trip oracle over every forward golden cron, plus explicit readability assertions (75 cases). Documents toHuman in README.
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.
Adds the reverse direction:
toHuman(cron)turns a 5- or 6-field node-cron expression back into plain English. It's the readback for atoCroncall ("you wrote X, here's the cron, which reads as Y").What it does
Covers frequency, clock times, field values/lists/ranges, ordinals (
L/#), and accepts month/weekday names in the input (MON-FRI,JAN).Round-trip property
The English is phrased so that
toCronparses it back to the same expression:This is the round-trip oracle from the design: the readback reuses the
toCrongrammar rather than reinventing a cron describer, and the test suite asserts the property over every cron the forward direction can produce.Scope
The readback prioritizes correctness and round-trip fidelity over perfect prose. English-only (no i18n). Rare composite shapes (e.g. a wildcard seconds field combined with a specific time) may not get the prettiest phrasing, though the round-trip holds for everything the forward parser generates.
Checks
npm run typecheck,npm run lint,npm run build: clean.npm test: 142 tests (67 forward + 75 reverse), all green.test/to-human.test.tsround-trips every forward golden cron plus explicit readability assertions.