![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@backtolife/dayjs-business-days
Advanced tools
Day.js plugin to add support for calculating dates only accounting for Business days
fork from https://github.com/soar-tech/dayjs-business-days
This is a plugin for Day.js that allows for Date calculations to take place that only consider Business Days i.e Monday to Friday
The following guide will help you use the plugin with Day.js, and explain the plugins API.
Day.js version 1.8.x installed
You can install via Yarn or npm
yarn add dayjs-business-days
npm install dayjs-business-days
You will need to import the plugin and activate it via the Day.js .extend()
function
import dayjs from 'dayjs'
import dayjsBusinessDays from 'dayjs-business-days'
dayjs.extend(dayjsBusinessDays);
Check if the date is a business day. Returns true or false
// Christmas day is a Friday
dayjs('2020-12-25').isBusinessDay(); // returns true
// Boxing day is a Saturday
dayjs('2020-12-26').isBusinessDay(); // returns false
number
{Number
} Number of Business Days to be addedAdds the number
of Business Days to the current date. Returns the new date as a Day.js object
dayjs('2020-12-25').businessDaysAdd(3).format('DD/MM/YYYY') // returns 30/12/2020
number
{Number
} Number of Business Days to be subtractedSubtracts the number
of Business Days from the current date. Returns the new date as a Day.js object
dayjs('2020-12-30').businessDaysSubtract(3).format('DD/MM/YYYY') // returns 25/12/2020
date
{Day.js Date
} The date to be diffed fromCalculates the number of business days between a Day.js date and date
. Returns the difference as a positive or negative number.
dayjs('2020-12-25').businessDiff(dayjs('2020-12-30')) // returns -5
dayjs('2020-12-30').businessDiff(dayjs('2020-12-25')) // returns 5
Calculates the next Business Day. Returns a Day.js object
// 25th December 2020 is a Friday. Next business day is Monday 28th December.
dayjs('2020-12-25').nextBusinessDay().format('DD/MM/YYYY') // returns 28/12/2020
Calculates the previous Business Day. Returns a Day.js object
// 28th December 2020 is a Monday. Previous business day is Friday 25th December.
dayjs('2020-12-28').prevBusinessDay().format('DD/MM/YYYY') // returns 25/12/2020
Calculates all of the business days in a given month. Returns an array of Day.js objects
dayjs('2020-12-25').businessDaysInMonth()
// returns equivalent of [dayjs('2020-12-01'), dayjs('2020-12-02'), ...]
Calculates all of the business weeks and days in a given month. Returns an two dimensional array of Day.js objects
dayjs('2020-12-25').businessWeeksInMonth();
// returns equivalent of
// [
// [dayjs('2020-12-01'), dayjs('2020-12-02'), ...],
// [dayjs('2020-12-07'), dayjs('2020-12-08'), ...],
// ...
// ]
Check if the date is a holiday. Returns true or false
// Add holidays to plugin options
const options = {
holidays: ['2020-12-25'],
holidayFormat: 'YYYY-MM-DD',
forcedBusinessDays: ['2021-05-08'],
forcedBusinessDaysFormat: 'YYYY-MM-DD',
}
dayjs.extend(businessDays, options)
// Christmas day is a Friday
dayjs('2020-12-25').isHoliday() // returns true
dayjs('2021-05-08').isBusinessDay() // returns true
We are more than happy to accept PRs for bugs, improvements or new features. Developing your own changes locally is easy, you just need to clone the repo
git clone git@github.com/gmfe/dayjs-business-days
cd dayjs-business-days
and install the dependencies with either npm
or yarn
yarn bootstrap
Tests can be ran with the test
script
yarn test
FAQs
Day.js plugin to add support for calculating dates only accounting for Business days
We found that @backtolife/dayjs-business-days demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.