@sphereon/ui-components.core
Version:
SSI UI components Core
58 lines (57 loc) • 2.18 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
exports.__esModule = true;
exports.makeEpochMilli = exports.formatDate = exports.toLocalDateString = exports.toLocalDateTimeString = exports.DATE_FORMAT_OPTIONS = exports.EPOCH_MILLISECONDS = void 0;
var Localization_1 = __importDefault(require("../localization/Localization"));
exports.EPOCH_MILLISECONDS = 1000;
exports.DATE_FORMAT_OPTIONS = {
year: 'numeric',
month: 'numeric',
day: 'numeric'
};
var toLocalDateTimeString = function (date) {
return new Date((0, exports.formatDate)(date)).toLocaleString(Localization_1["default"].getLocale(), __assign(__assign({}, exports.DATE_FORMAT_OPTIONS), { hour: 'numeric', minute: 'numeric', second: 'numeric' }));
};
exports.toLocalDateTimeString = toLocalDateTimeString;
var toLocalDateString = function (date) {
return new Date((0, exports.formatDate)(date)).toLocaleDateString(Localization_1["default"].getLocale(), exports.DATE_FORMAT_OPTIONS);
};
exports.toLocalDateString = toLocalDateString;
var formatDate = function (date) {
var epoch = date;
epoch = removeFractionalPart(epoch);
if (!isEpochMilli(epoch)) {
epoch = (0, exports.makeEpochMilli)(epoch);
}
return epoch;
};
exports.formatDate = formatDate;
var makeEpochMilli = function (date) {
if (!isEpochMilli(date)) {
date = date * exports.EPOCH_MILLISECONDS;
}
return date;
};
exports.makeEpochMilli = makeEpochMilli;
var isEpochMilli = function (date) {
return date.toString().length > 10;
};
var removeFractionalPart = function (date) {
if (date.toString().indexOf('.') >= 0) {
return Number(date.toString().split('.')[0]);
}
return date;
};