diff --git a/dist/handlebars-i18n.js b/dist/handlebars-i18n.js index d8b2a65..8d0bfe3 100644 --- a/dist/handlebars-i18n.js +++ b/dist/handlebars-i18n.js @@ -456,6 +456,13 @@ * @returns {string} */ function (dateInput, offset, unit, options) { + + if (typeof dateInput !== 'number' && typeof dateInput !== 'string') + throw new Error('@ handlebars-i18n: invalid first argument "dateInput" was given for _dateAdd.'); + + if (typeof offset !== 'number') + throw new Error('@ handlebars-i18n: invalid second argument "offset" was given for _dateAdd.'); + const date = __createDateObj(dateInput); unit = unit || 'hour'; diff --git a/test/handlebars-i18n.test.js b/test/handlebars-i18n.test.js index 85ff469..8864b54 100644 --- a/test/handlebars-i18n.test.js +++ b/test/handlebars-i18n.test.js @@ -59,6 +59,10 @@ describe('handlebars-i18n Tests', function () { assert.isFunction(hI18n.helpers._date); }); + it('after method call init() HandlebarsEnvironment object should have a function _dateAdd', function () { + assert.isFunction(hI18n.helpers._dateAdd); + }); + it('after method call init() HandlebarsEnvironment object should have a function _dateRel', function () { assert.isFunction(hI18n.helpers._dateRel); }); @@ -256,6 +260,20 @@ describe('handlebars-i18n Tests', function () { }); + /**************************************** + Tests against function _date + ****************************************/ + + + it('function _dateAdd should return "12/17/1995" when called with parameters "December 17, 1995 02:00:00", 1, and "day"', function () { + i18next.changeLanguage('en'); + const res = hI18n.helpers._dateAdd('December 17, 1995 02:00:00', 1, "day"); + assert.equal('12/18/1995', res); + }); + + + + /**************************************** Tests against function _dateRel ****************************************/