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

Function match

packages/effect/src/Cron.ts:404–443  ·  view source on GitHub ↗
(cron: Cron, date: DateTime.DateTime.Input)

Source from the content-addressed store, hash-verified

402 * @since 2.0.0
403 */
404export const match = (cron: Cron, date: DateTime.DateTime.Input): boolean => {
405 const parts = dateTime.unsafeMakeZoned(date, {
406 timeZone: Option.getOrUndefined(cron.tz)
407 }).pipe(dateTime.toParts)
408
409 if (cron.seconds.size !== 0 && !cron.seconds.has(parts.seconds)) {
410 return false
411 }
412
413 if (cron.minutes.size !== 0 && !cron.minutes.has(parts.minutes)) {
414 return false
415 }
416
417 if (cron.hours.size !== 0 && !cron.hours.has(parts.hours)) {
418 return false
419 }
420
421 if (cron.months.size !== 0 && !cron.months.has(parts.month)) {
422 return false
423 }
424
425 if (cron.days.size === 0 && cron.weekdays.size === 0) {
426 return true
427 }
428
429 if (cron.and) {
430 return (cron.days.size === 0 || cron.days.has(parts.day)) &&
431 (cron.weekdays.size === 0 || cron.weekdays.has(parts.weekDay))
432 }
433
434 if (cron.weekdays.size === 0) {
435 return cron.days.has(parts.day)
436 }
437
438 if (cron.days.size === 0) {
439 return cron.weekdays.has(parts.weekDay)
440 }
441
442 return cron.days.has(parts.day) || cron.weekdays.has(parts.weekDay)
443}
444
445const daysInMonth = (date: Date): number =>
446 new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1, 0)).getUTCDate()

Callers 11

optionFunction · 0.70
eitherFunction · 0.70
toMillisFunction · 0.70
toSecondsFunction · 0.70
toMinutesFunction · 0.70
toHoursFunction · 0.70
toDaysFunction · 0.70
toWeeksFunction · 0.70
Duration.tsFile · 0.70
Either.tsFile · 0.70
Match.tst.tsFile · 0.50

Calls 1

pipeMethod · 0.65

Tested by

no test coverage detected