UNPKG

@sbh321/qcalendar

Version:

A forked version of Jeff Galbraith's fork of Quasar UI QCalendar

6 lines 15.7 kB
/*! * @subhambhandari/qcalendar v4.0.0-beta.19 * (c) 2024 Subham Bhandari <bhandarimaiya65@gmail.com> * Released under the MIT License. */ "use strict";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(),r=e.getFullYear();return[r,padNumber(t,2),padNumber(a,2)].join("-")}function getStartOfWeek(e,t,a){let r=copyTimestamp(e);if(1===r.day||0===r.weekday)while(!t.includes(r.weekday))r=nextDay(r);return r=findWeekday(r,t[0],prevDay),r=updateFormatted(r),a&&(r=updateRelative(r,a,r.hasTime)),r}function getEndOfWeek(e,t,a){let r=copyTimestamp(e);const n=daysInMonth(r.year,r.month);if(n===r.day||6===r.weekday)while(!t.includes(r.weekday))r=prevDay(r);return r=findWeekday(r,t[t.length-1],nextDay),r=updateFormatted(r),a&&(r=updateRelative(r,a,r.hasTime)),r}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 r=Date.UTC(e.year,e.month-1,e.day,e.hour,e.minute),n=Date.UTC(t.year,t.month-1,t.day,t.hour,t.minute);return!0===a&&n<r?0:n-r}function updateRelative(e,t,a=!1){let r=getDayIdentifier(t),n=getDayIdentifier(e),o=r===n;return e.hasTime&&a&&o&&(r=getTimeIdentifier(t),n=getTimeIdentifier(e),o=r===n),e.past=n<r,e.current=o,e.future=n>r,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,r,n){const o=getDayIdentifier(e);if(void 0!==t){const i=getDayIdentifier(parsed(t));o<=i&&(e.disabled=!0)}if(!0!==e.disabled&&void 0!==a){const s=getDayIdentifier(parsed(a));o>=s&&(e.disabled=!0)}if(!0!==e.disabled&&Array.isArray(r)&&r.length>0)for(const m in r)if(r[m]===e.weekday){e.disabled=!0;break}if(!0!==e.disabled&&Array.isArray(n)&&n.length>0)for(const d in n)if(Array.isArray(n[d])&&2===n[d].length){const u=parsed(n[d][0]),p=parsed(n[d][1]);if(isBetweenDates(e,u,p)){e.disabled=!0;break}}else{const y=getDayIdentifier(parseTimestamp(n[d]+" 00:00"));if(y===o){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()),r=(a.setDate(a.getDate()-(a.getDay()+6)%7+3),new Date(a.getFullYear(),0,4)),n=(r.setDate(r.getDate()-(r.getDay()+6)%7+3),a.getTimezoneOffset()-r.getTimezoneOffset()),o=(a.setHours(a.getHours()-n),(a-r)/MILLISECONDS_IN_WEEK);return 1+Math.floor(o)}function getWeekday(e){let t=e.weekday;if(e.hasDay){const a=Math.floor,r=e.day,n=(e.month+9)%MONTH_MAX+1,o=a(e.year/100),i=e.year%100-(e.month<=2?1:0);t=((r+a(2.6*n-.2)-2*o+i+a(i/4)+a(o/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,r=[0,1,2,3,4,5,6]){return relativeDays(e,t,a,r)}function relativeDays(e,t=nextDay,a=1,r=[0,1,2,3,4,5,6]){r.includes(e.weekday)||0!==e.weekday||t!==nextDay||++a;while(--a>=0)e=t(e),r.length<7&&!r.includes(e.weekday)&&++a;return e}function findWeekday(e,t,a=nextDay,r=6){while(e.weekday!==t&&--r>=0)e=a(e);return e}function getWeekdaySkips(t){const e=[1,1,1,1,1,1,1],r=[0,0,0,0,0,0,0];for(let e=0;e<t.length;++e)r[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 n=(a+e)%DAYS_IN_WEEK;if(r[n])break;++t}e[a]=r[a]*t}return e}function createDayList(e,t,a,r,n,o,i=[],s=[],m=42,d=0){const u=getDayIdentifier(t),p=[];let y=copyTimestamp(e),D=0,f=D===u;if(!(u<getDayIdentifier(e)))while((!f||p.length<d)&&p.length<m){if(D=getDayIdentifier(y),f=f||D>u&&p.length>=d,f)break;if(0===r[y.weekday]);else{const c=copyTimestamp(y);updateFormatted(c),updateRelative(c,a),updateDisabled(c,n,o,i,s),p.push(c)}y=relativeDays(y,nextDay)}return p}function createIntervalList(t,a,r,n,o){const i=[];for(let e=0;e<n;++e){const s=(a+e)*r,m=copyTimestamp(t);i.push(updateMinutes(m,s,o))}return i}function createNativeLocaleFormatter(r,n){const o=(e,t)=>"";return"undefined"===typeof Intl||"undefined"===typeof Intl.DateTimeFormat?o:(t,e)=>{try{const a=new Intl.DateTimeFormat(r||void 0,n(t,e));return a.format(makeDateTime(t))}catch(e){return console.error(`Intl.DateTimeFormat: ${e.message} -> `+getDateTime(t)),o}}}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,r){const n=getDayIdentifier(e)+(!0===r?getTimeIdentifier(e):0),o=getDayIdentifier(t)+(!0===r?getTimeIdentifier(t):0),i=getDayIdentifier(a)+(!0===r?getTimeIdentifier(a):0);return n>=o&&n<=i}function isOverlappingDates(e,t,a,r){const n=getDayIdentifier(e),o=getDayIdentifier(t),i=getDayIdentifier(a),s=getDayIdentifier(r);return n>=i&&n<=s||o>=i&&o<=s||i>=n&&o>=s}function addToDate(e,t){const r=copyTimestamp(e);let n;return __forEachObject(t,(e,t)=>{if(void 0!==r[t]){r[t]+=parseInt(e,10);const a=NORMALIZE_TYPES.indexOf(t);-1!==a&&(n=void 0===n?a:Math.min(a,n))}}),void 0!==n&&__normalize(r,NORMALIZE_TYPES[n]),updateFormatted(r),r}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),r=copyTimestamp(t);return a=findWeekday(a,0),r=findWeekday(r,6),Math.ceil(daysBetween(a,r)/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 n=(e,t)=>"",o={long:{timeZone:"UTC",weekday:"long"},short:{timeZone:"UTC",weekday:"short"},narrow:{timeZone:"UTC",weekday:"narrow"}};return"undefined"===typeof Intl||"undefined"===typeof Intl.DateTimeFormat?n:e;function e(t,e,a){try{const r=new Intl.DateTimeFormat(a||void 0,o[e]||o["long"]);return r.format(weekdayDateMap[t])}catch(e){return console.error(`Intl.DateTimeFormat: ${e.message} -> day of week: `+t),n}}}function getWeekdayNames(t,a){const e=Object.keys(weekdayDateMap),r=getWeekdayFormatter();return e.map(e=>r(e,t,a))}function getMonthFormatter(){const o=(e,t)=>"",i={long:{timeZone:"UTC",month:"long"},short:{timeZone:"UTC",month:"short"},narrow:{timeZone:"UTC",month:"narrow"}};return"undefined"===typeof Intl||"undefined"===typeof Intl.DateTimeFormat?o:e;function e(t,e,a){try{const r=new Intl.DateTimeFormat(a||void 0,i[e]||i["long"]),n=new Date;return n.setDate(1),n.setMonth(t),r.format(n)}catch(e){return console.error(`Intl.DateTimeFormat: ${e.message} -> month: `+t),o}}}function getMonthNames(t,a){const r=getMonthFormatter();return[...Array(12).keys()].map(e=>r(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}exports.DAYS_IN_MONTH=DAYS_IN_MONTH,exports.DAYS_IN_MONTH_LEAP=DAYS_IN_MONTH_LEAP,exports.DAYS_IN_MONTH_MAX=DAYS_IN_MONTH_MAX,exports.DAYS_IN_MONTH_MIN=DAYS_IN_MONTH_MIN,exports.DAYS_IN_WEEK=DAYS_IN_WEEK,exports.DAY_MIN=DAY_MIN,exports.FIRST_HOUR=FIRST_HOUR,exports.HOURS_IN_DAY=HOURS_IN_DAY,exports.MILLISECONDS_IN_DAY=MILLISECONDS_IN_DAY,exports.MILLISECONDS_IN_HOUR=MILLISECONDS_IN_HOUR,exports.MILLISECONDS_IN_MINUTE=MILLISECONDS_IN_MINUTE,exports.MILLISECONDS_IN_WEEK=MILLISECONDS_IN_WEEK,exports.MINUTES_IN_HOUR=MINUTES_IN_HOUR,exports.MONTH_MAX=MONTH_MAX,exports.MONTH_MIN=MONTH_MIN,exports.PARSE_DATE=PARSE_DATE,exports.PARSE_REGEX=PARSE_REGEX,exports.PARSE_TIME=PARSE_TIME,exports.TimeObject=TimeObject,exports.Timestamp=Timestamp,exports.addToDate=addToDate,exports.compareDate=compareDate,exports.compareDateTime=compareDateTime,exports.compareTime=compareTime,exports.compareTimestamps=compareTimestamps,exports.convertToUnit=convertToUnit,exports.copyTimestamp=copyTimestamp,exports.createDayList=createDayList,exports.createIntervalList=createIntervalList,exports.createNativeLocaleFormatter=createNativeLocaleFormatter,exports.daysBetween=daysBetween,exports.daysInMonth=daysInMonth,exports.diffTimestamp=diffTimestamp,exports.findWeekday=findWeekday,exports.getDate=getDate,exports.getDateTime=getDateTime,exports.getDayIdentifier=getDayIdentifier,exports.getDayOfYear=getDayOfYear,exports.getDayTimeIdentifier=getDayTimeIdentifier,exports.getEndOfMonth=getEndOfMonth,exports.getEndOfWeek=getEndOfWeek,exports.getMonthFormatter=getMonthFormatter,exports.getMonthNames=getMonthNames,exports.getStartOfMonth=getStartOfMonth,exports.getStartOfWeek=getStartOfWeek,exports.getTime=getTime,exports.getTimeIdentifier=getTimeIdentifier,exports.getWeekday=getWeekday,exports.getWeekdayFormatter=getWeekdayFormatter,exports.getWeekdayNames=getWeekdayNames,exports.getWeekdaySkips=getWeekdaySkips,exports.getWorkWeek=getWorkWeek,exports.indexOf=indexOf,exports.isBetweenDates=isBetweenDates,exports.isLeapYear=isLeapYear,exports.isOverlappingDates=isOverlappingDates,exports.makeDate=makeDate,exports.makeDateTime=makeDateTime,exports.maxTimestamp=maxTimestamp,exports.minTimestamp=minTimestamp,exports.moveRelativeDays=moveRelativeDays,exports.nextDay=nextDay,exports.padNumber=padNumber,exports.parseDate=parseDate,exports.parseTime=parseTime,exports.parseTimestamp=parseTimestamp,exports.parsed=parsed,exports.prevDay=prevDay,exports.relativeDays=relativeDays,exports.today=today,exports.updateDayOfYear=updateDayOfYear,exports.updateDisabled=updateDisabled,exports.updateFormatted=updateFormatted,exports.updateMinutes=updateMinutes,exports.updateRelative=updateRelative,exports.updateWeekday=updateWeekday,exports.updateWorkWeek=updateWorkWeek,exports.validateNumber=validateNumber,exports.validateTimestamp=validateTimestamp,exports.version=version,exports.weeksBetween=weeksBetween;