@magicbell/react-headless
Version:
Hooks to build a notification inbox
39 lines • 1.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.secondsToDate = secondsToDate;
exports.toDate = toDate;
exports.toUnix = toUnix;
const tslib_1 = require("tslib");
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
const localizedFormat_js_1 = tslib_1.__importDefault(require("dayjs/plugin/localizedFormat.js"));
const relativeTime_js_1 = tslib_1.__importDefault(require("dayjs/plugin/relativeTime.js"));
const updateLocale_js_1 = tslib_1.__importDefault(require("dayjs/plugin/updateLocale.js"));
dayjs_1.default.extend(localizedFormat_js_1.default);
dayjs_1.default.extend(relativeTime_js_1.default);
dayjs_1.default.extend(updateLocale_js_1.default);
/**
* Function to build a Date given a number of seconds.
*
* @example secondsToDate(1582263571)
*/
function secondsToDate(seconds) {
return seconds ? toDate(seconds * 1000) : null;
}
/**
* Function to build a Date given a string or number of milliseconds.
*
* @example toDate('2020-02-01')
*/
function toDate(date) {
return (0, dayjs_1.default)(date);
}
/**
* Function to return a UNIX timestamp from a date representation. This value is
* floored to the nearest second.
*
* @example toUnix('2020-10-06')
*/
function toUnix(date) {
return (0, dayjs_1.default)(date).unix();
}
//# sourceMappingURL=date.js.map