UNPKG

1.04 kBJavaScriptView Raw
1"use strict";
2exports.addMilliseconds = addMilliseconds;
3var _index = require("./toDate.js");
4var _index2 = require("./constructFrom.js");
5
6/**
7 * @name addMilliseconds
8 * @category Millisecond Helpers
9 * @summary Add the specified number of milliseconds to the given date.
10 *
11 * @description
12 * Add the specified number of milliseconds to the given date.
13 *
14 * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
15 *
16 * @param date - The date to be changed
17 * @param amount - The amount of milliseconds to be added.
18 *
19 * @returns The new date with the milliseconds added
20 *
21 * @example
22 * // Add 750 milliseconds to 10 July 2014 12:45:30.000:
23 * const result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
24 * //=> Thu Jul 10 2014 12:45:30.750
25 */
26function addMilliseconds(date, amount) {
27 const timestamp = +(0, _index.toDate)(date);
28 return (0, _index2.constructFrom)(date, timestamp + amount);
29}