moment-business-days
Advanced tools
Comparing version 1.1.2 to 1.1.3
13
index.js
@@ -74,11 +74,18 @@ 'use strict'; | ||
moment.fn.businessAdd = function (number, period) { | ||
var day = this.clone(); | ||
var day = this.clone().startOf('day'); | ||
if (!day.isValid()) { | ||
return day; | ||
} | ||
if (number < 0) { | ||
number = Math.round(-1 * number) * -1; | ||
} else { | ||
number = Math.round(number); | ||
} | ||
var signal = number < 0 ? -1 : 1; | ||
var remaining = Math.abs(number); | ||
period = typeof period !== 'undefined' ? period : 'days'; | ||
while (remaining) { | ||
var remaining = Math.abs(number); | ||
while (remaining > 0) { | ||
day.add(signal, period); | ||
@@ -85,0 +92,0 @@ |
{ | ||
"name": "moment-business-days", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "MomentJS plugin to use business days", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -154,3 +154,3 @@ 'use strict'; | ||
describe('On Tuesday, November 3rd 2015', function () { | ||
it('adds business days only, excluding weekends, even over 2 weeks ', function (done) { | ||
it('adds business days only, excluding weekends, even over 2 weeks', function (done) { | ||
var newBusinessDay = moment('11-03-2015', 'MM-DD-YYYY').businessAdd(5); | ||
@@ -160,3 +160,3 @@ expect(newBusinessDay.format('D')).to.eql('10'); | ||
}); | ||
it('adds business days only, excluding weekends ', function (done) { | ||
it('adds business days only, excluding weekends', function (done) { | ||
var newBusinessDay = moment('11-03-2015', 'MM-DD-YYYY').businessAdd(10); | ||
@@ -166,3 +166,23 @@ expect(newBusinessDay.format('D')).to.eql('17'); | ||
}); | ||
it('adds business hours only, excluding weekends ', function (done) { | ||
it('adds business days only, excluding weekends, rounding down fractional day values', function (done) { | ||
var newBusinessDay = moment('11-03-2015 12:42:00', 'MM-DD-YYYY hh-mm-ss').businessAdd(10.4); | ||
expect(newBusinessDay.format('D')).to.eql('17'); | ||
done(); | ||
}); | ||
it('adds business days only, excluding weekends, rounding up fractional day values', function (done) { | ||
var newBusinessDay = moment('11-03-2015 12:42:00', 'MM-DD-YYYY hh-mm-ss').businessAdd(10.5); | ||
expect(newBusinessDay.format('D')).to.eql('18'); | ||
done(); | ||
}); | ||
it('subtracts business days when negative values are added, excluding weekends, rounding down fractional day values', function (done) { | ||
var newBusinessDay = moment('11-03-2015 12:42:00', 'MM-DD-YYYY hh-mm-ss').businessAdd(-10.4); | ||
expect(newBusinessDay.format('D')).to.eql('20'); | ||
done(); | ||
}); | ||
it('subtracts business days when negative values are added, excluding weekends, rounding up fractional day values', function (done) { | ||
var newBusinessDay = moment('11-03-2015 12:42:00', 'MM-DD-YYYY hh-mm-ss').businessAdd(-10.5); | ||
expect(newBusinessDay.format('D')).to.eql('19'); | ||
done(); | ||
}); | ||
it('adds business hours only, excluding weekends', function (done) { | ||
var newBusinessDay = moment('11-06-2015', 'MM-DD-YYYY').businessAdd( | ||
@@ -169,0 +189,0 @@ 36, |
24867
516