/
index.js
27 lines (26 loc) · 1.09 KB
/
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
import toDate from '../toDate/index.js'
/**
* @name addMilliseconds
* @category Millisecond Helpers
* @summary Add the specified number of milliseconds to the given date.
*
* @description
* Add the specified number of milliseconds to the given date.
*
* @param {Date|String|Number} date - the date to be changed
* @param {Number} amount - the amount of milliseconds to be added
* @param {Options} [options] - the object with options. See [Options]{@link docs/Options}
* @param {0|1|2} [options.additionalDigits=2] - passed to `toDate`. See [toDate]{@link docs/toDate}
* @returns {Date} the new date with the milliseconds added
* @throws {RangeError} `options.additionalDigits` must be 0, 1 or 2
*
* @example
* // Add 750 milliseconds to 10 July 2014 12:45:30.000:
* var result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
* //=> Thu Jul 10 2014 12:45:30.750
*/
export default function addMilliseconds (dirtyDate, dirtyAmount, dirtyOptions) {
var timestamp = toDate(dirtyDate, dirtyOptions).getTime()
var amount = Number(dirtyAmount)
return new Date(timestamp + amount)
}