1
0
Fork 0
mirror of synced 2024-09-08 21:51:58 +12:00
budibase/packages/common/node_modules/date-fns/difference_in_seconds/index.js
2020-04-15 15:23:29 +01:00

28 lines
899 B
JavaScript

var differenceInMilliseconds = require('../difference_in_milliseconds/index.js')
/**
* @category Second Helpers
* @summary Get the number of seconds between the given dates.
*
* @description
* Get the number of seconds between the given dates.
*
* @param {Date|String|Number} dateLeft - the later date
* @param {Date|String|Number} dateRight - the earlier date
* @returns {Number} the number of seconds
*
* @example
* // How many seconds are between
* // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000?
* var result = differenceInSeconds(
* new Date(2014, 6, 2, 12, 30, 20, 0),
* new Date(2014, 6, 2, 12, 30, 7, 999)
* )
* //=> 12
*/
function differenceInSeconds (dirtyDateLeft, dirtyDateRight) {
var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / 1000
return diff > 0 ? Math.floor(diff) : Math.ceil(diff)
}
module.exports = differenceInSeconds