All Projects → jamesplease → Moment Business

jamesplease / Moment Business

Licence: mit
Utilities for work days in Moment. (Western workweeks only.)

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Moment Business

ng2-timezone-selector
A simple Angular module to create a timezone selector using moment-timezone.
Stars: ✭ 12 (-86.81%)
Mutual labels:  moment
React Article Bucket
总结,积累,分享,传播JavaScript各模块核心知识点文章全集,欢迎star,issue(勿fork,内容可能随时修改)。webpack核心内容部分请查看专栏: https://github.com/liangklfangl/webpack-core-usage
Stars: ✭ 750 (+724.18%)
Mutual labels:  moment
Fullcalendar Jalaali
Full-sized drag & drop event calendar (jQuery plugin) http://fullcalendar.io
Stars: ✭ 40 (-56.04%)
Mutual labels:  moment
moment-holiday
A Moment.js plugin for handling holidays. NO LONGER MAINTAINED (DEPRECATED)
Stars: ✭ 82 (-9.89%)
Mutual labels:  moment
Angular Moment Picker
Angular Moment Picker is an AngularJS directive for date and time picker using Moment.js.
Stars: ✭ 536 (+489.01%)
Mutual labels:  moment
Dayjs
⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
Stars: ✭ 37,373 (+40969.23%)
Mutual labels:  moment
moment-cache
⏱ Simple utility to cache moment.js results and speed up moment calls.
Stars: ✭ 29 (-68.13%)
Mutual labels:  moment
Placeline Nextjs
HyperTrack Placeline web application sample using NextJS, Ant-Design, Styled-Components, and Heroku
Stars: ✭ 88 (-3.3%)
Mutual labels:  moment
React Datepicker
A simple and reusable datepicker component for React
Stars: ✭ 6,206 (+6719.78%)
Mutual labels:  moment
Ember Cli Moment Shim
ember-cli shim for momentjs
Stars: ✭ 34 (-62.64%)
Mutual labels:  moment
React Native Timeago
An auto-updating timeago component for React Native using moment.js
Stars: ✭ 339 (+272.53%)
Mutual labels:  moment
Date Io
Abstraction over common javascript date management libraries
Stars: ✭ 382 (+319.78%)
Mutual labels:  moment
Emptyd Admin Webpack
基于typescript react webpack的脚手架
Stars: ✭ 30 (-67.03%)
Mutual labels:  moment
dayjs
Extended fork of Day.js - 2KB immutable date library alternative to Moment.js
Stars: ✭ 36 (-60.44%)
Mutual labels:  moment
Ngx Moment
moment.js pipes for Angular
Stars: ✭ 1,127 (+1138.46%)
Mutual labels:  moment
moment-dayjs-codemod
A Codemod to migrate from moment.js to day.js
Stars: ✭ 20 (-78.02%)
Mutual labels:  moment
Moment.php
Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
Stars: ✭ 900 (+889.01%)
Mutual labels:  moment
Angular Bootstrap Datetimepicker
Native Angular date/time picker component styled by Twitter Bootstrap
Stars: ✭ 1,289 (+1316.48%)
Mutual labels:  moment
Rc Datetime Picker
React component for datetime picker by Moment.js
Stars: ✭ 85 (-6.59%)
Mutual labels:  moment
Moment
一瞬,记录美好瞬间。
Stars: ✭ 31 (-65.93%)
Mutual labels:  moment

moment-business

Travis build status Test Coverage Dependency 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.

Guides

Dates and times

This library only works when you pass in dates without times. What this means is that you should not use Moment objects built from dates such as "2016-07-25T13:43:00.000+00:00". If you have datetimes that you wish to use with this library, then you must:

  1. use Moment's startOf() method to set this to be the start of the day
  2. manually strip out the information after the T before creating your Moment object

If you do not do this, then this library will not return the results that you expect.

Intervals

This library uses inclusive start, exclusive end intervals. What this means is that the start day is included in the result, but the end day is not.

This is consistent with how Moment's intervals work.

For example, the total number of days between March 1st, 2020 and March 2nd, 2020 will be computed as 1.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].