@sbh321/qcalendar
Version:
A forked version of Jeff Galbraith's fork of Quasar UI QCalendar
6 lines • 16.2 kB
JavaScript
/*!
* @subhambhandari/qcalendar v4.0.0-beta.19
* (c) 2024 Subham Bhandari <bhandarimaiya65@gmail.com>
* Released under the MIT License.
*/
const version="4.0.0-beta.19",PARSE_REGEX=/^(\d{4})-(\d{1,2})(-(\d{1,2}))?([^\d]+(\d{1,2}))?(:(\d{1,2}))?(:(\d{1,2}))?(.(\d{1,3}))?$/,PARSE_DATE=/^(\d{4})-(\d{1,2})(-(\d{1,2}))/,PARSE_TIME=/(\d\d?)(:(\d\d?)|)(:(\d\d?)|)/,DAYS_IN_MONTH=[0,31,28,31,30,31,30,31,31,30,31,30,31],DAYS_IN_MONTH_LEAP=[0,31,29,31,30,31,30,31,31,30,31,30,31],DAYS_IN_MONTH_MIN=28,DAYS_IN_MONTH_MAX=31,MONTH_MAX=12,MONTH_MIN=1,DAY_MIN=1,DAYS_IN_WEEK=7,MINUTES_IN_HOUR=60,HOURS_IN_DAY=24,FIRST_HOUR=0,MILLISECONDS_IN_MINUTE=6e4,MILLISECONDS_IN_HOUR=36e5,MILLISECONDS_IN_DAY=864e5,MILLISECONDS_IN_WEEK=6048e5,Timestamp={date:"",time:"",year:0,month:0,day:0,weekday:0,hour:0,minute:0,doy:0,workweek:0,hasDay:!1,hasTime:!1,past:!1,current:!1,future:!1,disabled:!1,currentWeekday:!1},TimeObject={hour:0,minute:0};function today(){const e=new Date,t=""+(e.getMonth()+1),a=""+e.getDate(),n=e.getFullYear();return[n,padNumber(t,2),padNumber(a,2)].join("-")}function getStartOfWeek(e,t,a){let n=copyTimestamp(e);if(1===n.day||0===n.weekday)while(!t.includes(n.weekday))n=nextDay(n);return n=findWeekday(n,t[0],prevDay),n=updateFormatted(n),a&&(n=updateRelative(n,a,n.hasTime)),n}function getEndOfWeek(e,t,a){let n=copyTimestamp(e);const r=daysInMonth(n.year,n.month);if(r===n.day||6===n.weekday)while(!t.includes(n.weekday))n=prevDay(n);return n=findWeekday(n,t[t.length-1],nextDay),n=updateFormatted(n),a&&(n=updateRelative(n,a,n.hasTime)),n}function getStartOfMonth(e){const t=copyTimestamp(e);return t.day=DAY_MIN,updateFormatted(t),t}function getEndOfMonth(e){const t=copyTimestamp(e);return t.day=daysInMonth(t.year,t.month),updateFormatted(t),t}function parseTime(e){const t=Object.prototype.toString.call(e);switch(t){case"[object Number]":return e;case"[object String]":{const a=PARSE_TIME.exec(e);return a?60*parseInt(a[1],10)+parseInt(a[3]||0,10):!1}case"[object Object]":return"number"!==typeof e.hour||"number"!==typeof e.minute?!1:60*e.hour+e.minute}return!1}function validateTimestamp(e){return!!PARSE_REGEX.exec(e)}function compareTimestamps(e,t){return JSON.stringify(e)===JSON.stringify(t)}function compareDate(e,t){return getDate(e)===getDate(t)}function compareTime(e,t){return getTime(e)===getTime(t)}function compareDateTime(e,t){return getDateTime(e)===getDateTime(t)}function parsed(e){const t=PARSE_REGEX.exec(e);return t?{date:e,time:padNumber(parseInt(t[6],10)||0,2)+":"+padNumber(parseInt(t[8],10)||0,2),year:parseInt(t[1],10),month:parseInt(t[2],10),day:parseInt(t[4],10)||1,hour:isNaN(parseInt(t[6],10))?0:parseInt(t[6],10),minute:isNaN(parseInt(t[8],10))?0:parseInt(t[8],10),weekday:0,doy:0,workweek:0,hasDay:!!t[4],hasTime:!0,past:!1,current:!1,future:!1,disabled:!1}:null}function parseTimestamp(e,t){let a=parsed(e);return null===a?null:(a=updateFormatted(a),t&&updateRelative(a,t,a.hasTime),a)}function parseDate(e,t=!1){const a=t?"UTC":"";return updateFormatted({date:padNumber(e[`get${a}FullYear`](),4)+"-"+padNumber(e[`get${a}Month`]()+1,2)+"-"+padNumber(e[`get${a}Date`](),2),time:padNumber(e[`get${a}Hours`]()||0,2)+":"+padNumber(e[`get${a}Minutes`]()||0,2),year:e[`get${a}FullYear`](),month:e[`get${a}Month`]()+1,day:e[`get${a}Date`](),hour:e[`get${a}Hours`](),minute:e[`get${a}Minutes`](),weekday:0,doy:0,workweek:0,hasDay:!0,hasTime:!0,past:!1,current:!1,future:!1,disabled:!1})}function getDayIdentifier(e){return 1e8*e.year+1e6*e.month+1e4*e.day}function getTimeIdentifier(e){return 100*e.hour+e.minute}function getDayTimeIdentifier(e){return getDayIdentifier(e)+getTimeIdentifier(e)}function diffTimestamp(e,t,a){const n=Date.UTC(e.year,e.month-1,e.day,e.hour,e.minute),r=Date.UTC(t.year,t.month-1,t.day,t.hour,t.minute);return!0===a&&r<n?0:r-n}function updateRelative(e,t,a=!1){let n=getDayIdentifier(t),r=getDayIdentifier(e),i=n===r;return e.hasTime&&a&&i&&(n=getTimeIdentifier(t),r=getTimeIdentifier(e),i=n===r),e.past=r<n,e.current=i,e.future=r>n,e.currentWeekday=e.weekday===t.weekday,e}function updateMinutes(e,t,a){return e.hasTime=!0,e.hour=Math.floor(t/MINUTES_IN_HOUR),e.minute=t%MINUTES_IN_HOUR,e.time=getTime(e),a&&updateRelative(e,a,!0),e}function updateWeekday(e){return e.weekday=getWeekday(e),e}function updateDayOfYear(e){return e.doy=getDayOfYear(e),e}function updateWorkWeek(e){return e.workweek=getWorkWeek(e),e}function updateDisabled(e,t,a,n,r){const i=getDayIdentifier(e);if(void 0!==t){const o=getDayIdentifier(parsed(t));i<=o&&(e.disabled=!0)}if(!0!==e.disabled&&void 0!==a){const m=getDayIdentifier(parsed(a));i>=m&&(e.disabled=!0)}if(!0!==e.disabled&&Array.isArray(n)&&n.length>0)for(const d in n)if(n[d]===e.weekday){e.disabled=!0;break}if(!0!==e.disabled&&Array.isArray(r)&&r.length>0)for(const u in r)if(Array.isArray(r[u])&&2===r[u].length){const s=parsed(r[u][0]),y=parsed(r[u][1]);if(isBetweenDates(e,s,y)){e.disabled=!0;break}}else{const D=getDayIdentifier(parseTimestamp(r[u]+" 00:00"));if(D===i){e.disabled=!0;break}}return e}function updateFormatted(e){return e.hasTime=!0,e.time=getTime(e),e.date=getDate(e),e.weekday=getWeekday(e),e.doy=getDayOfYear(e),e.workweek=getWorkWeek(e),e}function getDayOfYear(e){if(0!==e.year)return(Date.UTC(e.year,e.month-1,e.day)-Date.UTC(e.year,0,0))/24/60/60/1e3}function getWorkWeek(e){0===e.year&&(e=parseTimestamp(today()));const t=makeDate(e);if(isNaN(t))return 0;const a=new Date(t.getFullYear(),t.getMonth(),t.getDate()),n=(a.setDate(a.getDate()-(a.getDay()+6)%7+3),new Date(a.getFullYear(),0,4)),r=(n.setDate(n.getDate()-(n.getDay()+6)%7+3),a.getTimezoneOffset()-n.getTimezoneOffset()),i=(a.setHours(a.getHours()-r),(a-n)/MILLISECONDS_IN_WEEK);return 1+Math.floor(i)}function getWeekday(e){let t=e.weekday;if(e.hasDay){const a=Math.floor,n=e.day,r=(e.month+9)%MONTH_MAX+1,i=a(e.year/100),o=e.year%100-(e.month<=2?1:0);t=((n+a(2.6*r-.2)-2*i+o+a(o/4)+a(i/4))%7+7)%7}return t}function isLeapYear(e){return 1===(e%4===0^e%100===0^e%400===0)}function daysInMonth(e,t){return(isLeapYear(e)?DAYS_IN_MONTH_LEAP:DAYS_IN_MONTH)[t]}function copyTimestamp(e){return{...e}}function padNumber(e,t){let a=String(e);while(a.length<t)a="0"+a;return a}function getDate(e){let t=padNumber(e.year,4)+"-"+padNumber(e.month,2);return e.hasDay&&(t+="-"+padNumber(e.day,2)),t}function getTime(e){return e.hasTime?padNumber(e.hour,2)+":"+padNumber(e.minute,2):""}function getDateTime(e){return getDate(e)+" "+(e.hasTime?getTime(e):"00:00")}function nextDay(e){return++e.day,e.weekday=(e.weekday+1)%DAYS_IN_WEEK,e.day>DAYS_IN_MONTH_MIN&&e.day>daysInMonth(e.year,e.month)&&(e.day=DAY_MIN,++e.month,e.month>MONTH_MAX)&&(e.month=MONTH_MIN,++e.year),e}function prevDay(e){return e.day--,e.weekday=(e.weekday+6)%DAYS_IN_WEEK,e.day<DAY_MIN&&(e.month--,e.month<MONTH_MIN&&(e.year--,e.month=MONTH_MAX),e.day=daysInMonth(e.year,e.month)),e}function moveRelativeDays(e,t=nextDay,a=1,n=[0,1,2,3,4,5,6]){return relativeDays(e,t,a,n)}function relativeDays(e,t=nextDay,a=1,n=[0,1,2,3,4,5,6]){n.includes(e.weekday)||0!==e.weekday||t!==nextDay||++a;while(--a>=0)e=t(e),n.length<7&&!n.includes(e.weekday)&&++a;return e}function findWeekday(e,t,a=nextDay,n=6){while(e.weekday!==t&&--n>=0)e=a(e);return e}function getWeekdaySkips(t){const e=[1,1,1,1,1,1,1],n=[0,0,0,0,0,0,0];for(let e=0;e<t.length;++e)n[t[e]]=1;for(let a=0;a<DAYS_IN_WEEK;++a){let t=1;for(let e=1;e<DAYS_IN_WEEK;++e){const r=(a+e)%DAYS_IN_WEEK;if(n[r])break;++t}e[a]=n[a]*t}return e}function createDayList(e,t,a,n,r,i,o=[],m=[],d=42,u=0){const s=getDayIdentifier(t),y=[];let D=copyTimestamp(e),f=0,_=f===s;if(!(s<getDayIdentifier(e)))while((!_||y.length<u)&&y.length<d){if(f=getDayIdentifier(D),_=_||f>s&&y.length>=u,_)break;if(0===n[D.weekday]);else{const I=copyTimestamp(D);updateFormatted(I),updateRelative(I,a),updateDisabled(I,r,i,o,m),y.push(I)}D=relativeDays(D,nextDay)}return y}function createIntervalList(t,a,n,r,i){const o=[];for(let e=0;e<r;++e){const m=(a+e)*n,d=copyTimestamp(t);o.push(updateMinutes(d,m,i))}return o}function createNativeLocaleFormatter(n,r){const i=(e,t)=>"";return"undefined"===typeof Intl||"undefined"===typeof Intl.DateTimeFormat?i:(t,e)=>{try{const a=new Intl.DateTimeFormat(n||void 0,r(t,e));return a.format(makeDateTime(t))}catch(e){return console.error(`Intl.DateTimeFormat: ${e.message} -> `+getDateTime(t)),i}}}function makeDate(e,t=!0){return t?new Date(Date.UTC(e.year,e.month-1,e.day,0,0)):new Date(e.year,e.month-1,e.day,0,0)}function makeDateTime(e,t=!0){return t?new Date(Date.UTC(e.year,e.month-1,e.day,e.hour,e.minute)):new Date(e.year,e.month-1,e.day,e.hour,e.minute)}function validateNumber(e){return isFinite(parseInt(e,10))}function maxTimestamp(e,t=!1){const a=!0===t?getDayTimeIdentifier:getDayIdentifier;return e.reduce((e,t)=>{return Math.max(a(e),a(t))===a(e)?e:t})}function minTimestamp(e,t=!1){const a=!0===t?getDayTimeIdentifier:getDayIdentifier;return e.reduce((e,t)=>{return Math.min(a(e),a(t))===a(e)?e:t})}function isBetweenDates(e,t,a,n){const r=getDayIdentifier(e)+(!0===n?getTimeIdentifier(e):0),i=getDayIdentifier(t)+(!0===n?getTimeIdentifier(t):0),o=getDayIdentifier(a)+(!0===n?getTimeIdentifier(a):0);return r>=i&&r<=o}function isOverlappingDates(e,t,a,n){const r=getDayIdentifier(e),i=getDayIdentifier(t),o=getDayIdentifier(a),m=getDayIdentifier(n);return r>=o&&r<=m||i>=o&&i<=m||o>=r&&i>=m}function addToDate(e,t){const n=copyTimestamp(e);let r;return __forEachObject(t,(e,t)=>{if(void 0!==n[t]){n[t]+=parseInt(e,10);const a=NORMALIZE_TYPES.indexOf(t);-1!==a&&(r=void 0===r?a:Math.min(a,r))}}),void 0!==r&&__normalize(n,NORMALIZE_TYPES[r]),updateFormatted(n),n}const NORMALIZE_TYPES=["minute","hour","day","month"];function __forEachObject(t,a){Object.keys(t).forEach(e=>a(t[e],e))}function __normalizeMinute(e){if(e.minute>=MINUTES_IN_HOUR||e.minute<0){const t=Math.floor(e.minute/MINUTES_IN_HOUR);e.minute-=t*MINUTES_IN_HOUR,e.hour+=t,__normalizeHour(e)}return e}function __normalizeHour(e){if(e.hour>=HOURS_IN_DAY||e.hour<0){const t=Math.floor(e.hour/HOURS_IN_DAY);e.hour-=t*HOURS_IN_DAY,e.day+=t,__normalizeDay(e)}return e}function __normalizeDay(t){__normalizeMonth(t);let a=daysInMonth(t.year,t.month);if(t.day>a){++t.month,t.month>MONTH_MAX&&__normalizeMonth(t);let e=t.day-a;a=daysInMonth(t.year,t.month);do{e>a&&(++t.month,t.month>MONTH_MAX&&__normalizeMonth(t),e-=a,a=daysInMonth(t.year,t.month))}while(e>a);t.day=e}else if(t.day<=0){let e=-1*t.day;--t.month,t.month<=0&&__normalizeMonth(t),a=daysInMonth(t.year,t.month);do{e>a&&(e-=a,--t.month,t.month<=0&&__normalizeMonth(t),a=daysInMonth(t.year,t.month))}while(e>a);t.day=a-e}return t}function __normalizeMonth(e){if(e.month>MONTH_MAX){const t=Math.floor(e.month/MONTH_MAX);e.month=e.month%MONTH_MAX,e.year+=t}else e.month<MONTH_MIN&&(e.month+=MONTH_MAX,--e.year);return e}function __normalize(e,t){switch(t){case"minute":return __normalizeMinute(e);case"hour":return __normalizeHour(e);case"day":return __normalizeDay(e);case"month":return __normalizeMonth(e)}}function daysBetween(e,t){const a=diffTimestamp(e,t,!0);return Math.floor(a/MILLISECONDS_IN_DAY)}function weeksBetween(e,t){let a=copyTimestamp(e),n=copyTimestamp(t);return a=findWeekday(a,0),n=findWeekday(n,6),Math.ceil(daysBetween(a,n)/DAYS_IN_WEEK)}const weekdayDateMap={Sun:new Date("2020-01-05T00:00:00.000Z"),Mon:new Date("2020-01-06T00:00:00.000Z"),Tue:new Date("2020-01-07T00:00:00.000Z"),Wed:new Date("2020-01-08T00:00:00.000Z"),Thu:new Date("2020-01-09T00:00:00.000Z"),Fri:new Date("2020-01-10T00:00:00.000Z"),Sat:new Date("2020-01-11T00:00:00.000Z")};function getWeekdayFormatter(){const r=(e,t)=>"",i={long:{timeZone:"UTC",weekday:"long"},short:{timeZone:"UTC",weekday:"short"},narrow:{timeZone:"UTC",weekday:"narrow"}};return"undefined"===typeof Intl||"undefined"===typeof Intl.DateTimeFormat?r:e;function e(t,e,a){try{const n=new Intl.DateTimeFormat(a||void 0,i[e]||i["long"]);return n.format(weekdayDateMap[t])}catch(e){return console.error(`Intl.DateTimeFormat: ${e.message} -> day of week: `+t),r}}}function getWeekdayNames(t,a){const e=Object.keys(weekdayDateMap),n=getWeekdayFormatter();return e.map(e=>n(e,t,a))}function getMonthFormatter(){const i=(e,t)=>"",o={long:{timeZone:"UTC",month:"long"},short:{timeZone:"UTC",month:"short"},narrow:{timeZone:"UTC",month:"narrow"}};return"undefined"===typeof Intl||"undefined"===typeof Intl.DateTimeFormat?i:e;function e(t,e,a){try{const n=new Intl.DateTimeFormat(a||void 0,o[e]||o["long"]),r=new Date;return r.setDate(1),r.setMonth(t),n.format(r)}catch(e){return console.error(`Intl.DateTimeFormat: ${e.message} -> month: `+t),i}}}function getMonthNames(t,a){const n=getMonthFormatter();return[...Array(12).keys()].map(e=>n(e,t,a))}function convertToUnit(e,t="px"){if(null!=e&&""!==e)return isNaN(e)?String(e):"auto"===e?e:""+Number(e)+t}function indexOf(t,a){for(let e=0;e<t.length;e++)if(!0===a(t[e],e))return e;return-1}var Plugin={version:version,PARSE_REGEX:PARSE_REGEX,PARSE_DATE:PARSE_DATE,PARSE_TIME:PARSE_TIME,DAYS_IN_MONTH:DAYS_IN_MONTH,DAYS_IN_MONTH_LEAP:DAYS_IN_MONTH_LEAP,DAYS_IN_MONTH_MIN:DAYS_IN_MONTH_MIN,DAYS_IN_MONTH_MAX:DAYS_IN_MONTH_MAX,MONTH_MAX:MONTH_MAX,MONTH_MIN:MONTH_MIN,DAY_MIN:DAY_MIN,DAYS_IN_WEEK:DAYS_IN_WEEK,MINUTES_IN_HOUR:MINUTES_IN_HOUR,HOURS_IN_DAY:HOURS_IN_DAY,FIRST_HOUR:FIRST_HOUR,MILLISECONDS_IN_MINUTE:MILLISECONDS_IN_MINUTE,MILLISECONDS_IN_HOUR:MILLISECONDS_IN_HOUR,MILLISECONDS_IN_DAY:MILLISECONDS_IN_DAY,MILLISECONDS_IN_WEEK:MILLISECONDS_IN_WEEK,Timestamp:Timestamp,TimeObject:TimeObject,today:today,getStartOfWeek:getStartOfWeek,getEndOfWeek:getEndOfWeek,getStartOfMonth:getStartOfMonth,getEndOfMonth:getEndOfMonth,parseTime:parseTime,validateTimestamp:validateTimestamp,parsed:parsed,parseTimestamp:parseTimestamp,parseDate:parseDate,getDayIdentifier:getDayIdentifier,getTimeIdentifier:getTimeIdentifier,getDayTimeIdentifier:getDayTimeIdentifier,diffTimestamp:diffTimestamp,updateRelative:updateRelative,updateMinutes:updateMinutes,updateWeekday:updateWeekday,updateDayOfYear:updateDayOfYear,updateWorkWeek:updateWorkWeek,updateDisabled:updateDisabled,updateFormatted:updateFormatted,getDayOfYear:getDayOfYear,getWorkWeek:getWorkWeek,getWeekday:getWeekday,isLeapYear:isLeapYear,daysInMonth:daysInMonth,copyTimestamp:copyTimestamp,padNumber:padNumber,getDate:getDate,getTime:getTime,getDateTime:getDateTime,nextDay:nextDay,prevDay:prevDay,relativeDays:relativeDays,moveRelativeDays:moveRelativeDays,findWeekday:findWeekday,getWeekdaySkips:getWeekdaySkips,createDayList:createDayList,createIntervalList:createIntervalList,createNativeLocaleFormatter:createNativeLocaleFormatter,makeDate:makeDate,makeDateTime:makeDateTime,validateNumber:validateNumber,maxTimestamp:maxTimestamp,minTimestamp:minTimestamp,isBetweenDates:isBetweenDates,isOverlappingDates:isOverlappingDates,daysBetween:daysBetween,weeksBetween:weeksBetween,addToDate:addToDate,compareTimestamps:compareTimestamps,compareDate:compareDate,compareTime:compareTime,compareDateTime:compareDateTime,getWeekdayFormatter:getWeekdayFormatter,getWeekdayNames:getWeekdayNames,getMonthFormatter:getMonthFormatter,getMonthNames:getMonthNames,convertToUnit:convertToUnit,indexOf:indexOf};export{DAYS_IN_MONTH,DAYS_IN_MONTH_LEAP,DAYS_IN_MONTH_MAX,DAYS_IN_MONTH_MIN,DAYS_IN_WEEK,DAY_MIN,FIRST_HOUR,HOURS_IN_DAY,MILLISECONDS_IN_DAY,MILLISECONDS_IN_HOUR,MILLISECONDS_IN_MINUTE,MILLISECONDS_IN_WEEK,MINUTES_IN_HOUR,MONTH_MAX,MONTH_MIN,PARSE_DATE,PARSE_REGEX,PARSE_TIME,TimeObject,Timestamp,addToDate,compareDate,compareDateTime,compareTime,compareTimestamps,convertToUnit,copyTimestamp,createDayList,createIntervalList,createNativeLocaleFormatter,daysBetween,daysInMonth,Plugin as default,diffTimestamp,findWeekday,getDate,getDateTime,getDayIdentifier,getDayOfYear,getDayTimeIdentifier,getEndOfMonth,getEndOfWeek,getMonthFormatter,getMonthNames,getStartOfMonth,getStartOfWeek,getTime,getTimeIdentifier,getWeekday,getWeekdayFormatter,getWeekdayNames,getWeekdaySkips,getWorkWeek,indexOf,isBetweenDates,isLeapYear,isOverlappingDates,makeDate,makeDateTime,maxTimestamp,minTimestamp,moveRelativeDays,nextDay,padNumber,parseDate,parseTime,parseTimestamp,parsed,prevDay,relativeDays,today,updateDayOfYear,updateDisabled,updateFormatted,updateMinutes,updateRelative,updateWeekday,updateWorkWeek,validateNumber,validateTimestamp,version,weeksBetween};