From 69d05dbe26590955c91d2dd0f018f37aa6ab8129 Mon Sep 17 00:00:00 2001 From: SuhailAlkowaileet Date: Mon, 28 May 2018 00:52:50 +0300 Subject: [PATCH] Fix 'iDate' add and sub - 'iDate' fix is done by @abublihi . - Update `moment-hijri` to version `2.1.0` Co-Authored-By: Abdulsalam salh alblihi --- .dockerignore | 1 + .travis.yml | 6 ++++- bower.json | 4 ++-- moment-hijri.js | 8 ++++++- package.json | 2 +- test.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..66dc905 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +undefined \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 244b7e8..53fc891 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,7 @@ language: node_js node_js: - - '0.10' + - "8" + - "7" + - "6" + - "5" + - "4" diff --git a/bower.json b/bower.json index 36b433c..913c9fc 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "moment-hijri", "main": "moment-hijri.js", - "version": "0.4.2", + "version": "2.1.0", "homepage": "https://github.com/xsoh/moment-hijri", "authors": [ "Suhail Alkowaileet " @@ -27,6 +27,6 @@ "tests" ], "dependencies": { - "momentjs": "~2.10.3" + "momentjs": "^2.22.1" } } diff --git a/moment-hijri.js b/moment-hijri.js index d586d7e..8fd782d 100644 --- a/moment-hijri.js +++ b/moment-hijri.js @@ -127,6 +127,7 @@ , parseTokenOneOrTwoDigits = /\d\d?/, parseTokenOneToThreeDigits = /\d{1,3}/, parseTokenThreeDigits = /\d{3}/, parseTokenFourDigits = /\d{1,4}/, parseTokenSixDigits = /[+\-]?\d{1,6}/, parseTokenWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.?)|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i, parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/i, parseTokenT = /T/i, parseTokenTimestampMs = /[\+\-]?\d+(\.\d{1,3})?/ , unitAliases = { + hd: 'idate', hm: 'imonth', hy: 'iyear' } @@ -723,7 +724,10 @@ this.iYear(this.iYear() + val) } else if (units === 'imonth') { this.iMonth(this.iMonth() + val) - } else { + } else if (units === 'idate') { + this.iDate(this.iDate() + val) + } + else { moment.fn.add.call(this, val, units) } return this @@ -741,6 +745,8 @@ this.iYear(this.iYear() - val) } else if (units === 'imonth') { this.iMonth(this.iMonth() - val) + } else if (units === 'idate') { + this.iDate(this.iDate() - val) } else { moment.fn.subtract.call(this, val, units) } diff --git a/package.json b/package.json index b84f7dc..a6cb3d2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "moment-hijri", - "version": "2.0.1", + "version": "2.1.0", "description": "A Hijri calendar (Based on Umm al-Qura calculations) plugin for moment.js.", "author": { "name": "Suhail Alkowaileet", diff --git a/test.js b/test.js index be87563..0246523 100644 --- a/test.js +++ b/test.js @@ -333,6 +333,26 @@ describe('moment', function() { it('should also has iYears alias', function() { moment.fn.iYear.should.be.equal(moment.fn.iYears) }) + + it('should add years', function() { + var m = moment('1409-07-18', 'iYYYY-iMM-iDD') + m.add(1, 'iYear') + m.format('iYYYY-iMM-iDD').should.be.equal('1410-07-18') + m.add(4, 'iYear') + m.format('iYYYY-iMM-iDD').should.be.equal('1414-07-18') + m.add(1, 'iYear') + m.format('iYYYY-iMM-iDD').should.be.equal('1415-07-18') + }) + + it('should subtract years', function() { + var m = moment('1409-07-18', 'iYYYY-iMM-iDD') + m.subtract(1, 'iYear') + m.format('iYYYY-iMM-iDD').should.be.equal('1408-07-18') + m.subtract(5, 'iYear') + m.format('iYYYY-iMM-iDD').should.be.equal('1403-07-18') + m.subtract(1, 'iYear') + m.format('iYYYY-iMM-iDD').should.be.equal('1402-07-18') + }) }) describe('#iMonth', function() { @@ -372,6 +392,26 @@ describe('moment', function() { m.iMonth('Jum-I') m.format('iYYYY/iM/iD').should.be.equal('1436/5/10') }) + + it('should add months', function() { + var m = moment('1409-07-18', 'iYYYY-iMM-iDD') + m.add(1, 'iMonth') + m.format('iYYYY-iMM-iDD').should.be.equal('1409-08-18') + m.add(4, 'iMonth') + m.format('iYYYY-iMM-iDD').should.be.equal('1409-12-18') + m.add(1, 'iMonth') + m.format('iYYYY-iMM-iDD').should.be.equal('1410-01-18') + }) + + it('should subtract months', function() { + var m = moment('1409-07-18', 'iYYYY-iMM-iDD') + m.subtract(1, 'iMonth') + m.format('iYYYY-iMM-iDD').should.be.equal('1409-06-18') + m.subtract(5, 'iMonth') + m.format('iYYYY-iMM-iDD').should.be.equal('1409-01-18') + m.subtract(1, 'iMonth') + m.format('iYYYY-iMM-iDD').should.be.equal('1408-12-18') + }) }) describe('#iDate', function() { @@ -401,6 +441,26 @@ describe('moment', function() { it('should also has iDates alias', function() { moment.fn.iDate.should.be.equal(moment.fn.iDates) }) + + it('should add days', function() { + var m = moment('1409-07-18', 'iYYYY-iMM-iDD') + m.add(1, 'iDate') + m.format('iYYYY-iMM-iDD').should.be.equal('1409-07-19') + m.add(10, 'iDate') + m.format('iYYYY-iMM-iDD').should.be.equal('1409-07-29') + m.add(1, 'iDate') + m.format('iYYYY-iMM-iDD').should.be.equal('1409-08-01') + }) + + it('should subtract days', function() { + var m = moment('1409-07-18', 'iYYYY-iMM-iDD') + m.subtract(1, 'iDate') + m.format('iYYYY-iMM-iDD').should.be.equal('1409-07-17') + m.subtract(10, 'iDate') + m.format('iYYYY-iMM-iDD').should.be.equal('1409-07-07') + m.subtract(7, 'iDate') + m.format('iYYYY-iMM-iDD').should.be.equal('1409-06-30') + }) }) describe('#iDayOfYear', function() { @@ -446,5 +506,4 @@ describe('moment', function() { }) - })