moment-business-time
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -252,12 +252,18 @@ var moment = require('moment'), | ||
diff--; | ||
from = from.addWorkingTime(1, 'day'); | ||
} else { | ||
diff += from.diff(openingTimes(from)[1], unit, true); | ||
from = openingTimes(from.nextWorkingDay())[0]; | ||
} | ||
from = openingTimes(from.nextWorkingDay())[0]; | ||
} | ||
if (unit === 'day') { | ||
diff--; | ||
} else { | ||
if (unit !== 'day') { | ||
diff += from.diff(to, unit, true); | ||
} else if (detail) { | ||
console.warn('WARNING: passing `true` as a third argument to `workingDiff` may lead to ambiguous results'); | ||
console.warn('See https://github.com/lennym/moment-business-time/issues/12#issuecomment-199710566') | ||
var hours = from.diff(to, 'hour', true), | ||
denominator = comparator.isWorkingDay() ? comparator : comparator.nextWorkingDay(), | ||
total = openingTimes(denominator)[1].diff(openingTimes(denominator)[0], 'hour', true); | ||
diff += hours/total; | ||
} | ||
@@ -264,0 +270,0 @@ |
{ | ||
"name": "moment-business-time", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "Query and manipulate moment objects within the context of business/working hours", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -402,4 +402,13 @@ var moment = require('../lib/business-hours'); | ||
from.workingDiff(to, 'days').should.equal(-16); | ||
to.workingDiff(from, 'days').should.equal(16); | ||
from.workingDiff(to, 'days').should.equal(-15); | ||
to.workingDiff(from, 'days').should.equal(15); | ||
moment('2015-02-27T15:00:00').workingDiff(moment('2015-02-27T10:00:00'), 'day').should.equal(0); | ||
moment('2015-02-27T15:00:00').workingDiff(moment('2015-02-27T10:00:00'), 'day', true).should.equal(0.625); | ||
moment('2015-02-27T15:00:00').workingDiff(moment('2015-02-26T10:00:00'), 'day').should.equal(1) | ||
moment('2015-02-27T15:00:00').workingDiff(moment('2015-02-26T10:00:00'), 'day', true).should.equal(1.625); | ||
moment('2015-02-27T15:00:00').workingDiff(moment('2015-02-21T10:00:00'), 'day', true).should.equal(4.75); | ||
moment('2015-02-21T10:00:00').workingDiff(moment('2015-02-27T15:00:00'), 'day', true).should.equal(-4.75); | ||
}); | ||
@@ -406,0 +415,0 @@ |
36473
624