diff --git a/lib/utils/mercadopagoDate.js b/lib/utils/mercadopagoDate.js index 927e0e8c..29bd77b7 100644 --- a/lib/utils/mercadopagoDate.js +++ b/lib/utils/mercadopagoDate.js @@ -1,12 +1,14 @@ -var moment = require('moment'); +var dayjs = require("dayjs"); +var utc = require('dayjs/plugin/utc') +dayjs.extend(utc) var mercadopagoDate = function mercadopagoDate() { if (arguments.length === 1) { - this.date = moment(arguments[0]); + this.date = dayjs(arguments[0]); } else if (arguments.length === 2) { - this.date = moment(arguments[0], arguments[1]); + this.date = dayjs(arguments[0], arguments[1]); } else { - this.date = moment(); + this.date = dayjs(); } }; @@ -14,7 +16,9 @@ var mercadopagoDate = function mercadopagoDate() { * Converts a mercadopagoDate to ISO_8601 String equivalent */ mercadopagoDate.prototype.toString = function (utc) { - if (utc !== undefined && (typeof utc === 'number')) return this.date.utc(utc).format(mercadopagoDate.ISO_8601); + if (utc !== undefined && typeof utc === "number") { + return this.date.utcOffset(utc).format(mercadopagoDate.ISO_8601); + } return this.date.format(mercadopagoDate.ISO_8601); }; @@ -32,24 +36,24 @@ mercadopagoDate.prototype.toDate = function () { * @returns {mercadopagoDate} */ mercadopagoDate.prototype.add = function (days) { - this.date.add(days, 'day'); + this.date = this.date.add(days, "day"); return this; }; /** - * Substract days to a mercadopagoDate + * Subtract days from a mercadopagoDate * @param days * @returns {mercadopagoDate} */ mercadopagoDate.prototype.subtract = function (days) { - this.date.subtract(days, 'day'); + this.date = this.date.subtract(days, "day"); return this; }; /** - * ISO_8601 format for moment library + * ISO_8601 format for dayjs library * @type {string} */ -mercadopagoDate.ISO_8601 = 'YYYY-MM-DDTHH:mm:ss.SSSZ'; +mercadopagoDate.ISO_8601 = "YYYY-MM-DDTHH:mm:ss.SSSZ"; module.exports = mercadopagoDate; diff --git a/package-lock.json b/package-lock.json index 9ac00678..ca68c017 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "ajv": "^6.12.3", "bluebird": "3.4.7", - "moment": "^2.29.4", + "dayjs": "^1.11.7", "request": "^2.88.0", "request-etag": "2.0.3", "uuid": "3.0.1" @@ -1257,6 +1257,11 @@ "node": ">=0.10" } }, + "node_modules/dayjs": { + "version": "1.11.7", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.7.tgz", + "integrity": "sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ==" + }, "node_modules/debug": { "version": "4.3.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz", @@ -3330,14 +3335,6 @@ "url": "https://github.com/chalk/supports-color?sponsor=1" } }, - "node_modules/moment": { - "version": "2.29.4", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", - "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==", - "engines": { - "node": "*" - } - }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -5745,6 +5742,11 @@ "assert-plus": "^1.0.0" } }, + "dayjs": { + "version": "1.11.7", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.7.tgz", + "integrity": "sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ==" + }, "debug": { "version": "4.3.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz", @@ -7285,11 +7287,6 @@ "integrity": "sha1-j3uhUSrhJxYR2SdmnZm2wumfBY8=", "dev": true }, - "moment": { - "version": "2.29.4", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", - "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==" - }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", diff --git a/package.json b/package.json index a9694790..1fac0cfb 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "dependencies": { "ajv": "^6.12.3", "bluebird": "3.4.7", - "moment": "^2.29.4", + "dayjs": "^1.11.7", "request": "^2.88.0", "request-etag": "2.0.3", "uuid": "3.0.1" diff --git a/test/mercadopagoDate.js b/test/mercadopagoDate.js index 88d28bbb..e2712d13 100644 --- a/test/mercadopagoDate.js +++ b/test/mercadopagoDate.js @@ -1,6 +1,8 @@ /* eslint-env node, mocha */ var chai = require('chai'); -var moment = require('moment'); +var dayjs = require('dayjs'); +var utc = require('dayjs/plugin/utc'); +dayjs.extend(utc); var MercadopagoDate = require('../lib/utils/mercadopagoDate'); var assert = chai.assert; @@ -9,7 +11,7 @@ describe('MercadopagoDate Class', function () { // I'm getting the current offset, because if the test server has another TZ, this tests will crash before(function () { - var currentOffset = (moment('2016-01-01').utcOffset() / 60); + var currentOffset = (dayjs('2016-01-01').utcOffset() / 60); stringOffset = (currentOffset < 0) ? '-' : '+'; diff --git a/test/utils.js b/test/utils.js index 950eee57..60b9711b 100644 --- a/test/utils.js +++ b/test/utils.js @@ -1,6 +1,8 @@ /* eslint-env node, mocha */ var chai = require('chai'); -var moment = require('moment'); +var dayjs = require('dayjs'); +var utc = require('dayjs/plugin/utc'); +dayjs.extend(utc); var MercadopagoDate = require('../lib/utils/mercadopagoDate'); var assert = chai.assert; var mp = require('../index.js'); @@ -10,7 +12,7 @@ describe('Utils Module', function () { // I'm getting the current offset, because if the test server has another TZ, this tests will crash before(function () { - var currentOffset = (moment('2016-01-01').utcOffset() / 60); + var currentOffset = (dayjs('2016-01-01').utcOffset() / 60); stringOffset = (currentOffset < 0) ? '-' : '+'; @@ -34,11 +36,11 @@ describe('Utils Module', function () { }); it('Invalid Date Format (string)', function () { - assert.throws(mp.utils.date.from.bind(mp.utils, '2016/01/01'), 'Invalid date sent'); + assert.throws(mp.utils.date.from.bind(mp.utils.date, '2016/01/01'), 'Invalid date sent'); }); it('Invalid Date Format (empty object)', function () { - assert.throws(mp.utils.date.from.bind(mp.utils, {}), 'Invalid date sent'); + assert.throws(mp.utils.date.from.bind(mp.utils.date, {}), 'Invalid date sent'); }); it('Valid date with Date Object', function () {