@toreda/time
Version:
Simple, small footprint library for common time operations and converting between units of time.
20 lines (19 loc) • 704 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.unixTimestampNow = unixTimestampNow;
const constants_1 = require("../../time/constants");
/**
* Get the current time as a unix timestamp in integer seconds.
* Does not create a Time object.
*
* @param offset Optional seconds to add or subtract. Non-finite values
* (NaN, Infinity) are ignored. No effect when omitted or null.
* @returns Seconds since Unix Epoch.
*/
function unixTimestampNow(offset) {
const now = Math.floor(Date.now() / constants_1.TimeConstants.SECONDS_TO_MILLISECONDS);
if (typeof offset !== 'number' || !isFinite(offset)) {
return now;
}
return now + offset;
}