MCPcopy Create free account
hub / github.com/Effect-TS/effect / formatSegment

Function formatSegment

packages/effect/src/Cron.ts:653–676  ·  view source on GitHub ↗
(values: ReadonlySet<number>)

Source from the content-addressed store, hash-verified

651}
652
653const 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.

Callers

nothing calls this directly

Calls 2

pushMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected