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

Function make

packages/effect/src/Cron.ts:141–205  ·  view source on GitHub ↗
(values: {
  readonly seconds?: Iterable<number> | undefined
  readonly minutes: Iterable<number>
  readonly hours: Iterable<number>
  readonly days: Iterable<number>
  readonly months: Iterable<number>
  readonly weekdays: Iterable<number>
  readonly and?: boolean | undefined
  readonly tz?: DateTime.TimeZone | undefined
})

Source from the content-addressed store, hash-verified

139 * @category constructors
140 */
141export const make = (values: {
142 readonly seconds?: Iterable<number> | undefined
143 readonly minutes: Iterable<number>
144 readonly hours: Iterable<number>
145 readonly days: Iterable<number>
146 readonly months: Iterable<number>
147 readonly weekdays: Iterable<number>
148 readonly and?: boolean | undefined
149 readonly tz?: DateTime.TimeZone | undefined
150}): Cron => {
151 const o: Mutable<Cron> = Object.create(CronProto)
152 o.seconds = new Set(Arr.sort(values.seconds ?? [0], N.Order))
153 o.minutes = new Set(Arr.sort(values.minutes, N.Order))
154 o.hours = new Set(Arr.sort(values.hours, N.Order))
155 o.days = new Set(Arr.sort(values.days, N.Order))
156 o.months = new Set(Arr.sort(values.months, N.Order))
157 o.weekdays = new Set(Arr.sort(values.weekdays, N.Order))
158 o.and = values.and === true
159 o.tz = Option.fromNullable(values.tz)
160
161 const seconds = Array.from(o.seconds)
162 const minutes = Array.from(o.minutes)
163 const hours = Array.from(o.hours)
164 const days = Array.from(o.days)
165 const months = Array.from(o.months)
166 const weekdays = Array.from(o.weekdays)
167
168 o.first = {
169 second: seconds[0] ?? 0,
170 minute: minutes[0] ?? 0,
171 hour: hours[0] ?? 0,
172 day: days[0] ?? 1,
173 month: (months[0] ?? 1) - 1,
174 weekday: weekdays[0] ?? 0
175 }
176
177 o.last = {
178 second: seconds[seconds.length - 1] ?? 59,
179 minute: minutes[minutes.length - 1] ?? 59,
180 hour: hours[hours.length - 1] ?? 23,
181 day: days[days.length - 1] ?? 31,
182 month: (months[months.length - 1] ?? 12) - 1,
183 weekday: weekdays[weekdays.length - 1] ?? 6
184 }
185
186 o.next = {
187 second: lookupTable(seconds, 60, "next"),
188 minute: lookupTable(minutes, 60, "next"),
189 hour: lookupTable(hours, 24, "next"),
190 day: lookupTable(days, 32, "next"),
191 month: lookupTable(months, 13, "next"),
192 weekday: lookupTable(weekdays, 7, "next")
193 }
194
195 o.prev = {
196 second: lookupTable(seconds, 60, "prev"),
197 minute: lookupTable(minutes, 60, "prev"),
198 hour: lookupTable(hours, 24, "prev"),

Callers 3

fromRecordFunction · 0.70
ServiceFunction · 0.70
parseFunction · 0.70

Calls 2

lookupTableFunction · 0.85
createMethod · 0.80

Tested by

no test coverage detected