Notes › Tech Notes › Cron generator template button round trip: only 1 of 8 rebuilds word for word, and the previewer freezes the second on the wall clock

Cron generator template button round trip: only 1 of 8 rebuilds word for word, and the previewer freezes the second on the wall clock

Round-tripping every Cron template button leaves only 1 of 8 rebuilt word for word: 5 single values degrade into n-n ranges, 2 asterisk-led steps fall back to wildcards, and the previewer pins the second field to the moment you enter, so 7 of 8 wrongly report no trigger within a year.

Press a template button and the expression takes a round trip first

The setup is ordinary: the page assembles a 5-field or 6-field cron expression for a scheduled job, the 8 template buttons hand out a string as soon as you press one, and copying it away should be the end of it. The chain is button argument → per-field state → rebuilt expression, and once that chain is walked under a pinned fake clock, only 0/1 * * * * * of the 8 returns word for word. The other 7 come back reshaped: some only change their spelling, some lose their meaning on the way out.

The page is a purely local logic machine: 16271 bytes of template, 327 line segments, 10299 characters of script text holding 15 named functions, zero external dependencies. Read that text back as it stands, add a DOM stub and a pinned fake clock, run it in a virtual machine, and every entry below reproduces on demand, with no real scheduler and no network.

Two kinds of non-inverse: single value decay and swallowed steps

Parsing hangs on one regular expression. A stepped form such as 0/1 enters the step branch, a range such as 1-5 enters the range branch, and a lone 0 has no branch of its own, so it decays into the range 0-0. That is why 0 0 9 * * * is rebuilt as 0-0 0-0 9-9 * * *: the expanded set never moves, only the literal does. Feeding the rebuilt string through the parser again is the more interesting half, because by then everything is a range, so it passes through untouched and from the second round on it is a fixed point. Five buttons fall in this class, where the round trip only changes the wrapper.

The second class is more than a wrapper. A step that begins with an asterisk does not match the parsing regex, and that field drops back to the wildcard: 0 0 */2 * * * * rebuilds as 0-0 0-0 * * * *, and 0 */5 * * * * * rebuilds as 0-0 * * * * *. The two buttons labelled 每 2 小时 and 每 5 分钟, every 2 hours and every 5 minutes, lose their meaning on a single pass.

A note on direction: this door only swings one way, from plain to elaborate. No rebuilt string comes out tighter than its original and none raises an error, because when the regex misses the field silently falls back to the wildcard and the lost meaning leaves no trace in the interface. The output box is the only place the change shows.

The round trip behind one button press Press a button0 0 9 * * * Parse: value decays0 → range 0-0 Rebuild expression0-0 0-0 9-9... Feed it once moreFixed point Word-for-word inverse 1 / 8: 0/1 * * * * * 5 reshaped: single values rebuild as n-n, set unchanged 2 lose meaning: asterisk-led */2 and */5 collapse to wildcards
Figure 1 One round trip sorts the 8 buttons into three outcomes

The round trip ledger, word for word

Button argumentRebuilt stringNature
0/1 * * * * *0/1 * * * * *only word-for-word inverse
0 0 9 * * *0-0 0-0 9-9 * * *value decays, set unchanged
0 0 */2 * * * *0-0 0-0 * * * *step swallowed, meaning lost
0 */5 * * * * *0-0 * * * * *step swallowed, meaning lost

Switching field counts is not clearing, it is hiding

Toggling between the 5-field and 6-field modes without touching a template keeps the second field intact. Set it to 30-30 in 6-field mode, switch to 5 fields and that segment disappears, since the alignment runs slice(1) to drop seconds; switch back and it returns untouched. Any template button rebuilds the whole state instead. A false alarm sits in this corner too: from the default state, 5-field mode plus preview always gives 0 rows and pops 「表达式含 L / W / # 等扩展记号,暂不支持执行时间预览(表达式本身仍可用于 Quartz 系统)。, the extension token notice, at 53 characters and 121 bytes. The 5-field parsing path never touches the second field, so it happens to be null and walks into a guard meant only for extension tokens; even typing abc into the step start, which yields NaN/1, is swallowed by that same sentence.

So this message judges not the shape of the expression but which fields were parsed at all. Before rereading the expression, confirm which mode you are sitting in.

The previewer freezes the second at the moment you enter

