diff-ymd-package
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -281,2 +281,25 @@ ## Changelog | ||
### [v3.1.0] | ||
#### Added | ||
- **Simplification:** Integrate diff as global Date Object method on importing | ||
- Added source codes for integrating to Date | ||
- Added the README.md codes for documenting integration. | ||
#### Changed | ||
- Updated the README.md documentation for documenting integration. | ||
- Updated source codes | ||
- Enhanced README.md for follwing best practices and recommended practices | ||
#### Fixed | ||
- Fixed some issues related to the new changes. | ||
- Configured files for publishing diff-ymd-package v3.1.0. | ||
#### Documentation | ||
- README.md updated: Added consistent formating and recommended for best practices. | ||
### [Next Release] - Collecting issues and new features for next release | ||
@@ -286,4 +309,4 @@ | ||
- [Unreleased](https://github.com/farhan7reza7/diff-ymd-package/compare/v3.0.0...HEAD) | ||
- [v3.0.0](https://github.com/farhan7reza7/diff-ymd-package/releases/tag/v3.0.0) | ||
- [Unreleased](https://github.com/farhan7reza7/diff-ymd-package/compare/v3.1.0...HEAD) | ||
- [v3.1.0](https://github.com/farhan7reza7/diff-ymd-package/releases/tag/v3.1.0) | ||
- [Next Release](https://github.com/farhan7reza7/diff-ymd-package/milestone/2) |
@@ -6,3 +6,6 @@ module.exports = { | ||
collectCoverage: true, | ||
coverageReporters: ['text', 'cobertura'], | ||
testEnvironment: 'node', | ||
}; |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.DatesYMD=e():t.DatesYMD=e()}(this,(()=>{return t={609:t=>{function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function r(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,n(i.key),i)}}function n(t){var r=function(t,r){if("object"!=e(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,"string");if("object"!=e(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==e(r)?r:String(r)}var i=function(){function t(e,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.firstDate=e,this.secondDate=r,this.handleEmpty=function(){var t,e;return""===this.firstDate&&""===this.secondDate?(t=new Date,e=new Date):""===this.firstDate?(t=new Date,e=new Date(this.secondDate)):""===this.secondDate?(t=new Date(this.firstDate),e=new Date):(t=new Date(this.firstDate),e=new Date(this.secondDate)),[t,e]},this.swapDates=function(t,e){if(t.getTime()<e.getTime()){var r=t;t=e,e=r}return[t,e]},this.initDiff=function(){var t,e,r,n;return t=(r=this.handleEmpty())[0],e=r[1],(n=this.swapDates(t,e))&&(t=n[0],e=n[1]),[t,e]}}var e,n;return e=t,(n=[{key:"diffArray",value:function(){var t,e,r,n,i,o,f,a,u,s,c,y,l;return i=(f=this.initDiff())[0],a=(o=f[1]).getFullYear(),u=i.getFullYear(),s=o.getMonth()+1,c=i.getMonth()+1,y=o.getDate(),l=i.getDate(),c>=s&&l>=y?(t=u-a,e=c-s,r=l-y):c<s&&l>=y?(r=l-y,e=c+12-s,t=u-1-a):c>s&&l<y?(e=c-s-1,t=u-a,r=2==(n=c-1)?u%4==0?l>29?l:29-y+l:l>28?l:28-y+l:4===n||6===n||8===n||11===n?l>30?l:30-y+l:31-y+l):c<=s&&l<y&&(e=c+11-s,t=u-1-a,r=2==(n=c-1)?u%4==0?l>29?l:29-y+l:l>28?l:28-y+l:4===n||6===n||8===n||11===n?l>30?l:30-y+l:31-y+l),[t,e,r,t+"Y "+e+"M "+r+"D"]}},{key:"formattedYMD",value:function(){return this.diffArray()[3]}},{key:"customizeFormat",value:function(t,e,r,n){return this.diffArray()[0]+t+n+this.diffArray()[1]+e+n+this.diffArray()[2]+r}},{key:"diffInMonths",value:function(){var t;return 12*(t=this.diffArray())[0]+t[1]}},{key:"diffInWeeks",value:function(){var t,e,r;return e=(t=this.initDiff())[0],r=t[1],Math.floor((e.getTime()-r.getTime())/6048e5)}},{key:"diffInDays",value:function(){var t,e,r;return e=(t=this.initDiff())[0],r=t[1],Math.floor((e.getTime()-r.getTime())/864e5)}},{key:"diffInYears",value:function(){return this.diffArray()[0]}},{key:"diffInHours",value:function(){return 24*this.diffInDays()}},{key:"diffInMinutes",value:function(){return 60*this.diffInHours()}},{key:"diffInSeconds",value:function(){return 60*this.diffInMinutes()}}])&&r(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),t}();t.exports=i},919:(t,e,r)=>{var n=r(609);t.exports=function(t,e){return new n(t,e)}},954:(t,e,r)=>{var n=r(609),i=r(919);t.exports=n,t.exports.diffDates=i}},e={},function r(n){var i=e[n];if(void 0!==i)return i.exports;var o=e[n]={exports:{}};return t[n](o,o.exports,r),o.exports}(954);var t,e})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.DatesYMD=e():t.DatesYMD=e()}(this,(()=>{return t={609:t=>{function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function r(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,n(i.key),i)}}function n(t){var r=function(t,r){if("object"!=e(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,"string");if("object"!=e(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==e(r)?r:String(r)}var i=function(){function t(e,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.firstDate=e,this.secondDate=r,this.handleEmpty=function(){var t,e;return""===this.firstDate&&""===this.secondDate?(t=new Date,e=new Date):""===this.firstDate?(t=new Date,e=new Date(this.secondDate)):""===this.secondDate?(t=new Date(this.firstDate),e=new Date):(t=new Date(this.firstDate),e=new Date(this.secondDate)),[t,e]},this.swapDates=function(t,e){if(t.getTime()<e.getTime()){var r=t;t=e,e=r}return[t,e]},this.initDiff=function(){var t,e,r,n;return t=(r=this.handleEmpty())[0],e=r[1],(n=this.swapDates(t,e))&&(t=n[0],e=n[1]),[t,e]}}var e,n;return e=t,(n=[{key:"diffArray",value:function(){var t,e,r,n,i,o,f,a,u,s,c,y,l;return i=(f=this.initDiff())[0],a=(o=f[1]).getFullYear(),u=i.getFullYear(),s=o.getMonth()+1,c=i.getMonth()+1,y=o.getDate(),l=i.getDate(),c>=s&&l>=y?(t=u-a,e=c-s,r=l-y):c<s&&l>=y?(r=l-y,e=c+12-s,t=u-1-a):c>s&&l<y?(e=c-s-1,t=u-a,r=2==(n=c-1)?u%4==0?l>29?l:29-y+l:l>28?l:28-y+l:4===n||6===n||8===n||11===n?l>30?l:30-y+l:31-y+l):c<=s&&l<y&&(e=c+11-s,t=u-1-a,r=2==(n=c-1)?u%4==0?l>29?l:29-y+l:l>28?l:28-y+l:4===n||6===n||8===n||11===n?l>30?l:30-y+l:31-y+l),[t,e,r,t+"Y "+e+"M "+r+"D"]}},{key:"formattedYMD",value:function(){return this.diffArray()[3]}},{key:"customizeFormat",value:function(t,e,r,n){return this.diffArray()[0]+t+n+this.diffArray()[1]+e+n+this.diffArray()[2]+r}},{key:"diffInMonths",value:function(){var t;return 12*(t=this.diffArray())[0]+t[1]}},{key:"diffInWeeks",value:function(){var t,e,r;return e=(t=this.initDiff())[0],r=t[1],Math.floor((e.getTime()-r.getTime())/6048e5)}},{key:"diffInDays",value:function(){var t,e,r;return e=(t=this.initDiff())[0],r=t[1],Math.floor((e.getTime()-r.getTime())/864e5)}},{key:"diffInYears",value:function(){return this.diffArray()[0]}},{key:"diffInHours",value:function(){return 24*this.diffInDays()}},{key:"diffInMinutes",value:function(){return 60*this.diffInHours()}},{key:"diffInSeconds",value:function(){return 60*this.diffInMinutes()}}])&&r(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),t}();t.exports=i},919:(t,e,r)=>{var n=r(609);t.exports=function(t,e){return new n(t,e)}},954:(t,e,r)=>{var n=r(609),i=r(919);Date.prototype.diff=function(t){return i(this,t)},t.exports=n,t.exports.diffDates=i}},e={},function r(n){var i=e[n];if(void 0!==i)return i.exports;var o=e[n]={exports:{}};return t[n](o,o.exports,r),o.exports}(954);var t,e})); |
{ | ||
"name": "diff-ymd-package", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "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.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -9,2 +9,3 @@ # diff-ymd-package | ||
[![CI][ci-image]][ci-url] | ||
[![Codecov-report][codecov-img]][codecov-url] | ||
[![License][license-image]][licence-url] | ||
@@ -79,2 +80,13 @@ [![LinkedIn][linked-image]][linked-url] | ||
**`OR` for version `3.1.0` and `above`** | ||
**Can use simplified function `diff` as Global Date Object method** | ||
```javascript | ||
//require('@farhan7reza7/diff-ymd-package'); //or | ||
require('diff-ymd-package'); // can use any if authenticated | ||
``` | ||
### `Create an instance:` | ||
@@ -97,5 +109,22 @@ | ||
const Formatter = DatesYMD.diffDates(date1, date2); // can use any | ||
const Formatter = DatesYMD.diffDates(date1, date2); | ||
``` | ||
**`OR` for version `3.1.0` and `above`** | ||
**Can use simplified function `diff` as Global Date Object method** | ||
```javascript | ||
const date1 = '2022-01-01'; | ||
const date2 = '2023-12-31'; | ||
const DateInstance = new Date(date1); // create Global Date instance | ||
const Formatter = DateInstance.diff(date2); //create an instance to `calculates the difference` between `Date instance` and the `date passed to it` | ||
``` | ||
**Note:** For `diff` as `Global Date method`, `only one date(the date to be subtracted from/to Global Date instance)` passed to `diff method` | ||
**`diff` method create an instance of DatesYMD to `calculates the difference` between `Date instance` and the `date passed to it`** | ||
**Note:** For CDN based, only **DatesYMD** constructor name creates an instance, and can use diffDates as well, but only using global **DatesYMD** like **DatesYMD.diffDates(...)** | ||
@@ -399,1 +428,3 @@ | ||
[linked-url]: https://www.linkedin.com/in/farhan7reza7/ | ||
[codecov-img]: https://codecov.io/gh/farhan7reza7/diff-ymd-package/graph/badge.svg?token=UZWFE2WAJF | ||
[codecov-url]: https://codecov.io/gh/farhan7reza7/diff-ymd-package |
@@ -6,5 +6,4 @@ /** | ||
*/ | ||
const DatesYMD = require("./DatesYMD"); | ||
const DatesYMD = require('./DatesYMD'); | ||
/** | ||
@@ -36,6 +35,21 @@ * Represents a utility for calculating the difference between two dates in formatted or desired customized ways. | ||
*/ | ||
const diffDates = require("./diff-dates"); | ||
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. | ||
*/ | ||
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 |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1176808
64
1243
427