MCPcopy Index your code
hub / github.com/Effect-TS/effect / make

Function make

packages/effect/src/Cron.ts:138–200  ·  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 tz?: DateTime.TimeZone | undefined
})

Source from the content-addressed store, hash-verified

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

Callers 2

fromRecordFunction · 0.70
ServiceFunction · 0.70

Calls 2

lookupTableFunction · 0.85
createMethod · 0.80

Tested by

no test coverage detected