(cronExpression: string, date: Date = new Date(), timezone: string = 'UTC')
| 413 | * original expression contains no `L` (no filtering needed). |
| 414 | */ |
| 415 | export const cronDomMatchesNow = (cronExpression: string, date: Date = new Date(), timezone: string = 'UTC'): boolean => { |
| 416 | const parsed = _parseCronFields(cronExpression) |
| 417 | |
| 418 | // Extract DOM, month, year in the schedule's timezone so leap-year and |
| 419 | // DST month boundaries are honoured. |
| 420 | let dom: number, month: number, year: number |
| 421 | try { |
| 422 | const fmt = new Intl.DateTimeFormat('en-US', { |
| 423 | timeZone: timezone, |
| 424 | year: 'numeric', |
| 425 | month: 'numeric', |
| 426 | day: 'numeric' |
| 427 | }) |
| 428 | const parts = fmt.formatToParts(date) |
| 429 | const get = (type: string) => parseInt(parts.find((p) => p.type === type)?.value ?? '0', 10) |
| 430 | dom = get('day') |
| 431 | month = get('month') |
| 432 | year = get('year') |
| 433 | } catch { |
| 434 | dom = date.getUTCDate() |
| 435 | month = date.getUTCMonth() + 1 |
| 436 | year = date.getUTCFullYear() |
| 437 | } |
| 438 | |
| 439 | // Day 0 of next month == last day of current month. |
| 440 | const lastDay = new Date(year, month, 0).getDate() |
| 441 | return _matchDomField(parsed.domField, dom, lastDay) |
| 442 | } |
| 443 | |
| 444 | // ─── Visual Picker helpers ──────────────────────────────────────────────────── |
| 445 |
no test coverage detected