import n from"dayjs";import y from"dayjs/plugin/advancedFormat";import D from"dayjs/plugin/customParseFormat";import k from"dayjs/plugin/localeData";import Y from"dayjs/plugin/quarterOfYear";import W from"dayjs/plugin/weekOfYear";import b from"dayjs/plugin/weekYear";import x from"dayjs/plugin/weekday";import{noteOnce as _}from"../../vc-util/warning.mjs";n.extend(D);n.extend(y);n.extend(x);n.extend(k);n.extend(W);n.extend(b);n.extend(Y);n.extend((e,t)=>{const r=t.prototype,a=r.format;r.format=function(s){const o=(s||"").replace("Wo","wo");return a.bind(this)(o)}});const S={bn_BD:"bn-bd",by_BY:"be",en_GB:"en-gb",en_US:"en",fr_BE:"fr",fr_CA:"fr-ca",hy_AM:"hy-am",kmr_IQ:"ku",nl_BE:"nl-be",pt_BR:"pt-br",zh_CN:"zh-cn",zh_HK:"zh-hk",zh_TW:"zh-tw"},c=e=>S[e]||e.split("_")[0],h=()=>{_(!1,"Not match any format. Please help to fire a issue about this.")},M=/\[([^\]]+)\]|Q|wo|ww|w|WW|W|zzz|[zS]|gggg|GGGG|k{1,2}/g;function u(e,t,r){const a=[...new Set(e.split(r))];let i=0;for(let s=0;s<a.length;s++){const o=a[s];if(i+=o.length,i>t)return o;i+=r.length}}const g=(e,t)=>{if(!e)return null;if(n.isDayjs(e))return e;const r=t.matchAll(M);let a=n(e,t);if(r===null)return a;for(const i of r){const s=i[0],o=i.index;if(s==="Q"){const l=e.slice(o-1,o),f=u(e,o,l).match(/\d+/)[0];a=a.quarter(Number.parseInt(f))}if(s.toLowerCase()==="wo"){const l=e.slice(o-1,o),f=u(e,o,l).match(/\d+/)[0];a=a.week(Number.parseInt(f))}s.toLowerCase()==="ww"&&(a=a.week(Number.parseInt(e.slice(o,o+s.length)))),s.toLowerCase()==="w"&&(a=a.week(Number.parseInt(e.slice(o,o+s.length+1))))}return a},G={getNow:()=>n(),getFixedDate:e=>n(e,["YYYY-M-DD","YYYY-MM-DD"]),getEndDate:e=>e.endOf("month"),getWeekDay:e=>{const t=e.locale("en");return t.weekday()+t.localeData().firstDayOfWeek()},getYear:e=>e.year(),getMonth:e=>e.month(),getDate:e=>e.date(),getHour:e=>e.hour(),getMinute:e=>e.minute(),getSecond:e=>e.second(),addYear:(e,t)=>e.add(t,"year"),addMonth:(e,t)=>e.add(t,"month"),addDate:(e,t)=>e.add(t,"day"),setYear:(e,t)=>e.year(t),setMonth:(e,t)=>e.month(t),setDate:(e,t)=>e.date(t),setHour:(e,t)=>e.hour(t),setMinute:(e,t)=>e.minute(t),setSecond:(e,t)=>e.second(t),isAfter:(e,t)=>e.isAfter(t),isValidate:e=>e.isValid(),locale:{getWeekFirstDay:e=>n().locale(c(e)).localeData().firstDayOfWeek(),getWeekFirstDate:(e,t)=>t.locale(c(e)).weekday(0),getWeek:(e,t)=>t.locale(c(e)).week(),getShortWeekDays:e=>n().locale(c(e)).localeData().weekdaysMin(),getShortMonths:e=>n().locale(c(e)).localeData().monthsShort(),format:(e,t,r)=>t.locale(c(e)).format(r),parse:(e,t,r)=>{const a=c(e);for(let i=0;i<r.length;i+=1){const s=r[i],o=t;if(s.includes("wo")||s.includes("Wo")){const f=o.split("-")[0],p=o.split("-")[1],w=n(f,"YYYY").startOf("year").locale(a);for(let d=0;d<=52;d+=1){const m=w.add(d,"week");if(m.format("Wo")===p)return m}return h(),null}const l=n(o,s,!0).locale(a);if(l.isValid())return l}return t||h(),null}},toDate:(e,t)=>Array.isArray(e)?e.map(r=>g(r,t)):g(e,t),toString:(e,t)=>Array.isArray(e)?e.map(r=>n.isDayjs(r)?r.format(t):r):n.isDayjs(e)?e.format(t):e};export{G as default};
