UNPKG

diff-ymd-package

Version:

A javascript library for calculating the difference between two dates in formatted ways like (aY bM cD)(aYears bMonths cDays) or customized desired formats like aY-bM-cD or aYears-bMonths-cDays or kDays or mWeeks or nMonths etc.

812 lines (654 loc) 24.2 kB
<!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>diff-ymd-package Documentation</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"><a href="https://github.com/farhan7reza7/diff-ymd-package">diff-ymd-package</a></h1> <h4>diff-ymd-package provides APIs for calculating the difference between two dates in formatted ways like (aY bM cD)(aYears bMonths cDays) or customized desired formats like aY-bM-cD or aYears-bMonths-cDays or kDays or mWeeks or nMonths etc.</h4> <section> <header> <h2></h2> </header> <article> <div class="container-overview"> <dl class="details"></dl> </div> <h3 class="subsection-title">diff as Global Date Object method</h3> <h4 class="name" id="diff"> <span class="type-signature"></span>diffDates<span class="signature" >(date)</span ><span class="type-signature"> &rarr; {<a href="global.html#DatesYMD">DatesYMD</a>}</span > </h4> <div class="description">Creates an instance of DatesYMD.</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"> (type- String but Number for epoch, and Object for dateObject) - The date to be differed, in the format 'yyyy-mm-dd' or 'yyyy/mm/dd' or yyyy.mm.dd or dateString or dateObject or Timestamp(epoch). </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#line48">line 48</a> </li> </ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc"> An object containing methods for date difference calculations. </div> <dl> <dt>Type</dt> <dd> <span class="param-type" ><a href="global.html#DatesYMD">DatesYMD</a></span > </dd> </dl> <h3 class="subsection-title">Global DatesYMD methods</h3> <h4 class="name" id="diffDates"> <span class="type-signature"></span>diffDates<span class="signature" >(firstDate, secondDate)</span ><span class="type-signature"> &rarr; {<a href="global.html#DatesYMD">DatesYMD</a>}</span > </h4> <div class="description">Creates an instance of DatesYMD.</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>firstDate</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"> (type- String but Number for epoch, and Object for dateObject) - The first date in the format 'yyyy-mm-dd' or 'yyyy/mm/dd' or yyyy.mm.dd or dateString or dateObject or Timestamp(epoch). </td> </tr> <tr> <td class="name"><code>secondDate</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"> (type- String but Number for epoch, and Object for dateObject) - The second date in the format 'yyyy-mm-dd' or 'yyyy/mm/dd' or yyyy.mm.dd or dateString or dateObject or Timestamp(epoch). </td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="diff-ymd.js.html">diff-ymd.js</a>, <a href="diff-ymd.js.html#line368">line 368</a> </li> </ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc"> An object containing methods for date difference calculations. </div> <dl> <dt>Type</dt> <dd> <span class="param-type" ><a href="global.html#DatesYMD">DatesYMD</a></span > </dd> </dl> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="customizeFormat"> <span class="type-signature"></span>customizeFormat<span class="signature" >(yearUnit, monthUnit, dayUnit, partSeparator)</span ><span class="type-signature"> &rarr; {string}</span> </h4> <div class="description"> Customizes the difference using specified units and separators like (a + yearUnit + partSeparator + b + monthUnit + partSeparator + c + dayUnit), eg. aYs-bMs-cDs etc. </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>yearUnit</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The unit for years.</td> </tr> <tr> <td class="name"><code>monthUnit</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The unit for months.</td> </tr> <tr> <td class="name"><code>dayUnit</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The unit for days.</td> </tr> <tr> <td class="name"><code>partSeparator</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"> The separator between year, month, and day parts. </td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="diff-ymd.js.html">diff-ymd.js</a>, <a href="diff-ymd.js.html#line552">line 552</a> </li> </ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc">The customized formatted difference.</div> <dl> <dt>Type</dt> <dd> <span class="param-type">string</span> </dd> </dl> <h4 class="name" id="diffArray"> <span class="type-signature"></span>diffArray<span class="signature" >()</span ><span class="type-signature"> &rarr; {Array}</span> </h4> <div class="description"> Calculates the difference between two dates and returns an array containing years, months, days, and a formatted difference string. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="diff-ymd.js.html">diff-ymd.js</a>, <a href="diff-ymd.js.html#line438">line 438</a> </li> </ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc"> An array containing the calculated years, months, days, and the formatted difference. </div> <dl> <dt>Type</dt> <dd> <span class="param-type">Array</span> </dd> </dl> <h4 class="name" id="diffInDays"> <span class="type-signature"></span>diffInDays<span class="signature" >()</span ><span class="type-signature"> &rarr; {number}</span> </h4> <div class="description"> Calculates the difference in days between two dates. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="diff-ymd.js.html">diff-ymd.js</a>, <a href="diff-ymd.js.html#line614">line 614</a> </li> </ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc">The difference in days.</div> <dl> <dt>Type</dt> <dd> <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="diffInHours"> <span class="type-signature"></span>diffInHours<span class="signature" >()</span ><span class="type-signature"> &rarr; {number}</span> </h4> <div class="description"> Calculates the difference in hours between two dates. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="diff-ymd.js.html">diff-ymd.js</a>, <a href="diff-ymd.js.html#line651">line 651</a> </li> </ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc">The difference in hours.</div> <dl> <dt>Type</dt> <dd> <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="diffInMinutes"> <span class="type-signature"></span>diffInMinutes<span class="signature" >()</span ><span class="type-signature"> &rarr; {number}</span> </h4> <div class="description"> Calculates the difference in minutes between two dates. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="diff-ymd.js.html">diff-ymd.js</a>, <a href="diff-ymd.js.html#line668">line 668</a> </li> </ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc">The difference in minutes.</div> <dl> <dt>Type</dt> <dd> <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="diffInMonths"> <span class="type-signature"></span>diffInMonths<span class="signature" >()</span ><span class="type-signature"> &rarr; {number}</span> </h4> <div class="description"> Calculates the difference in months between two dates. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="diff-ymd.js.html">diff-ymd.js</a>, <a href="diff-ymd.js.html#line574">line 574</a> </li> </ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc">The difference in months.</div> <dl> <dt>Type</dt> <dd> <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="diffInSeconds"> <span class="type-signature"></span>diffInSeconds<span class="signature" >()</span ><span class="type-signature"> &rarr; {number}</span> </h4> <div class="description"> Calculates the difference in seconds between two dates. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="diff-ymd.js.html">diff-ymd.js</a>, <a href="diff-ymd.js.html#line685">line 685</a> </li> </ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc">The difference in seconds.</div> <dl> <dt>Type</dt> <dd> <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="diffInWeeks"> <span class="type-signature"></span>diffInWeeks<span class="signature" >()</span ><span class="type-signature"> &rarr; {number}</span> </h4> <div class="description"> Calculates the difference in weeks between two dates. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="diff-ymd.js.html">diff-ymd.js</a>, <a href="diff-ymd.js.html#line594">line 594</a> </li> </ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc">The difference in weeks.</div> <dl> <dt>Type</dt> <dd> <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="diffInYears"> <span class="type-signature"></span>diffInYears<span class="signature" >()</span ><span class="type-signature"> &rarr; {number}</span> </h4> <div class="description"> Calculates the difference in years between two dates. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="diff-ymd.js.html">diff-ymd.js</a>, <a href="diff-ymd.js.html#line634">line 634</a> </li> </ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc">The difference in years.</div> <dl> <dt>Type</dt> <dd> <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="formattedYMD"> <span class="type-signature"></span>formattedYMD<span class="signature" >()</span ><span class="type-signature"> &rarr; {string}</span> </h4> <div class="description"> Returns the formatted difference between two dates. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="diff-ymd.js.html">diff-ymd.js</a>, <a href="diff-ymd.js.html#line539">line 539</a> </li> </ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc"> The formatted difference in the format 'aY bM cD'. </div> <dl> <dt>Type</dt> <dd> <span class="param-type">string</span> </dd> </dl> <h3 class="subsection-title">Type Definitions</h3> <h4 class="name" id="DatesYMD">DatesYMD</h4> <div class="description"> Represents a utility for calculating the difference between two dates in formatted or desired customized ways. </div> <h5>Type:</h5> <ul> <li> <span class="param-type">Object</span> </li> </ul> <h5 class="subsection-title">Properties:</h5> <table class="props"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>diffArray</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"> Calculates the difference between two dates and returns an array containing years, months, days, and a formatted difference string. </td> </tr> <tr> <td class="name"><code>formattedYMD</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"> Returns the formatted difference between two dates. </td> </tr> <tr> <td class="name"><code>customizeFormat</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"> Customizes the difference using specified units and separators. </td> </tr> <tr> <td class="name"><code>diffInMonths</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"> Calculates the difference in months between two dates. </td> </tr> <tr> <td class="name"><code>diffInWeeks</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"> Calculates the difference in weeks between two dates. </td> </tr> <tr> <td class="name"><code>diffInDays</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"> Calculates the difference in days between two dates. </td> </tr> <tr> <td class="name"><code>diffInYears</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"> Calculates the difference in years between two dates. </td> </tr> <tr> <td class="name"><code>diffInHours</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"> Calculates the difference in hours between two dates. </td> </tr> <tr> <td class="name"><code>diffInMinutes</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"> Calculates the difference in minutes between two dates. </td> </tr> <tr> <td class="name"><code>diffInSeconds</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"> Calculates the difference in seconds between two dates. </td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="diff-ymd.js.html">diff-ymd.js</a>, <a href="diff-ymd.js.html#line342">line 342</a> </li> </ul> </dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2> <h3>Classes</h3> <ul> <li><a href="global.html#DatesYMD">DatesYMD</a></li> </ul> <h3>Global</h3> <ul> <li><a href="global.html#DatesYMD">DatesYMD</a></li> </ul> <h3>Global object special method</h3> <ul> <li><a href="global.html#diffDates">diffDates</a></li> </ul> <h3>diff as Global Date Object method</h3> <ul> <li><a href="global.html#diff">diff</a></li> </ul> <h3>DatesYMD Methods</h3> <ul> <li><a href="global.html#customizeFormat">customizeFormat</a></li> <li><a href="global.html#diffArray">diffArray</a></li> <li><a href="global.html#diffInDays">diffInDays</a></li> <li><a href="global.html#diffInHours">diffInHours</a></li> <li><a href="global.html#diffInMinutes">diffInMinutes</a></li> <li><a href="global.html#diffInMonths">diffInMonths</a></li> <li><a href="global.html#diffInSeconds">diffInSeconds</a></li> <li><a href="global.html#diffInWeeks">diffInWeeks</a></li> <li><a href="global.html#diffInYears">diffInYears</a></li> <li><a href="global.html#formattedYMD">formattedYMD</a></li> </ul> </nav> <br class="clear" /> <footer> Documentation generated for <a href="https://www.npmjs.com/package/diff-ymd-package">diff-ymd-package</a> </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"></script> </body> </html>