| 651 | } |
| 652 | |
| 653 | const formatSegment = (values: ReadonlySet<number>): string => { |
| 654 | if (values.size === 0) { |
| 655 | return "*" |
| 656 | } |
| 657 | const array = Array.from(values) |
| 658 | const segments: Array<string> = [] |
| 659 | let index = 0 |
| 660 | while (index < array.length) { |
| 661 | const start = array[index]! |
| 662 | const step = array[index + 1]! - start |
| 663 | if (index + 2 < array.length && array[index + 2]! - array[index + 1]! === step) { |
| 664 | let end = index + 2 |
| 665 | while (end + 1 < array.length && array[end + 1]! - array[end]! === step) { |
| 666 | end++ |
| 667 | } |
| 668 | segments.push(`${start}-${array[end]}${step === 1 ? "" : `/${step}`}`) |
| 669 | index = end + 1 |
| 670 | } else { |
| 671 | segments.push(`${start}`) |
| 672 | index++ |
| 673 | } |
| 674 | } |
| 675 | return segments.join(",") |
| 676 | } |
| 677 | |
| 678 | /** |
| 679 | * Returns `true` when a date/time matches a `Cron` schedule. |