Skip to content

Commit

Permalink
feat(hMonth): add support to month name
Browse files Browse the repository at this point in the history
  • Loading branch information
msarhan committed Jun 13, 2015
1 parent 1acf2d1 commit 5143d5a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -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 <xsoh.k7@gmail.com>"
Expand Down
5 changes: 4 additions & 1 deletion moment-hijri.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
14 changes: 14 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 5143d5a

Please sign in to comment.