The preview of the next 5 runs steps with d.setMinutes, one minute at a time, and never moves the seconds. Entering at fake clock 13:07:23, the second is clamped to the second of entry plus one, which is 24, and after that the whole timeline only tests for a hit on second 24. Under the same construction 24-24 * * * * * lands all 5 rows while 25-25 * * * * * lands nothing, and the gap is that frozen second. Press 7 of the 8 template buttons and you are told 「按当前配置一年内没有触发时间」, no run time in the coming year. Move the clock to 13:07:59 and enter again: 59+1 carries, the second settles to 0, and the same button prints all 5 rows.

The window has its own account. MAX_STEPS=1052000 at one step per minute, so a full scan reaches 730.56 days, roughly two years of depth, while the empty-result wording still says one year. A sample that can never be hit, day 30 of month 2, scans full and gets the same sentence.

Back to the original scene of pressing a button and copying the result: if the second on the wall clock disagrees with the template at the moment you open the preview, the 5-row list is invisible across the screen. It reads like a broken configuration but is only a rigid stepper, so check the generated string in the output box word for word before you copy.

Two timelines with the second frozen wall clock 13:07:23scan second fixed at 24 25-25 hits 0 rows24-24 hits 5 rows no run time in one year7 / 8 buttons leave empty wall clock 13:07:5959+1 carries, second to 0 same button, all 5 rows window 1052000 steps ≈ 730.56 days
Figure 2 Change the second you enter on and the outcome flips

Field parsing accounts measured along the way

  • A list with a trailing comma, 0,, lets the field expand into any value.
  • The minute field written as 0-70 expands into 71 keys, with no clamp on the upper bound.
  • The only clamp sits on the step value every: 0 and -5 both clamp down to /1, and an empty start is silently read as 0.
  • Restricting day and weekday together is read as an or: in the 5-row preview of 0/1 0-0 0-0 15-15 * 1-1, day 15 of month 12 is listed even though it is a Tuesday, and writing 7 in the weekday field normalizes through %7 so all 5 rows land on Sunday.
  • Distance to the N-th run rounds in three modes: the minute mode prints 0 分钟后, since a one second gap rounds down to 0, and the longer samples print 19 小时 52 分钟后 and, floored by day mode, 130 天后.

The generating side is now measured. Asking another page when a rebuilt string actually runs belongs to handing the expression to the crontab parser to verify the next run, and this article does not repeat its answer. The field-by-field picker that assembles a cron expression stays purely local. For more shapes of that or account, the one where day 15 of month 12 is listed anyway, how day and weekday restrictions union when both are limited works the scenario out.

Quick questions

Q: Do schedulers accept the rebuilt n-n range strings?

This page only produces a string. The decay class expands to the same set as its original, but a previewer that parses a shape is no promise that every scheduler accepts it, so treat the string in the output box as the authority before you copy.

Q: I pressed the 每 5 分钟 button, why does the preview look like it runs every minute?

An asterisk-led step does not parse, the field falls back to the wildcard, and the minute field of the rebuilt string is no longer restricted. The preview steps from the rebuilt state, so read the generated string after pressing a button and only then decide whether to edit it back.

Q: It says no run time within one year, is the configuration hopeless?

Move the second field or try a clean minute first. One frozen second is enough to send 7 of the 8 buttons home empty-handed, and the one year in the wording is not the window either: a full scan of 1052000 steps reaches 730.56 days of depth.

Q: Does switching between 5 and 6 fields lose settings?

Toggling the mode without a template loses nothing; the second field is only hidden and comes back when you return to the original mode. A template button rebuilds the whole state from its own argument.

📎 Related articles

A malformed URL into the parser page: example.com:80 is read as the protocol, and %e stops the segment table halfway 2026-11-21 Rejection sampling and the no-repeat cutoff: 60000 draws give chi-square 53.75, and ratio 0.05 is the switch point 2026-11-21 Is Pasted-Back SQL Byte-Identical After Formatting: 8 String Syntaxes Cross-Checked, 2 Unclosed Backticks Paired Silently 2026-11-20 84 Field Names Across 7 Tabs: 2nd_field Comes in 6 Spellings and 5 Switches Move Only the Java Column 2026-11-20 Excel to JSON trusts only two numeric regexes: 0012 becomes 12, 1e5 stays a string, and the 8-cell switch matrix lands between 99 and 192 bytes 2026-11-20