UNPKG

moment-working-days

Version:

This is a Moment.js plugin that allows you to calculate working days considering sequence of date(s) - similar to start-stop timer sequence. You can customize the week off days, and also declare custom dates for holidays (eg: public holidays) to exclude t

1,662 lines (478 loc) 18.7 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Class: WorkingDays</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Class: WorkingDays</h1> <section> <header> <h2><span class="attribs"><span class="type-signature"></span></span>WorkingDays<span class="signature">(config<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h2> </header> <article> <div class="container-overview"> <h4 class="name" id="WorkingDays"><span class="type-signature"></span>new WorkingDays<span class="signature">(config<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4> <div class="description"> Working days Calculator </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>config</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">Configure includeToday, verbose, weekOffDays, dateFormat, customHolidays</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line36">line 36</a> </li></ul></dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>const WorkingDays = require('moment-working-days'); const momentWorkingdays = new WorkingDays({ includeToday: true, // optional. Default true verbose: true, // optional. Default false weekOffDays: [0, 6], // optional. Default [0, 6] dateFormat: 'DD-MM-YYYY', // optional. Default 'YYYY-MM-DD' customHolidays: ['02-12-2019'], // optional customWorkingDays: ['07-12-2019'] // optional })</code></pre> </div> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="addWorkingDays"><span class="type-signature"></span>addWorkingDays<span class="signature">(date, noOfDays)</span><span class="type-signature"> &rarr; {string}</span></h4> <div class="description"> Takes date string and number of days. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>date</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="default"> </td> <td class="description last">Date string</td> </tr> <tr> <td class="name"><code>noOfDays</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="default"> 1 </td> <td class="description last">Number of days</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line186">line 186</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> returns date string after adding noOfDays working days </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>momentWorkingdays.addWorkingDays("06-12-2019", 2) // Friday // returns 10-12-2019 // Tuesday</code></pre> <h4 class="name" id="getWorkingDays"><span class="type-signature"></span>getWorkingDays<span class="signature">(data)</span><span class="type-signature"> &rarr; {number}</span></h4> <div class="description"> Takes array of dates. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>data</code></td> <td class="type"> <span class="param-type">Array.&lt;string></span> </td> <td class="description last">Array of Date string(s)</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line122">line 122</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> returns number of working days </div> <dl> <dt> Type </dt> <dd> <span class="param-type">number</span> </dd> </dl> <h5>Examples</h5> <pre class="prettyprint"><code>momentWorkingdays.getWorkingDays([ "29-11-2019", "03-12-2019", "07-12-2019", "12-12-2019" ]) // returns 6</code></pre> <pre class="prettyprint"><code>momentWorkingdays.getWorkingDays([ "29-11-2019", "03-12-2019", "07-12-2019" ]) // returns 3</code></pre> <pre class="prettyprint"><code>momentWorkingdays.getWorkingDays([ "29-11-2019" ]) // returns 6</code></pre> <h4 class="name" id="isWorkingday"><span class="type-signature"></span>isWorkingday<span class="signature">(date)</span><span class="type-signature"> &rarr; {boolean}</span></h4> <div class="description"> Util to calculate working days considering sequence of date(s) - similar to start-stop timer sequence </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>date</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">Date string</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line71">line 71</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> returns if its a working day or not </div> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> <h5>Examples</h5> <pre class="prettyprint"><code>momentWorkingdays.isWorkingday("02-12-2019") // Monday // returns 6</code></pre> <pre class="prettyprint"><code>momentWorkingdays.isWorkingday("01-12-2019") // Sunday // returns false</code></pre> <pre class="prettyprint"><code>momentWorkingdays.isWorkingday("06-12-2019") // Friday // returns true</code></pre> <h4 class="name" id="nextWorkingDay"><span class="type-signature"></span>nextWorkingDay<span class="signature">(date)</span><span class="type-signature"> &rarr; {string}</span></h4> <div class="description"> Takes date string. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>date</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">Date string</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line218">line 218</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> returns next working day </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>momentWorkingdays.nextWorkingDay("06-12-2019") // Friday // returns 09-12-2019 // Monday</code></pre> <h4 class="name" id="prevWorkingDay"><span class="type-signature"></span>prevWorkingDay<span class="signature">(date)</span><span class="type-signature"> &rarr; {string}</span></h4> <div class="description"> Takes date string. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>date</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">Date string</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line265">line 265</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> returns previous working day </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>momentWorkingdays.prevWorkingDay("09-12-2019") // Monday // returns 06-12-2019 // Friday</code></pre> <h4 class="name" id="setCustomWorkingDays"><span class="type-signature"></span>setCustomWorkingDays<span class="signature">(customWorkingDays)</span><span class="type-signature"> &rarr; {<a href="WorkingDays.html">WorkingDays</a>}</span></h4> <div class="description"> Sets customWorkingDays. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>customWorkingDays</code></td> <td class="type"> <span class="param-type">Array.&lt;string></span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line289">line 289</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> returns WorkingDays object </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="WorkingDays.html">WorkingDays</a></span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>momentWorkingdays.customWorkingDays(['07-12-2019'])</code></pre> <h4 class="name" id="setWeekOffDays"><span class="type-signature"></span>setWeekOffDays<span class="signature">(weekOffDays)</span><span class="type-signature"> &rarr; {<a href="WorkingDays.html">WorkingDays</a>}</span></h4> <div class="description"> Sets weekOffDays. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>weekOffDays</code></td> <td class="type"> <span class="param-type">Array.&lt;string></span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line277">line 277</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> returns WorkingDays object </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="WorkingDays.html">WorkingDays</a></span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>momentWorkingdays.setWeekOffDays([0, 1, 2, 3, 4, 6])</code></pre> <h4 class="name" id="subtractWorkingDays"><span class="type-signature"></span>subtractWorkingDays<span class="signature">(date, noOfDays)</span><span class="type-signature"> &rarr; {string}</span></h4> <div class="description"> Takes date string and number of days. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>date</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="default"> </td> <td class="description last">Date string</td> </tr> <tr> <td class="name"><code>noOfDays</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="default"> 1 </td> <td class="description last">Number of days</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line234">line 234</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> returns date string after subtracting noOfDays working days </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>momentWorkingdays.subtractWorkingDays("09-12-2019", 2) // Monday // returns 05-12-2019 // Thursday</code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WorkingDays.html">WorkingDays</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Wed Dec 11 2019 10:22:43 GMT+0530 (IST) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>