-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (29 loc) · 954 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import instance from '../utils/instance'
import rangeCount from '../rangeCount/index'
/**
* @name distanceCount
* @summary Get weekday count from original date
*
* @description
* Get weekday count from original date
*
* @param {Number} offset - the end date
* @param {Date} origin - the original date
* @returns {Number} the count
*
* @example
* // For the weekday date:
* var result = distanceCount(10, new Date(2018, 5, 20))
* //=> 8
*/
export default function distanceCount (offset, origin = new Date()) {
if (arguments.length > 2) {
throw new TypeError('2 argument required, but only ' + arguments.length + ' present')
}
if (!(typeof offset === 'number' && origin instanceof Date)) {
throw new TypeError(`(Number, Date) required, but got (${instance(offset)}, ${instance(origin)})`)
}
const endDate = new Date(origin.getTime())
endDate.setDate(origin.getDate() + offset)
return rangeCount(origin, endDate)
}