Using the Moment.js Business plugin, you can use Moment for workweeks that follow the Western calendar: 7-day workweeks with Saturday and Sunday off. It provides a list of functions to identify weekdays, weekends, etc.
Write the below command in the terminal to install:
npm install moment-business
The following are some of the functions in this plugin:
- weekDays
- weekendDays
- addWeekDays
- subtractWeekDays
- isWeekDay
- isWeekendDay
The below examples will help to understand some of the methods of the Business Plugin.
Example 1:
Javascript
import moment from 'moment' ; import business from "moment-business" ; let today = moment(); let weekDay = business.isWeekDay(today); console.log(today.format( 'dddd, DD-MM-yyyy' )); console.log(weekDay); |
Output:
Example 2:
Javascript
import moment from 'moment' ; import business from "moment-business" ; let today = moment(); let next = business.addWeekDays(today, 10); console.log(next.format( 'DD-MM-YYYY' )); |
Output:
Reference: https://momentjs.com/docs/#/plugins/moment-business/