@alanszp/business-days-date-fns
v16.0.0
Published
Wrapper for date-fns core TS/JS lib.
Downloads
222
Readme
📆 business-days-date-fns
An wrapper of some functionalities of date-fns with a custom non business days calendar.
🙋 Why?
date-fns
is great, but maybe you want to control dates using a your self calendar. This library allow you to do this.
⌚ TD;LR
This library is like isWeekend that excludes Saturday and Sunday but excluding the dates of your calendar too
🕹️ Features
- addBusinessDays, differenceInBusinessDays and subBusinessDays implementation and new functions: isNonBusinessDay, isBusinessDay,
- cache storage for a better performance
Async implementation
const {
addBusinessDays,
subBusinessDays
differenceInBusinessDays,
isNonBusinessDay,
isBusinessDay
} = withNonBusinessDays(({ year }) => {
return fetch(`${MY_API_CALENDAR}?year=${year}`)
})
const result = await addBusinessDays(new Date("2022-01-01"), 10, { year: 2022 })
Sync implementation
const {
addBusinessDays,
subBusinessDays
differenceInBusinessDays,
isNonBusinessDay,
isBusinessDay
} = withNonBusinessDays([
new Date('2022-01-01'),
new Date('2022-01-10')
])
const result = addBusinessDays(new Date("2022-01-01"), 10)