@hakit/core
Version:
A collection of React hooks and helpers for Home Assistant to easily communicate with the Home Assistant WebSocket API.
52 lines (51 loc) • 1.85 kB
JavaScript
const I = {
ms: 1,
s: 1e3,
min: 6e4,
h: 36e5,
d: 864e5
}, d = (t, e) => u(parseFloat(t) * I[e]) || "0", o = (t, e = 2) => {
let r = "" + t;
for (let n = 1; n < e; n++)
r = parseInt(r) < 10 ** n ? `0${r}` : r;
return r;
};
function u(t) {
const e = Math.floor(t / 1e3 / 3600), r = Math.floor(t / 1e3 % 3600 / 60), n = Math.floor(t / 1e3 % 3600 % 60), a = Math.floor(t % 1e3);
return e > 0 ? `${e}:${o(r)}:${o(n)}` : r > 0 ? `${r}:${o(n)}` : n > 0 || a > 0 ? `${n}${a > 0 ? `.${o(a, 3)}` : ""}` : null;
}
const N = /^\d{4}-(0[1-9]|1[0-2])-([12]\d|0[1-9]|3[01])[T| ](((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)(\8[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)$/, E = (t) => N.test(t), m = "^\\d{4}-(0[1-9]|1[0-2])-([12]\\d|0[1-9]|3[01])", f = new RegExp(m + "$"), D = new RegExp(m), h = (t, e = !1) => e ? D.test(t) : f.test(t);
function L(t) {
return t ? t instanceof Date && !isNaN(t.valueOf()) : !1;
}
const s = {}, c = {}, i = {}, S = (t) => (s[t] || (s[t] = new Intl.DateTimeFormat("en-US", {
year: "numeric",
month: "long",
day: "numeric",
timeZone: t
})), s[t]), l = (t) => (c[t] || (c[t] = new Intl.DateTimeFormat("en-US", {
hour: "numeric",
minute: "2-digit",
hourCycle: "h12",
timeZone: t
})), c[t]), _ = (t) => (i[t] || (i[t] = new Intl.DateTimeFormat("en-US", {
year: "numeric",
month: "long",
day: "numeric",
hour: "numeric",
minute: "2-digit",
hourCycle: "h12",
timeZone: t
})), i[t]), C = (t, e) => S(e.time_zone).format(t), O = (t, e) => l(e.time_zone).format(t), T = (t, e) => _(e.time_zone).format(t);
export {
I as UNIT_TO_MILLISECOND_CONVERT,
L as checkValidDate,
C as formatDate,
T as formatDateTime,
d as formatDuration,
O as formatTime,
h as isDate,
E as isTimestamp,
u as millisecondsToDuration
};
//# sourceMappingURL=date.js.map