@aotearoan/neon
Version:
Neon is a lightweight design library of Vue 3 components with minimal dependencies.
3 lines (2 loc) • 2.84 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class s{static formatDate(t){const{dayFormatted:o,monthShortName:n}=s.stringToNeonDate(t.toISOString());return`${n} ${o}`}static formatISOStringToDateAndTime(t,o=!1){const{dayFormatted:n,monthShortName:a,year:r,time:e,timeShort:g}=s.stringToNeonDate(t);return o?`${n} ${a} ${r}, ${e}`:`${n} ${a} ${r}, ${g}`}static stringToNeonDate(t,o,n=!1){const a=o||navigator.language,r=new Date,e=Intl.DateTimeFormat().resolvedOptions().timeZone,g=!(t.match(/(.*)Z/)||t.match(/(.*)[+-]\d{2}:\d{2}/)),i=new Date(!n&&t.length===10?`${t}T${r.toISOString().split("T")[1]}`:t+(g?"Z":""));let c;t.length>10&&(c=i.toLocaleString("en-GB",t.length<=16?{hour12:!1,hour:"2-digit",minute:"2-digit",timeZone:e}:{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit",timeZone:e}));const m={year:+i.toLocaleString("en-US",{year:"numeric",timeZone:e}),yearFormatted:i.toLocaleString(a,{year:"numeric",timeZone:e}),month:+i.toLocaleString("en-US",{month:"numeric",timeZone:e}),monthShortName:i.toLocaleString(a,{month:"short",timeZone:e}),monthLongName:i.toLocaleString(a,{month:"long",timeZone:e}),day:+i.toLocaleString("en-US",{day:"numeric",timeZone:e}),dayFormatted:i.toLocaleString(a,{day:"2-digit",timeZone:e})};return c&&(m.time=c,m.timeShort=i.toLocaleString("en-GB",{hour12:!1,hourCycle:"h23",hour:"2-digit",minute:"2-digit",timeZone:e})),m}static dateToIso(t,o=!1){const n=t.toISOString();return o?n:n.split("T")[0]}static dmyToIso(t,o,n){return`${n}-${o<10?"0"+o:o}-${t<10?"0"+t:t}`}static dowNames(t,o="short"){const n=t||navigator.language,a=new Date,r=[];for(;!r[a.getDay()];)r[a.getDay()]=a.toLocaleString(n,{weekday:o}),a.setDate(a.getDate()+1);const e=r.shift();return e&&r.push(e),r}static monthNames(t,o="short"){const n=t||navigator.language;return Array.from(Array(12).keys()).map(a=>new Date(2023,a,15).toLocaleString(n,{month:o}))}static toCalendarConfiguration(t,o,n,a,r){const e=r||navigator.language,g=s.stringToNeonDate(s.dateToIso(new Date),e),i=t?s.stringToNeonDate(t,e,!0):void 0,c=o||g.month,m=o&&n?new Date(n,o-1,15):null,L=(m==null?void 0:m.toLocaleString(e,{month:"long"}))||g.monthLongName,S=n||g.year,T=a||Math.floor(S/10)*10,d=new Date(S,(c+11)%12,1),f=new Date(S,(c+11)%12,1);f.setDate(f.getDate()-1);const u=[];let D=1,w=!1;for(let l=0;l<6;l++){u[l]=[];for(let h=0;h<7;h++)if(l===0&&h<f.getDay())u[l][h]=null;else if(u[l][h]=d.getDate(),D=d.getDate(),d.setDate(d.getDate()+1),d.getDate()===1){for(let y=h+1;y<7;y++)u[l][y]=null;w=!0;break}if(w)break}return{today:g,selected:i,pageMonth:c,pageMonthName:L,pageYear:S,pageDecadeStart:T,dowNames:s.dowNames(e),dowLongNames:s.dowNames(e,"long"),dates:u,lastDayOfMonth:D,months:s.monthNames(e),monthLongNames:s.monthNames(e,"long")}}}exports.NeonDateUtils=s;
//# sourceMappingURL=NeonDateUtils.cjs.js.map