UNPKG

node-red-contrib-home-assistant-websocket

Version:
2 lines (1 loc) 1.63 kB
"use strict";var s=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var W=(t,e)=>{for(var n in e)s(t,n,{get:e[n],enumerable:!0})},O=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of $(e))!b.call(t,i)&&i!==n&&s(t,i,{get:()=>e[i],enumerable:!(r=M(e,i))||r.enumerable});return t};var S=t=>O(s({},"__esModule",{value:!0}),t);var F={};W(F,{alignDateToMidnight:()=>I,isTriggerTimeInPast:()=>C,isWithDate:()=>u,isWithDateTime:()=>D,parseCalendarDate:()=>w,shortenString:()=>y,toLocalISOWithOffset:()=>x});module.exports=S(F);function u(t){return t.date!==void 0}function D(t){return t.dateTime!==void 0}function w(t){if(u(t)){const[e,n,r]=t.date.split("-").map(Number);return new Date(e,n-1,r,0,0,0,0)}else if(D(t))return new Date(t.dateTime);throw new Error("Invalid Calendar DateOrDateTime")}function x(t,e=!1){const n=(d,p=2)=>String(d).padStart(p,"0"),r=t.getFullYear(),i=n(t.getMonth()+1),c=n(t.getDate()),f=n(t.getHours()),g=n(t.getMinutes()),m=n(t.getSeconds());let o=`${r}-${i}-${c}T${f}:${g}:${m}`;e&&(o+=`.${n(t.getMilliseconds(),3)}`);const a=t.getTimezoneOffset(),h=a<=0?"+":"-",l=n(Math.floor(Math.abs(a)/60)),T=n(Math.abs(a)%60);return o+=`${h}${l}:${T}`,o}function y(t,e){return t.length<=e?t:t.slice(0,e-3)+"..."}function I(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate(),0,0,0,0)}function C(t,e){const n=Math.floor(t.getTime()/1e3),r=Math.floor(e/1e3);return n<r}0&&(module.exports={alignDateToMidnight,isTriggerTimeInPast,isWithDate,isWithDateTime,parseCalendarDate,shortenString,toLocalISOWithOffset});