Business Days
Import
Section titled “Import”import { addBusinessDays, subtractBusinessDays, countBusinessDays, isWithinWorkingHours, checkIsBusinessDay,} from 'date-wiz';// orimport { ... } from 'date-wiz/business';addBusinessDays()
Section titled “addBusinessDays()”function addBusinessDays( date: DateInput, days: number, options?: BusinessDayOptions,): DateAdd n business days, automatically skipping weekends and any specified holidays.
import { addBusinessDays } from 'date-wiz';
// Monday Jan 8 + 5 business days = Monday Jan 15addBusinessDays(new Date('2024-01-08'), 5)
// With public holidays excludedaddBusinessDays(new Date('2024-01-08'), 5, { holidays: ['2024-01-09', '2024-12-25'],})
// Negative value subtracts business daysaddBusinessDays(new Date('2024-01-15'), -5) // → Monday Jan 8subtractBusinessDays()
Section titled “subtractBusinessDays()”function subtractBusinessDays( date: DateInput, days: number, options?: BusinessDayOptions,): DateConvenience wrapper for addBusinessDays(date, -days, options).
// Friday Jan 12 - 1 business day = Thursday Jan 11subtractBusinessDays(new Date('2024-01-12'), 1)countBusinessDays()
Section titled “countBusinessDays()”function countBusinessDays( from: DateInput, to: DateInput, options?: BusinessDayOptions,): numberCount the business days between two dates. The start date is exclusive; the end date is inclusive.
// Monday Jan 8 → Friday Jan 12 = 4 business days (Mon is excluded)countBusinessDays( new Date('2024-01-08'), new Date('2024-01-12'),) // → 4
// Exclude a holidaycountBusinessDays( new Date('2024-01-08'), new Date('2024-01-12'), { holidays: ['2024-01-09'] },) // → 3
// Negative when from > tocountBusinessDays( new Date('2024-01-12'), new Date('2024-01-08'),) // → -4isWithinWorkingHours()
Section titled “isWithinWorkingHours()”function isWithinWorkingHours( date: DateInput, options?: WorkingHoursOptions,): booleanReturns true when the given date falls within the configured working hours on a working day.
| Option | Type | Default | Description |
|---|---|---|---|
start | string | '09:00' | Start time in HH:MM (24h) |
end | string | '17:00' | End time in HH:MM (24h), exclusive |
workDays | number[] | [1,2,3,4,5] | Working days (0=Sun … 6=Sat) |
import { isWithinWorkingHours } from 'date-wiz';
// Monday 10 AM — within 9–17 windowisWithinWorkingHours( new Date('2024-01-08T10:00:00'), { start: '09:00', end: '17:00' },) // → true
// Saturday — weekendisWithinWorkingHours(new Date('2024-01-13T10:00:00')) // → false
// After hoursisWithinWorkingHours( new Date('2024-01-08T18:30:00'), { start: '09:00', end: '18:00' },) // → false
// Custom work week (Mon–Sat)isWithinWorkingHours(new Date(), { start: '08:00', end: '20:00', workDays: [1, 2, 3, 4, 5, 6],})checkIsBusinessDay()
Section titled “checkIsBusinessDay()”function checkIsBusinessDay( date: DateInput, options?: BusinessDayOptions,): booleanReturns true when the given date is a working day (Mon–Fri, not a holiday).
checkIsBusinessDay(new Date('2024-01-08')) // Monday → truecheckIsBusinessDay(new Date('2024-01-13')) // Saturday → false
// With holidayscheckIsBusinessDay(new Date('2024-01-08'), { holidays: ['2024-01-08'],}) // → false (it's a holiday)BusinessDayOptions
Section titled “BusinessDayOptions”interface BusinessDayOptions { /** * ISO date strings (YYYY-MM-DD) of public holidays to exclude. * @example ['2024-12-25', '2024-01-01'] */ holidays?: string[];}