Utilities for work days in Moment. (Western workweeks only.)
JavaScript HTML
Latest commit 56976cf Jan 30, 2017 @jmeas committed on GitHub Update README.md
Permalink
Failed to load latest commit information.
dist 3.0.1 Sep 16, 2016
src Ensure reversed args in weekDays/weekendDays is handled properly May 6, 2016
test Simplify unit tests May 10, 2016
.codeclimate.yml Add CodeClimate config file May 15, 2016
.gitignore First work. Jan 29, 2015
.jscsrc Stricter JSCS. Feb 14, 2015
.jshintrc Add constant time solutions. Jan 31, 2015
.travis.yml Fix code coverage May 6, 2016
CHANGELOG.md 3.0.1 Sep 16, 2016
LICENSE Initial commit Jan 29, 2015
README.md Update README.md Jan 30, 2017
bower.json 3.0.1 Sep 16, 2016
gulpfile.js Stricter JSCS. Feb 14, 2015
package.json 3.0.1 Sep 16, 2016

README.md

moment-business

Travis build status Code Climate Test Coverage Dependency Status devDependency Status

Utilities for working with week days and weekend days in Moment. It assumes a Western workweek, in which weekends are Saturday and Sunday.

Looking for a vanilla JS version of this library? Check out bizniz.js

Motivation

Moment is an indispensable tool for working with dates in Javascript, but it doesn't (and won't) supply methods for working with week days or weekend days.

This library supplies you with those missing tools.

Why this library?

There are alternative libraries for these methods, but this one uses constant-time algorithms, not loops. Loops are easier for a human to write, but are much slower for a computer to resolve.

Getting Started

Install this library through npm.

npm install moment-business

Next, import it into your project.

import business from 'moment-business';

business.isWeekDay(someMoment);

Note: this library is also available through Bower.

API

weekDays( startMoment, endMoment )

Calculate the number of week days between startMoment and endMoment. Week days are Monday through Friday.

If endMoment comes before startMoment, then this function will return a negative value.

weekendDays( startMoment, endMoment )

Calculate the number of weekend days between the moment and otherMoment. Weekend days are Saturday and Sunday.

If endMoment comes before startMoment, then this function will return a negative value.

addWeekDays( moment, amount )

Add week days to a moment, modifying the original moment. Returns the moment.

subtractWeekDays( moment, amount )

Subtract week days from the moment, modifying the original moment. Returns the moment.

isWeekDay( moment )

Whether or not the Moment is a week day (Monday - Friday).

isWeekendDay( moment )

Whether or not the Moment occurs on Saturday or Sunday.