パッケージの詳細

moment-business

jmeas167.7kMIT3.0.1

Methods to work with week days and weekends in moment.

moment, momentjs, moment.js, business

readme

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.

更新履歴

3.0.1

  • Fix the name of the library in non-module loader browser environments. Previously, the library was attached as window.none. Now it is available under window.momentBusiness. Note that this issue does not affect users building with ES2015/CommonJS/AMD module bundlers.

3.0.0

  • The functions in this library now accept moments as arguments rather than being attached to the Moment prototype.
  • The behavior is weekDays and weekendDays now aligns more closely with Moment.prototype.diff. If the endMoment passed in comes before startMoment, then the result will be negative.
  • Better docs!

2.0.0

The API is now more consistent.

  • Rename isWorkDay to isWeekDay
  • Rename addWorkDays to addWeekDays
  • Rename subtractWorkDays to subtractWeekDays

1.1.1

  • Add dependencies to bower.json
  • Support invalid values when adding or subtracting work days (it returns the same moment)
  • Add this CHANGELOG file

1.1.0

  • Two new methods: isWeekendDay and isWorkDay

1.0.2

  • Removes the wrapper file altogether

1.0.1

  • Fixes an issue with the UMD wrapper

1.0.0

First major release.