moment-business
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/moment-business package

3.0.1 • Public • Published

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 supply methods for working with week days or weekend days (at least, not yet).

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.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
3.0.121,123latest

Version History

VersionDownloads (Last 7 Days)Published
3.0.121,123
3.0.00
2.0.00
1.1.10
1.1.00
1.0.10
1.0.00

Package Sidebar

Install

npm i moment-business

Weekly Downloads

21,123

Version

3.0.1

License

MIT

Last publish

Collaborators

  • jmeas