From 5143d5ada8f708ed77291c6a4f0d73d37e5cccb3 Mon Sep 17 00:00:00 2001 From: "Mouaffak A. Sarhan" Date: Sat, 13 Jun 2015 22:24:15 +0300 Subject: [PATCH] feat(hMonth): add support to month name --- bower.json | 2 +- moment-hijri.js | 5 ++++- package.json | 2 +- test.js | 14 ++++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/bower.json b/bower.json index 05635f2..36b433c 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "moment-hijri", "main": "moment-hijri.js", - "version": "0.4.1", + "version": "0.4.2", "homepage": "https://github.com/xsoh/moment-hijri", "authors": [ "Suhail Alkowaileet " diff --git a/moment-hijri.js b/moment-hijri.js index 80eb0d3..04442bf 100644 --- a/moment-hijri.js +++ b/moment-hijri.js @@ -650,8 +650,11 @@ if (input != null) { if (typeof input === 'string') { input = this.localeData().hMonthsParse(input) - if (typeof input !== 'number') + if(input >= 0) { + input -= 1 + } else { return this + } } h = toHijri(this.year(), this.month(), this.date()) lastDay = Math.min(h.hd, hMoment.hDaysInMonth(h.hy, input)) diff --git a/package.json b/package.json index 7e2fcc4..de0ffa3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "moment-hijri", - "version": "0.4.1", + "version": "0.4.2", "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 bfbc2c2..86cd446 100644 --- a/test.js +++ b/test.js @@ -390,6 +390,20 @@ describe('moment', function() { it('should also has hMonths alias', function() { moment.fn.hMonth.should.be.equal(moment.fn.hMonths) }) + + it('should set month by name and short name', function() { + var m = moment(new Date(2015, 0, 1)) + m.hMonth('Shawwal') + m.format('hYYYY/hM/hD').should.be.equal('1436/10/10') + + m = moment(new Date(2015, 0, 1)) + m.hMonth('Safar') + m.format('hYYYY/hM/hD').should.be.equal('1436/2/10') + + m = moment(new Date(2015, 0, 1)) + m.hMonth('Jum-I') + m.format('hYYYY/hM/hD').should.be.equal('1436/5/10') + }) }) describe('#hDate', function() {