npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dayjs-business-days

v1.0.4

Published

Day.js plugin to add support for calculating dates only accounting for Business days

Downloads

40,433

Readme

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

  • Calculate if date is a Business Day
  • Add/Subtract Business Days
  • Calculate difference between dates in Business Days
  • Get Next/Prev Business Day
  • Get all Business Days/Weeks in a Month
  • Based off of moment-business-days

Current CI/CD Status

CI not yet implemented

Contents

Getting Started

The following guide will help you use the plugin with Day.js, and explain the plugins API.

Prerequisites

Day.js version 1.8.x installed

Installing

You can install via Yarn or npm

yarn add dayjs-business-days
npm install dayjs-business-days

Usage Guide

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);

isBusinessDay() => Boolean

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

businessDaysAdd(number) => Day.js Object

  • number {Number} Number of Business Days to be added

Adds 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

businessDaysSubtract(number) => Day.js Object

  • number {Number} Number of Business Days to be subtracted

Subtracts 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

businessDiff(date) => Number

  • date {Day.js Date} The date to be diffed from

Calculates 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

nextBusinessDay() => Day.js Object

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

prevBusinessDay() => Day.js Object

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

businessDaysInMonth() => [Day.js Object]

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'), ...]

businessWeeksInMonth() => [[Day.js Object]]

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'), ...],
//   ...
// ]

Local Development and Contributing

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 [email protected]/soar-tech/dayjs-business-days

cd dayjs-business-days

and install the dependencies with either npm or yarn

npm i
yarn

Tests can be ran with the test script

npm run test
yarn test