moment-business-time
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -46,11 +46,17 @@ var moment = require('moment'), | ||
while (n > 0) { | ||
var then = d.clone().add(n, unit); | ||
var jump = openingTimes(d)[1].diff(d, unit); | ||
if (jump > n) { | ||
jump = n; | ||
} | ||
if (jump < 1) { | ||
jump = 1; | ||
} | ||
var then = d.clone().add(jump, unit); | ||
n -= jump; | ||
if (then.isWorkingTime()) { | ||
d = d.add(n, unit); | ||
n = 0; | ||
d = d.add(jump, unit); | ||
} else { | ||
var next = then.nextWorkingTime(); | ||
var diff = then.diff(openingTimes(d)[1], unit, true); | ||
d = next; | ||
n = diff; | ||
d = next.add(diff,unit); | ||
} | ||
@@ -68,11 +74,17 @@ } | ||
while (n > 0) { | ||
var then = d.clone().subtract(n, unit); | ||
var jump = -1 * openingTimes(d)[0].diff(d, unit); | ||
if (jump > n) { | ||
jump = n; | ||
} | ||
if (jump < 1) { | ||
jump = 1; | ||
} | ||
var then = d.clone().subtract(jump, unit); | ||
n -= jump; | ||
if (then.isWorkingTime()) { | ||
d = d.subtract(n, unit); | ||
n = 0; | ||
d = d.subtract(jump, unit); | ||
} else { | ||
var next = then.lastWorkingTime(); | ||
var diff = then.diff(openingTimes(d)[0], unit, true); | ||
d = next; | ||
n = -diff; | ||
d = next.add(diff,unit); | ||
} | ||
@@ -79,0 +91,0 @@ } |
{ | ||
"name": "moment-business-time", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "Query and manipulate moment objects within the context of business/working hours", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -82,2 +82,3 @@ var moment = require('../lib/business-hours'); | ||
moment(now).addWorkingTime(10, 'days').format(date).should.equal('2015-03-12'); | ||
moment(now).addWorkingTime(100, 'days').format(date).should.equal('2015-07-16'); | ||
}); | ||
@@ -115,4 +116,11 @@ | ||
moment(now).addWorkingTime(19, 'hours').format(full).should.equal('2015-03-02 13:12:34.000'); | ||
// https://github.com/lennym/moment-business-time/issues/3#issuecomment-199341232 | ||
moment('2016-03-21T15:30:00').addWorkingTime(17, 'hour').format(full).should.equal('2016-03-23 16:30:00.000'); | ||
moment('2016-03-21T15:30:00').addWorkingTime(18, 'hour').format(full).should.equal('2016-03-24 09:30:00.000'); | ||
}); | ||
it('handles running over multiple weeks', function () { | ||
moment(now).addWorkingTime(108, 'hours').format(full).should.equal('2015-03-17 14:12:34.000'); | ||
}); | ||
}); | ||
@@ -236,2 +244,6 @@ | ||
it('handles running over multiple weeks', function () { | ||
moment(now).subtractWorkingTime(108, 'hours').format(full).should.equal('2015-02-09 12:12:34.000'); | ||
}); | ||
}); | ||
@@ -238,0 +250,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35231
612