moment-business-days
Advanced tools
Comparing version 0.0.7 to 0.0.8
26
index.js
'use strict'; | ||
var moment = require('moment'); | ||
moment.fn.isHoliday = function () { | ||
var locale = this.localeData(); | ||
if (locale._holidays) { | ||
if (locale._holidays.indexOf(this.format(locale._holidayFormat)) >= 0) return true; | ||
} | ||
return false; | ||
}; | ||
moment.fn.isBusinessDay = function() { | ||
return !(this.day() === 0 || this.day() === 6); | ||
if (this.day() === 0 || this.day() === 6) return false; | ||
if (this.isHoliday()) return false; | ||
return true; | ||
}; | ||
@@ -67,2 +79,14 @@ | ||
moment.fn.prevBusinessDay = function() { | ||
var loop = 1; | ||
var limit = 7; | ||
while (loop < limit) { | ||
if (this.subtract(1, 'd').isBusinessDay()) { | ||
break; | ||
}; | ||
loop++; | ||
}; | ||
return this; | ||
}; | ||
moment.fn.monthBusinessDays = function() { | ||
@@ -69,0 +93,0 @@ var me = this.clone(); |
{ | ||
"name": "moment-business-days", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "MomentJS pluin to use business days ", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "./test.js" | ||
"test": "node ./test.js", | ||
"mochatest": "mocha tests/*" | ||
}, | ||
@@ -29,3 +30,7 @@ "repository": { | ||
}, | ||
"homepage": "https://github.com/kalmecak/moment-business-days" | ||
"homepage": "https://github.com/kalmecak/moment-business-days", | ||
"devDependencies": { | ||
"chai": "^3.3.0", | ||
"mocha": "^2.3.3" | ||
} | ||
} |
@@ -14,4 +14,26 @@ # moment-business-days | ||
// You'll be able use moment as you normally do | ||
```` | ||
#### Use localizaton to configure holidays: | ||
````javascript | ||
var moment = require('moment-business-days'); | ||
var july4th = '07-04-2015'; | ||
var laborDay = '09-07-2015'; | ||
moment.locale('us', { | ||
holidays: [july4th, laborDay], | ||
holidayFormat: 'MM-DD-YYYY' | ||
}); | ||
// moment-business-days will now stop considering these holidays as business days | ||
```` | ||
#### Run Tests: | ||
`npm test` | ||
### Methods: | ||
@@ -61,2 +83,14 @@ | ||
**prevBusinessDay()** | ||
Will retrieve the previous business date as moment date object: | ||
```javascript | ||
//Previous busines day of Monday 02-02-2015 | ||
moment('02-02-2015', 'DD-MM-YYYY').prevBusinessDay()._d // Fri Jan 30 2015 00:00:00 GMT-0600 (CST) | ||
//Previous busines day of Tuesday 03-02-2015 | ||
moment('03-02-2015', 'DD-MM-YYYY').prevBusinessDay()._d //Mon Feb 02 2015 00:00:00 GMT-0600 (CST) | ||
``` | ||
**monthBusinessDays()** | ||
@@ -63,0 +97,0 @@ |
14052
7
225
155
2