let convertTime=(e,t)=>{let a=timeOffset(e);return{week:a.weeks,day:t.enableWeek?a.days:a.totalDays,hour:t.enableDay?a.hours:a.totalHours,minute:t.enableHour||t.enableDay||t.enableWeek?a.minutes:a.totalMinutes,second:t.enableMinute||t.enableHour||t.enableDay||t.enableWeek?a.seconds:a.totalSeconds}},timeOffset=e=>({seconds:e%60,minutes:Math.floor(e/60)%60,hours:Math.floor(e/60/60)%24,days:Math.floor(e/60/60/24)%7,weeks:Math.floor(e/60/60/24/7),months:Math.floor(e/60/60/24/30.4368),totalDays:Math.floor(e/60/60/24),totalHours:Math.floor(e/60/60),totalMinutes:Math.floor(e/60),totalSeconds:e}),formatTime=e=>Number.isNaN(e)||0===e?"00":e<10?`0${e}`:e,calculateTime=e=>{let t=new Date().getTime();e||(e=getEndTime(0,3,0));let a=Math.ceil((e-t)/1e3);return a>0?a:0},getEndTime=(e,t,a)=>{let n=new Date,r=new Date;return n.setDate(r.getDate()+e),n.setHours(r.getHours()+t),n.setMinutes(r.getMinutes()+a),n.setSeconds(r.getSeconds()),n.getTime()},daily=(e,t,a)=>{let n=new Date,r=to24HrTime(`${e}:${t} ${a}`);e=r.hours,t=r.mins;let s=new Date(n.getFullYear(),n.getMonth(),n.getDate(),e,t).getTime(),l=s-n.getTime();return l<0&&(l+=864e5),Math.ceil(l/1e3)},standard=(e,t,a)=>calculateTime(getStandardEndtime(e,t,a)),parseTimezoneOffset=e=>{let t=e?.match(/([+-]\d{2}):(\d{2})$/);if(t?.[1]&&t?.[2]){let e=parseInt(t[1]),a=parseInt(t[2]),n=60*e+(e>=0?a:-a);return-n}let a=e?.match(/GMT([+-])(\d{2})(\d{2})/);if(a?.[1]&&a?.[2]&&a?.[3]){let e="+"===a[1]?-1:1,t=parseInt(a[2])*e,n=parseInt(a[3])*e;return 60*t+n}return null},handleDateUTCFormat=(e,t)=>{let a=new Date().getTimezoneOffset();return(e=new Date(e.getTime()-6e4*a-36e5*t)).getTime()},handleDateGMTFormat=({endTime:e,timezoneNumber:t,standardType:a})=>{let n=new Date(e);if("specific-time-zone"===a){let a="string"==typeof e?parseTimezoneOffset(e):null,r=-(60*t);return a?n.getTime()-(a-r)*6e4:n.getTime()}let r=new Date().getTimezoneOffset(),s="string"==typeof e?parseTimezoneOffset(e):null;return s?n.getTime()+(r-s)*6e4:n.getTime()},getStandardEndtime=(e,t,a)=>{if(!e)return 0;let n=new Date(e),r=0;r=t&&parseInt(t)?parseInt(t):parseInt(t.slice(3));let s="number"==typeof e||"string"==typeof e&&e.includes("Z");return s?handleDateUTCFormat(n,r):handleDateGMTFormat({endTime:e,timezoneNumber:r,standardType:a})},evergreen=e=>{let{days:t,hours:a,mins:n,seconds:r=0}=e;return(t??0)*86400+(a??0)*3600+(n??0)*60+(r??0)},refreshAfterFinish=(e,t)=>{let a=new Date().getTime(),n=(86400*t.days+3600*t.hours+60*t.mins)*1e3,r=(a-e)%n;return Math.ceil((n-r)/1e3)},to24HrTime=e=>{let[t,a,n]=e.toLowerCase().match(/\d+|[a-z]+/g)||[],r=`${Number(t)%12+("am"==n?0:12)}:${a}`.split(":");return{hours:parseInt(r[0]?r[0]:"0"),mins:parseInt(r[1]?r[1]:"0")}};export{calculateTime,convertTime,daily,evergreen,formatTime,getEndTime,getStandardEndtime,refreshAfterFinish,standard};
