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.
139 lines (114 loc) • 5.32 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: index.js</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">Source: index.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* Represents a javascript class 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 nDays or mWeeks etc.
*
* @class
*/
const DatesYMD = require("./DatesYMD");
/**
* Represents a utility for calculating the difference between two dates in formatted or desired customized ways.
*
* @typedef {Object} DatesYMD
* @property {Function} diffArray - Calculates the difference between two dates and returns an array containing years, months, days, and a formatted difference string.
* @property {Function} formattedYMD - Returns the formatted difference between two dates.
* @property {Function} customizeFormat - Customizes the difference using specified units and separators.
* @property {Function} diffInMonths - Calculates the difference in months between two dates.
* @property {Function} diffInWeeks - Calculates the difference in weeks between two dates.
* @property {Function} diffInDays - Calculates the difference in days between two dates.
* @property {Function} diffInYears - Calculates the difference in years between two dates.
* @property {Function} diffInHours - Calculates the difference in hours between two dates.
* @property {Function} diffInMinutes - Calculates the difference in minutes between two dates.
* @property {Function} diffInSeconds - Calculates the difference in seconds between two dates.
*/
/**
* Creates an instance of DatesYMD.
*
* @param {string} firstDate (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).
* @param {string} secondDate (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).
*
* @returns {DatesYMD} An object containing methods for date difference calculations.
*/
const diffDates = require("./diff-dates");
/**
* Makes the `diff` method available as the method of the Date object on importing the diff-ymd-package.
*
* This method creates an instance of DatesYMD to calculates the difference between Date instance and the passed date.
*
* @function
* @memberof Date.prototype
* @name diff
* @param {string} date (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).
* @returns {DatesYMD} An object containing methods for date difference calculations.
*/
if (!Date.prototype.diff) {
Date.prototype.diff = function (date) {
return diffDates(this, date);
};
}
// Export the DatesYMD class and equivalent function diffDates for usages in other modules
module.exports = DatesYMD; // default export for class
module.exports.diffDates = diffDates; // named export for equivalent function
</code></pre>
</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>