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