UNPKG

@hakit/core

Version:

A collection of React hooks and helpers for Home Assistant to easily communicate with the Home Assistant WebSocket API.

3 lines (2 loc) 1.64 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=864e5,D=36e5,d=6e4,I=1e3,m={ms:1,s:I,min:d,h:D,d:l},T=(t,e)=>u(parseFloat(t)*m[e])||"0",n=(t,e=2)=>{let r=""+t;for(let o=1;o<e;o++)r=parseInt(r)<10**o?`0${r}`:r;return r};function u(t){const e=Math.floor(t/1e3/3600),r=Math.floor(t/1e3%3600/60),o=Math.floor(t/1e3%3600%60),a=Math.floor(t%1e3);return e>0?`${e}:${n(r)}:${n(o)}`:r>0?`${r}:${n(o)}`:o>0||a>0?`${o}${a>0?`.${n(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)?)?)$/,h=t=>N.test(t),f="^\\d{4}-(0[1-9]|1[0-2])-([12]\\d|0[1-9]|3[01])",S=new RegExp(f+"$"),g=new RegExp(f),_=(t,e=!1)=>e?g.test(t):S.test(t);function E(t){return t?t instanceof Date&&!isNaN(t.valueOf()):!1}const s={},i={},c={},C=t=>(s[t]||(s[t]=new Intl.DateTimeFormat("en-US",{year:"numeric",month:"long",day:"numeric",timeZone:t})),s[t]),O=t=>(i[t]||(i[t]=new Intl.DateTimeFormat("en-US",{hour:"numeric",minute:"2-digit",hourCycle:"h12",timeZone:t})),i[t]),L=t=>(c[t]||(c[t]=new Intl.DateTimeFormat("en-US",{year:"numeric",month:"long",day:"numeric",hour:"numeric",minute:"2-digit",hourCycle:"h12",timeZone:t})),c[t]),M=(t,e)=>C(e.time_zone).format(t),p=(t,e)=>O(e.time_zone).format(t),$=(t,e)=>L(e.time_zone).format(t);exports.UNIT_TO_MILLISECOND_CONVERT=m;exports.checkValidDate=E;exports.formatDate=M;exports.formatDateTime=$;exports.formatDuration=T;exports.formatTime=p;exports.isDate=_;exports.isTimestamp=h;exports.millisecondsToDuration=u; //# sourceMappingURL=date.js.map