(cron: Cron, date: DateTime.DateTime.Input)
| 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. |
| 680 | * |
| 681 | * **When to use** |
| 682 | * |
| 683 | * Use to test whether a specific date/time satisfies a cron schedule. |
| 684 | * |
| 685 | * **Details** |
| 686 | * |
| 687 | * The schedule's timezone determines which calendar fields are read from the |
| 688 | * input; the host system's timezone is used when the schedule has no timezone. |
| 689 | * Seconds, minutes, hours, and months are checked against their restrictions; |
| 690 | * an empty set leaves that field unrestricted. If only `days` or `weekdays` is |
| 691 | * restricted, that field must match. If both are restricted, either may match |
| 692 | * unless the schedule was created with `and: true`, which requires both to |
| 693 | * match. |
| 694 | * |
| 695 | * **Example** (Matching dates against a schedule) |
| 696 | * |
| 697 | * ```ts import.meta.vitest |
searching dependent graphs…