forked from date-fns/date-fns
/
index.js
29 lines (27 loc) · 1.04 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
28
29
import getTime from '../getTime/index.js'
/**
* @name getUnixTime
* @category Timestamp Helpers
* @summary Get the seconds timestamp of the given date.
*
* @description
* Get the seconds timestamp of the given date.
*
* @param {Date|String|Number} date - the given date
* @param {Options} [options] - the object with options. See [Options]{@link https://date-fns.org/docs/Options}
* @param {0|1|2} [options.additionalDigits=2] - passed to `toDate`. See [toDate]{@link https://date-fns.org/docs/toDate}
* @returns {Number} the timestamp
* @throws {TypeError} 1 argument required
* @throws {RangeError} `options.additionalDigits` must be 0, 1 or 2
*
* @example
* // Get the timestamp of 29 February 2012 11:45:05:
* var result = getTime(new Date(2012, 1, 29, 11, 45, 5))
* //=> 1330515905
*/
export default function getUnixTime (dirtyDate, dirtyOptions) {
if (arguments.length < 1) {
throw new TypeError('1 argument required, but only ' + arguments.length + ' present')
}
return Math.floor(getTime(dirtyDate, dirtyOptions) / 1000)
}