moment-business-time
- We thank lennym, from which we forked this library
Query and manipulate moment objects within the scope of business/working hours.
Install
npm install [--save] moment-business-time
Methods
moment#isWorkingDay
Returns: Boolean
Determines if the day of the current instance is a working day. Working days are defined as any day with working hours in the current locale.
Example:
;// true;// false
moment#isWorkingTime
Returns: Boolean
Determines if the day and time of the current instance corresponds to during business hours as defined by the currnet locale.
Example:
;// true;// false
moment#nextWorkingDay
Returns: moment
Returns a new moment representing the next day considered to be a working day. The hours/minutes/seconds will be as for the source moment.
Example:
;// Mon Mar 02 2015 10:00:00 GMT+0000;// Mon Mar 02 2015 20:00:00 GMT+0000
moment#nextWorkingTime
Returns: moment
Returns a new moment representing the start of the next day considered to be a working day.
Example:
;// Mon Mar 02 2015 09:00:00 GMT+0000;// Mon Mar 02 2015 09:00:00 GMT+0000
moment#lastWorkingDay
Returns: moment
Returns a new moment representing the previous day considered to be a working day. The hours/minutes/seconds will be as for the source moment.
Example:
;// Fri Feb 27 2015 10:00:00 GMT+0000;// Fri Feb 27 2015 20:00:00 GMT+0000
moment#lastWorkingTime
Returns: moment
Returns a new moment representing the end of the previous day considered to be a working day.
Example:
;// Fri Feb 27 2015 17:00:00 GMT+0000;// Fri Feb 27 2015 17:00:00 GMT+0000
moment#addWorkingTime
Returns: self
Adds an amount of working time to a moment, modifying the original moment instance.
Example:
;// Fri Feb 27 2015 15:00:00 GMT+0000;// Mon Mar 02 2015 14:00:00 GMT+0000;// Fri Feb 27 2015 15:30:00 GMT+0000
moment#subtractWorkingTime
Returns: self
Adds an amount of working time to a moment, modifying the original moment instance.
Example:
;// Fri Feb 27 2015 11:00:00 GMT+0000;// Fri Feb 27 2015 12:00:00 GMT+0000;// Fri Feb 27 2015 10:30:00 GMT+0000
moment#workingDiff
Returns: Number
Calculates the difference between two moments, counting only working time. Arguments are as per moment#diff
Example:
;// 12;// 12.5
Configuration
Working hours
The working hours used for a locale can be modified using moment's locale
method. The default working hours are 09:00-17:00, Mon-Fri.
Example:
// set opening time to 09:30 and close early on Wednesdaysmoment; // false // false
Holidays
Holidays which should not be considered as working days can be configured by passing them as locale information.
Example:
moment; // false
Recurring holidays can also be set with wildcard parameters.
moment; // false // false // false // false
Running tests
npm test