-
Notifications
You must be signed in to change notification settings - Fork 0
/
p-6c02d679.js
5 lines (5 loc) · 5.49 KB
/
p-6c02d679.js
1
2
3
4
5
/*!
* Built by BASIS
* Copyright BASIS International Ltd.
*/
import{j as t}from"./p-2b4379f2.js";class e{static fromNumber(t){let e=null;if(Number.isFinite(t)&&t>=0){e=new Date(0,0,0);try{let n=Math.floor(t),r=Math.floor(t%1*60),a=Math.floor(t%1*60%1*60),s=Math.round(t%1*60%1*60%1*1e3);s>=1e3&&(s=0,++a,a>=60&&(a=0,++r,r>=60&&(r=0,++n)));let l=e.getTime();l=l-l%1e3+s,e.setTime(l),e.setHours(12===n?t<12?0:12:n),e.setMinutes(r),e.setSeconds(a)}catch(t){throw new Error("Invalid time value")}}return e}static fromDate(t){let n=-1;return null!==t&&(n=e.tim(t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds())),n}static parse(t,n=e.CURRENT_LOCALE){if(null===t)return null;let r=String(t).trim();if(0===r.length)return null;const a=e.ampms(n);let s=null;r.toUpperCase().startsWith("AM")&&(s=!1,r=r.substring(2)),r.toUpperCase().startsWith("PM")&&(s=!0,r=r.substring(2)),r.startsWith(a[0])&&(s=!1,r=r.substring(a[0].length)),r.startsWith(a[1])&&(s=!0,r=r.substring(a[1].length)),r.toUpperCase().endsWith("AM")&&(s=!1,r=r.substring(0,r.length-2)),r.toUpperCase().endsWith("PM")&&(s=!0,r=r.substring(0,r.length-2)),r.endsWith(a[0])&&(s=!1,r=r.substring(0,r.length-a[0].length)),r.endsWith(a[1])&&(s=!0,r=r.substring(0,r.length-a[1].length));const l=r.trim().split("");if(0===l.length)return null;let p=0,i=0,u=0,I=0,o=!0;for(let t=0;t<l.length&&o;++t)o=/^\d$/.test(l[t]);if(o)switch(l.length){case 0:break;case 1:p=parseInt(l[0],10);break;case 2:p=10*parseInt(l[0],10)+parseInt(l[1],10);break;case 3:p=parseInt(l[0],10),i=10*parseInt(l[1],10)+parseInt(l[2],10);break;case 4:p=10*parseInt(l[0],10)+parseInt(l[1],10),i=10*parseInt(l[2],10)+parseInt(l[3],10);break;case 5:p=parseInt(l[0],10),i=10*parseInt(l[1],10)+parseInt(l[2],10),u=10*parseInt(l[3],10)+parseInt(l[4],10);break;case 6:p=10*parseInt(l[0],10)+parseInt(l[1],10),i=10*parseInt(l[2],10)+parseInt(l[3],10),u=10*parseInt(l[4],10)+parseInt(l[5],10);break;case 7:p=10*parseInt(l[0],10)+parseInt(l[1],10),i=10*parseInt(l[2],10)+parseInt(l[3],10),u=10*parseInt(l[4],10)+parseInt(l[5],10),I=100*parseInt(l[6],10);break;case 8:p=10*parseInt(l[0],10)+parseInt(l[1],10),i=10*parseInt(l[2],10)+parseInt(l[3],10),u=10*parseInt(l[4],10)+parseInt(l[5],10),I=100*parseInt(l[6],10)+10*parseInt(l[7],10);break;case 9:p=10*parseInt(l[0],10)+parseInt(l[1],10),i=10*parseInt(l[2],10)+parseInt(l[3],10),u=10*parseInt(l[4],10)+parseInt(l[5],10),I=100*parseInt(l[6],10)+10*parseInt(l[7],10)+parseInt(l[8],10);break;default:return null}else{let t=1,e=0,n=!1;for(let r=0;r<=l.length;++r)if(r<l.length&&/^\d$/.test(l[r]))e=10*e+parseInt(l[r],10),n=!0;else{if(r<l.length&&/^[a-z]$/i.test(l[r]))return null;if(n)if(1===t)p=e;else if(2===t)i=e;else if(3===t)u=e;else{if(4!==t)return null;I=e}++t,e=0,n=!1}}null!==s&&(s&&p<12&&(p+=12),s||12!==p||(p-=12));try{return e.tim(p,i,u,I)}catch(t){return null}}static format(t,n=e.DEFAULT_TIME_MASK,r=e.CURRENT_LOCALE){const a=t instanceof Date?t:e.fromNumber(t);if(null===a)return"";const s=e.ampms(r),l=e.buildMaskTranslation({minutes:a.getMinutes(),seconds:a.getSeconds(),milliseconds:a.getMilliseconds(),get hours24(){return a.getHours()},get hours12(){return this.hours24%12||12},AM:s[0],PM:s[1]});let p=n;for(const t in l)p=p.replace(new RegExp("(%"+t+")","g"),l[t]);return p}static ampms(n){var r,a;const s=new Date(2e3,0,1,10,0,0),l=new Date(2e3,0,1,14,0,0),p=(null==n?void 0:n.trim().length)>0?n:e.CURRENT_LOCALE,i=new Intl.DateTimeFormat(t(p),{hour:"numeric",hour12:!0}),u=i.formatToParts(s),I=i.formatToParts(l);return[(null===(r=u.find((t=>"dayPeriod"===t.type)))||void 0===r?void 0:r.value)||"",(null===(a=I.find((t=>"dayPeriod"===t.type)))||void 0===a?void 0:a.value)||""]}static generateIntervals(t=60,n=e.DEFAULT_TIME_MASK,r=e.CURRENT_LOCALE,a=null,s=null){let l=Math.abs(t);l<60&&(console.warn(`Step ${l} is smaller than the recommended minimum of 60. Using the recommended minimum step.`),l=60);let p=null,i=null;null!=a&&a>-1&&(p=e.fromNumber(a<0?0:a)),null!=s&&s>-1&&(i=e.fromNumber(s<0||s>24?23:s)),p&&i&&p.getTime()>i.getTime()&&([p,i]=[i,p]);const u=Math.floor(86400/l),I=[];for(let t=0;t<=u;t++){const a=t*l,s=Math.floor(a/3600),u=Math.floor(a%3600/60),o=new Date(0,0,0,s,u);(null===p||o.getTime()>=p.getTime())&&(null===i||o.getTime()<=i.getTime())&&I.push(e.format(o,n,r))}const o=null!==p?e.format(p,n,r):null,c=null!==i?e.format(i,n,r):null;return null===o||I.includes(o)||I.unshift(o),null===c||I.includes(c)||I.push(c),[...new Set(I)]}static tim(t,e,n,r){let a=0;return a+=t,a+=e/60,a+=n/3600,a+=r/36e5,a}static buildMaskTranslation(t){return{Hz:1==String(t.hours24).length?"0"+t.hours24:t.hours24,Hs:t.hours24,Hl:t.hours24,Hp:String.fromCharCode(t.hours24),Hd:t.hours24,H:t.hours24,hz:1==String(t.hours12).length?"0"+t.hours12:t.hours12,hs:t.hours12,hl:t.hours12,hp:String.fromCharCode(t.hours12),hd:t.hours12,h:t.hours12,mz:1==String(t.minutes).length?"0"+t.minutes:t.minutes,ms:t.minutes,ml:t.minutes,mp:String.fromCharCode(t.minutes),md:t.minutes,m:t.minutes,sz:1==String(t.seconds).length?"0"+t.seconds:t.seconds,ss:t.seconds,sl:t.seconds,sp:String.fromCharCode(t.seconds),sd:t.seconds,s:t.seconds,tz:1==String(t.milliseconds).length?"00"+t.milliseconds:2==String(t.milliseconds).length?"0"+t.milliseconds:t.milliseconds,ts:t.milliseconds,tl:t.milliseconds,tp:String.fromCharCode(t.milliseconds),td:t.milliseconds,t:t.milliseconds,aP:t.hours24>=12?t.PM:t.AM,a:t.hours24>=12?t.PM:t.AM,PP:t.hours24>=12?"PM":"AM",P:t.hours24>=12?"PM":"AM",pp:t.hours24>=12?"pm":"am",p:t.hours24>=12?"pm":"am"}}}e.DEFAULT_TIME_MASK="%h:%mz %a",e.CURRENT_LOCALE=Intl.DateTimeFormat().resolvedOptions().locale;export{e as D}