@quasar/quasar-ui-qcalendar
Version:
QCalendar - Day/Month/Week Calendars, Popups, Date Pickers, Schedules, Agendas, Planners and Tasks for your Vue Apps
6 lines • 14.8 kB
JavaScript
/*!
* @quasar/quasar-ui-qcalendar v4.1.2
* (c) 2025 Jeff Galbraith <jeff@quasar.dev>
* Released under the MIT License.
*/
const version="4.1.2",PARSE_DATETIME=/^(\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],TIME_CONSTANTS={MILLISECONDS_IN:{SECOND:1e3,MINUTE:6e4,HOUR:36e5,DAY:864e5,WEEK:6048e5},SECONDS_IN:{MINUTE:60,HOUR:3600,DAY:86400,WEEK:604800},MINUTES_IN:{MINUTE:1,HOUR:60,DAY:1440,WEEK:10080},HOURS_IN:{DAY:24,WEEK:168},DAYS_IN:{WEEK:7}},DAYS_IN_MONTH_MIN=28,DAYS_IN_MONTH_MAX=31,MONTH_MAX=12,MONTH_MIN=1,DAY_MIN=1,FIRST_HOUR=0;function validateTimestamp(e){return"string"===typeof e&&PARSE_DATETIME.test(e)}function parsed(e){if("string"!==typeof e)return null;const t=PARSE_DATETIME.exec(e);if(!t||!t[1]||!t[2])return null;const a=parseInt(t[1],10),r=parseInt(t[2],10),n=parseInt(t[4]||"1",10),i=parseInt(t[6]||"0",10),o=parseInt(t[8]||"0",10);return{date:e,time:i.toString().padStart(2,"0")+":"+o.toString().padStart(2,"0"),year:a,month:r,day:n,hour:i,minute:o,hasDay:!!t[4],hasTime:!0,past:!1,current:!1,future:!1,disabled:!1,weekday:0,doy:0,workweek:0}}function parseDate(e,t=!1){if(!(e instanceof Date))return null;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 padNumber(e,t){let a=String(e);while(a.length<t)a="0"+a;return a}function isLeapYear(e){return 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 nextDay(e){const t=new Date(e.year,e.month-1,e.day+1);return updateFormatted(normalizeTimestamp({...e,year:t.getFullYear(),month:t.getMonth()+1,day:t.getDate()}))}function prevDay(e){const t=new Date(e.year,e.month-1,e.day-1);return updateFormatted(normalizeTimestamp({...e,year:t.getFullYear(),month:t.getMonth()+1,day:t.getDate()}))}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 isToday(e){return e===today()}function getStartOfWeek(e,t,a){let r=copyTimestamp(e);if(t){if(1===r.day||0===r.weekday)while(!t.includes(Number(r.weekday)))r=nextDay(r);r=findWeekday(r,t[0],prevDay),r=updateFormatted(r),a&&(r=updateRelative(r,a,r.hasTime))}return r}function getEndOfWeek(e,t,a){let r=copyTimestamp(e);if(t&&Array.isArray(t)){const n=daysInMonth(r.year,r.month);if(n===r.day||r.weekday===t[t.length-1])while(!t.includes(Number(r.weekday)))r=prevDay(r);r=findWeekday(r,t[t.length-1],nextDay),r=updateFormatted(r),a&&(r=updateRelative(r,a,r.hasTime))}return r}function getStartOfMonth(e){let t=copyTimestamp(e);return t.day=DAY_MIN,t=updateFormatted(t),t}function getEndOfMonth(e){let t=copyTimestamp(e);return t.day=daysInMonth(t.year,t.month),t=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"object"!==typeof e||"number"!==typeof e.hour||"number"!==typeof e.minute?!1:"object"===typeof e&&"hour"in e&&"minute"in e&&60*e.hour+e.minute}return!1}function compareTimestamps(e,t){return!(!e||!t)&&e.year===t.year&&e.month===t.month&&e.day===t.day&&e.hour===t.hour&&e.minute===t.minute}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 parseTimestamp(e,t=null){let a=parsed(e);return a?(a=updateFormatted(a),t&&(a=updateRelative(a,t,a.hasTime)),a):null}function getDayIdentifier(e){return 1e8*(e.year??0)+1e6*(e.month??0)+1e4*(e.day??0)}function getTimeIdentifier(e){return 100*(e.hour??0)+(e.minute??0)}function getDayTimeIdentifier(e){return getDayIdentifier(e)+getTimeIdentifier(e)}function diffTimestamp(e,t,a=!1){const r=Date.UTC(e.year??0,(e.month??1)-1,e.day??1,e.hour??0,e.minute??0),n=Date.UTC(t.year??0,(t.month??1)-1,t.day??1,t.hour??0,t.minute??0);return!0===a&&n<r?0:n-r}function updateRelative(e,t,a=!1){let r=copyTimestamp(e),n=getDayIdentifier(t),i=getDayIdentifier(r),o=n===i;return r.hasTime&&a&&o&&(n=getTimeIdentifier(t),i=getTimeIdentifier(r),o=n===i),r.past=i<n,r.current=o,r.future=i>n,r.currentWeekday=r.weekday===t.weekday,r}function updateMinutes(e,t,a=null){let r=copyTimestamp(e);return r.hasTime=!0,r.hour=Math.floor(t/TIME_CONSTANTS.MINUTES_IN.HOUR),r.minute=t%TIME_CONSTANTS.MINUTES_IN.HOUR,r.time=getTime(r),a&&(r=updateRelative(r,a,!0)),r}function updateWeekday(e){let t=copyTimestamp(e);return t.weekday=getWeekday(t),t}function updateDayOfYear(e){let t=copyTimestamp(e);return t.doy=getDayOfYear(t)||0,t}function updateWorkWeek(e){let t=copyTimestamp(e);return t.workweek=getWorkWeek(t),t}function updateDisabled(e,t,a,r,n){let i=copyTimestamp(e);const o=getDayIdentifier(i);if(void 0!==t){const u=parsed(t);if(u){const p=getDayIdentifier(u);o<=p&&(i.disabled=!0)}}if(!0!==i.disabled&&void 0!==a){const y=parsed(a);if(y){const T=getDayIdentifier(y);o>=T&&(i.disabled=!0)}}if(!0!==i.disabled&&Array.isArray(r)&&r.length>0)for(var s in r)if(r[s]===i.weekday){i.disabled=!0;break}if(!0!==i.disabled&&Array.isArray(n)&&n.length>0)for(var m in n)if(Array.isArray(n[m])&&2===n[m].length&&n[m][0]&&n[m][1]){const f=parsed(n[m][0]),c=parsed(n[m][1]);if(f&&c&&isBetweenDates(i,f,c)){i.disabled=!0;break}}else{const D=n[m];if(Array.isArray(D))for(var d of D){const g=parseTimestamp(d);if(g){const l=getDayIdentifier(g);if(l===o){i.disabled=!0;break}}}else if(D){const h=parseTimestamp(D);if(h){const I=getDayIdentifier(h);I===o&&(i.disabled=!0)}}}return i}function updateFormatted(e){let t=copyTimestamp(e);return t.hasTime=!0,t.time=getTime(t),t.date=getDate(t),t.weekday=getWeekday(t),t.doy=getDayOfYear(t)||0,t.workweek=getWorkWeek(t),t}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){let t=copyTimestamp(e);if(0===t.year){const n=parseTimestamp(today());n&&(t=n)}const a=new Date(Date.UTC(t.year,t.month-1,t.day)),r=4;a.setUTCDate(a.getUTCDate()-(a.getUTCDay()+6)%7+r),a.setUTCDate(a.getUTCDate()+r-(a.getUTCDay()||7));e=new Date(Date.UTC(a.getUTCFullYear(),0,1)),e=Math.ceil(((a.valueOf()-e.valueOf())/864e5+1)/7);return e}function getWeekday(e){let t=e.weekday;if(e.hasDay){const a=Math.floor,r=e.day,n=(e.month+9)%MONTH_MAX+1,i=a(e.year/100),o=e.year%100-(e.month<=2?1:0);t=((r+a(2.6*n-.2)-2*i+o+a(o/4)+a(i/4))%7+7)%7}return t??0}function copyTimestamp(e){return{...e}}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 moveRelativeDays(e,t=nextDay,a=1,r=[0,1,2,3,4,5,6]){const n=copyTimestamp(e);return relativeDays(n,t,a,r)}function relativeDays(e,t=nextDay,a=1,r=[0,1,2,3,4,5,6]){let n=copyTimestamp(e);r.includes(Number(n.weekday))||0!==n.weekday||t!==nextDay||++a;while(--a>=0)n=t(n),r.length<7&&!r.includes(Number(n.weekday))&&++a;return n}function findWeekday(e,t,a=nextDay,r=6){let n=copyTimestamp(e);while(n.weekday!==t&&--r>=0)n=a(n);return n}function createDayList(e,t,a,r=[0,1,2,3,4,5,6],n=void 0,i=void 0,o=[],s=[],m=42,d=0){const u=getDayIdentifier(e),p=getDayIdentifier(t),y=[];let T=copyTimestamp(e),f=0,c=f===p;if(!(p<u))while((!c||y.length<d)&&y.length<m){if(f=getDayIdentifier(T),c=c||f>p&&y.length>=d,c)break;if(r.includes(Number(T.weekday))){let e=copyTimestamp(T);e=updateFormatted(e),e=updateRelative(e,a),e=updateDisabled(e,n,i,o,s),y.push(e)}T=relativeDays(T,nextDay)}return y}function createIntervalList(t,a,r,n,i){const o=[];for(let e=0;e<n;++e){const s=(a+e)*r,m=copyTimestamp(t);o.push(updateMinutes(m,s,i))}return o}function createNativeLocaleFormatter(r,n){const e=()=>"";return"undefined"===typeof Intl||"undefined"===typeof Intl.DateTimeFormat?e:(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)),""}}}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(Number(e))}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=!1){const n=getDayIdentifier(e)+(!0===r?getTimeIdentifier(e):0),i=getDayIdentifier(t)+(!0===r?getTimeIdentifier(t):0),o=getDayIdentifier(a)+(!0===r?getTimeIdentifier(a):0);return n>=i&&n<=o}function isOverlappingDates(e,t,a,r){const n=getDayIdentifier(e),i=getDayIdentifier(t),o=getDayIdentifier(a),s=getDayIdentifier(r);return n>=o&&n<=s||i>=o&&i<=s||o>=n&&i>=s}function addToDate(e,t){const a=copyTimestamp(e);return t.year&&(a.year+=t.year),t.month&&(a.month+=t.month),t.day&&(a.day+=t.day),t.hour&&(a.hour+=t.hour),t.minute&&(a.minute+=t.minute),updateFormatted(normalizeTimestamp(a))}function normalizeTimestamp(e){const t=new Date(e.year,e.month-1,e.day,e.hour,e.minute);return{...e,year:t.getFullYear(),month:t.getMonth()+1,day:t.getDate(),hour:t.getHours(),minute:t.getMinutes()}}function daysBetween(e,t){const a=diffTimestamp(e,t,!0);return Math.floor(a/TIME_CONSTANTS.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)/TIME_CONSTANTS.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 e=()=>"",n={long:{timeZone:"UTC",weekday:"long"},short:{timeZone:"UTC",weekday:"short"},narrow:{timeZone:"UTC",weekday:"narrow"}};return"undefined"===typeof Intl||"undefined"===typeof Intl.DateTimeFormat?e:t;function t(t,e,a){try{const r=new Intl.DateTimeFormat(a||void 0,n[e]||n["long"]);return r.format(weekdayDateMap[t])}catch(e){return e instanceof Error&&console.error(`Intl.DateTimeFormat: ${e.message} -> day of week: `+t),""}}}function getWeekdayNames(t,a){const e=Object.keys(weekdayDateMap),r=getWeekdayFormatter();return e.map(e=>String(r(e,t,a)))}function getMonthFormatter(){const e=()=>"",i={long:{timeZone:"UTC",month:"long"},short:{timeZone:"UTC",month:"short"},narrow:{timeZone:"UTC",month:"narrow"}};return"undefined"===typeof Intl||"undefined"===typeof Intl.DateTimeFormat?e:t;function t(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 e instanceof Error&&console.error(`Intl.DateTimeFormat: ${e.message} -> month: `+t),""}}}function getMonthNames(t,a){const r=getMonthFormatter();return[...Array(12).keys()].map(e=>r(e,t,a))}function convertToUnit(e,t="px"){if(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}function minCharWidth(e,t){return 0===t?e:e.slice(0,t)}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.DAY_MIN=DAY_MIN,exports.FIRST_HOUR=FIRST_HOUR,exports.MONTH_MAX=MONTH_MAX,exports.MONTH_MIN=MONTH_MIN,exports.PARSE_DATE=PARSE_DATE,exports.PARSE_DATETIME=PARSE_DATETIME,exports.PARSE_TIME=PARSE_TIME,exports.TIME_CONSTANTS=TIME_CONSTANTS,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.getWorkWeek=getWorkWeek,exports.indexOf=indexOf,exports.isBetweenDates=isBetweenDates,exports.isLeapYear=isLeapYear,exports.isOverlappingDates=isOverlappingDates,exports.isToday=isToday,exports.makeDate=makeDate,exports.makeDateTime=makeDateTime,exports.maxTimestamp=maxTimestamp,exports.minCharWidth=minCharWidth,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;