123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734 |
- // Utilities
- import { createRange, padStart } from "../../../util/index.mjs"; // Types
- const firstDay = {
- '001': 1,
- AD: 1,
- AE: 6,
- AF: 6,
- AG: 0,
- AI: 1,
- AL: 1,
- AM: 1,
- AN: 1,
- AR: 1,
- AS: 0,
- AT: 1,
- AU: 1,
- AX: 1,
- AZ: 1,
- BA: 1,
- BD: 0,
- BE: 1,
- BG: 1,
- BH: 6,
- BM: 1,
- BN: 1,
- BR: 0,
- BS: 0,
- BT: 0,
- BW: 0,
- BY: 1,
- BZ: 0,
- CA: 0,
- CH: 1,
- CL: 1,
- CM: 1,
- CN: 1,
- CO: 0,
- CR: 1,
- CY: 1,
- CZ: 1,
- DE: 1,
- DJ: 6,
- DK: 1,
- DM: 0,
- DO: 0,
- DZ: 6,
- EC: 1,
- EE: 1,
- EG: 6,
- ES: 1,
- ET: 0,
- FI: 1,
- FJ: 1,
- FO: 1,
- FR: 1,
- GB: 1,
- 'GB-alt-variant': 0,
- GE: 1,
- GF: 1,
- GP: 1,
- GR: 1,
- GT: 0,
- GU: 0,
- HK: 0,
- HN: 0,
- HR: 1,
- HU: 1,
- ID: 0,
- IE: 1,
- IL: 0,
- IN: 0,
- IQ: 6,
- IR: 6,
- IS: 1,
- IT: 1,
- JM: 0,
- JO: 6,
- JP: 0,
- KE: 0,
- KG: 1,
- KH: 0,
- KR: 0,
- KW: 6,
- KZ: 1,
- LA: 0,
- LB: 1,
- LI: 1,
- LK: 1,
- LT: 1,
- LU: 1,
- LV: 1,
- LY: 6,
- MC: 1,
- MD: 1,
- ME: 1,
- MH: 0,
- MK: 1,
- MM: 0,
- MN: 1,
- MO: 0,
- MQ: 1,
- MT: 0,
- MV: 5,
- MX: 0,
- MY: 1,
- MZ: 0,
- NI: 0,
- NL: 1,
- NO: 1,
- NP: 0,
- NZ: 1,
- OM: 6,
- PA: 0,
- PE: 0,
- PH: 0,
- PK: 0,
- PL: 1,
- PR: 0,
- PT: 0,
- PY: 0,
- QA: 6,
- RE: 1,
- RO: 1,
- RS: 1,
- RU: 1,
- SA: 0,
- SD: 6,
- SE: 1,
- SG: 0,
- SI: 1,
- SK: 1,
- SM: 1,
- SV: 0,
- SY: 6,
- TH: 0,
- TJ: 1,
- TM: 1,
- TR: 1,
- TT: 0,
- TW: 0,
- UA: 1,
- UM: 0,
- US: 0,
- UY: 1,
- UZ: 1,
- VA: 1,
- VE: 0,
- VI: 0,
- VN: 1,
- WS: 0,
- XK: 1,
- YE: 0,
- ZA: 0,
- ZW: 0
- };
- function getWeekArray(date, locale, firstDayOfWeek) {
- const weeks = [];
- let currentWeek = [];
- const firstDayOfMonth = startOfMonth(date);
- const lastDayOfMonth = endOfMonth(date);
- const first = firstDayOfWeek ?? firstDay[locale.slice(-2).toUpperCase()] ?? 0;
- const firstDayWeekIndex = (firstDayOfMonth.getDay() - first + 7) % 7;
- const lastDayWeekIndex = (lastDayOfMonth.getDay() - first + 7) % 7;
- for (let i = 0; i < firstDayWeekIndex; i++) {
- const adjacentDay = new Date(firstDayOfMonth);
- adjacentDay.setDate(adjacentDay.getDate() - (firstDayWeekIndex - i));
- currentWeek.push(adjacentDay);
- }
- for (let i = 1; i <= lastDayOfMonth.getDate(); i++) {
- const day = new Date(date.getFullYear(), date.getMonth(), i);
- // Add the day to the current week
- currentWeek.push(day);
- // If the current week has 7 days, add it to the weeks array and start a new week
- if (currentWeek.length === 7) {
- weeks.push(currentWeek);
- currentWeek = [];
- }
- }
- for (let i = 1; i < 7 - lastDayWeekIndex; i++) {
- const adjacentDay = new Date(lastDayOfMonth);
- adjacentDay.setDate(adjacentDay.getDate() + i);
- currentWeek.push(adjacentDay);
- }
- if (currentWeek.length > 0) {
- weeks.push(currentWeek);
- }
- return weeks;
- }
- function startOfWeek(date, locale, firstDayOfWeek) {
- const day = firstDayOfWeek ?? firstDay[locale.slice(-2).toUpperCase()] ?? 0;
- const d = new Date(date);
- while (d.getDay() !== day) {
- d.setDate(d.getDate() - 1);
- }
- return d;
- }
- function endOfWeek(date, locale) {
- const d = new Date(date);
- const lastDay = ((firstDay[locale.slice(-2).toUpperCase()] ?? 0) + 6) % 7;
- while (d.getDay() !== lastDay) {
- d.setDate(d.getDate() + 1);
- }
- return d;
- }
- function startOfMonth(date) {
- return new Date(date.getFullYear(), date.getMonth(), 1);
- }
- function endOfMonth(date) {
- return new Date(date.getFullYear(), date.getMonth() + 1, 0);
- }
- function parseLocalDate(value) {
- const parts = value.split('-').map(Number);
- // new Date() uses local time zone when passing individual date component values
- return new Date(parts[0], parts[1] - 1, parts[2]);
- }
- const _YYYMMDD = /^([12]\d{3}-([1-9]|0[1-9]|1[0-2])-([1-9]|0[1-9]|[12]\d|3[01]))$/;
- function date(value) {
- if (value == null) return new Date();
- if (value instanceof Date) return value;
- if (typeof value === 'string') {
- let parsed;
- if (_YYYMMDD.test(value)) {
- return parseLocalDate(value);
- } else {
- parsed = Date.parse(value);
- }
- if (!isNaN(parsed)) return new Date(parsed);
- }
- return null;
- }
- const sundayJanuarySecond2000 = new Date(2000, 0, 2);
- function getWeekdays(locale, firstDayOfWeek) {
- const daysFromSunday = firstDayOfWeek ?? firstDay[locale.slice(-2).toUpperCase()] ?? 0;
- return createRange(7).map(i => {
- const weekday = new Date(sundayJanuarySecond2000);
- weekday.setDate(sundayJanuarySecond2000.getDate() + daysFromSunday + i);
- return new Intl.DateTimeFormat(locale, {
- weekday: 'narrow'
- }).format(weekday);
- });
- }
- function format(value, formatString, locale, formats) {
- const newDate = date(value) ?? new Date();
- const customFormat = formats?.[formatString];
- if (typeof customFormat === 'function') {
- return customFormat(newDate, formatString, locale);
- }
- let options = {};
- switch (formatString) {
- case 'fullDate':
- options = {
- year: 'numeric',
- month: 'long',
- day: 'numeric'
- };
- break;
- case 'fullDateWithWeekday':
- options = {
- weekday: 'long',
- year: 'numeric',
- month: 'long',
- day: 'numeric'
- };
- break;
- case 'normalDate':
- const day = newDate.getDate();
- const month = new Intl.DateTimeFormat(locale, {
- month: 'long'
- }).format(newDate);
- return `${day} ${month}`;
- case 'normalDateWithWeekday':
- options = {
- weekday: 'short',
- day: 'numeric',
- month: 'short'
- };
- break;
- case 'shortDate':
- options = {
- month: 'short',
- day: 'numeric'
- };
- break;
- case 'year':
- options = {
- year: 'numeric'
- };
- break;
- case 'month':
- options = {
- month: 'long'
- };
- break;
- case 'monthShort':
- options = {
- month: 'short'
- };
- break;
- case 'monthAndYear':
- options = {
- month: 'long',
- year: 'numeric'
- };
- break;
- case 'monthAndDate':
- options = {
- month: 'long',
- day: 'numeric'
- };
- break;
- case 'weekday':
- options = {
- weekday: 'long'
- };
- break;
- case 'weekdayShort':
- options = {
- weekday: 'short'
- };
- break;
- case 'dayOfMonth':
- return new Intl.NumberFormat(locale).format(newDate.getDate());
- case 'hours12h':
- options = {
- hour: 'numeric',
- hour12: true
- };
- break;
- case 'hours24h':
- options = {
- hour: 'numeric',
- hour12: false
- };
- break;
- case 'minutes':
- options = {
- minute: 'numeric'
- };
- break;
- case 'seconds':
- options = {
- second: 'numeric'
- };
- break;
- case 'fullTime':
- options = {
- hour: 'numeric',
- minute: 'numeric',
- second: 'numeric',
- hour12: true
- };
- break;
- case 'fullTime12h':
- options = {
- hour: 'numeric',
- minute: 'numeric',
- second: 'numeric',
- hour12: true
- };
- break;
- case 'fullTime24h':
- options = {
- hour: 'numeric',
- minute: 'numeric',
- second: 'numeric',
- hour12: false
- };
- break;
- case 'fullDateTime':
- options = {
- year: 'numeric',
- month: 'long',
- day: 'numeric',
- hour: 'numeric',
- minute: 'numeric',
- second: 'numeric',
- hour12: true
- };
- break;
- case 'fullDateTime12h':
- options = {
- year: 'numeric',
- month: 'long',
- day: 'numeric',
- hour: 'numeric',
- minute: 'numeric',
- second: 'numeric',
- hour12: true
- };
- break;
- case 'fullDateTime24h':
- options = {
- year: 'numeric',
- month: 'long',
- day: 'numeric',
- hour: 'numeric',
- minute: 'numeric',
- second: 'numeric',
- hour12: false
- };
- break;
- case 'keyboardDate':
- options = {
- year: 'numeric',
- month: '2-digit',
- day: '2-digit'
- };
- break;
- case 'keyboardDateTime':
- options = {
- year: 'numeric',
- month: '2-digit',
- day: '2-digit',
- hour: 'numeric',
- minute: 'numeric',
- second: 'numeric',
- hour12: false
- };
- break;
- case 'keyboardDateTime12h':
- options = {
- year: 'numeric',
- month: '2-digit',
- day: '2-digit',
- hour: 'numeric',
- minute: 'numeric',
- second: 'numeric',
- hour12: true
- };
- break;
- case 'keyboardDateTime24h':
- options = {
- year: 'numeric',
- month: '2-digit',
- day: '2-digit',
- hour: 'numeric',
- minute: 'numeric',
- second: 'numeric',
- hour12: false
- };
- break;
- default:
- options = customFormat ?? {
- timeZone: 'UTC',
- timeZoneName: 'short'
- };
- }
- return new Intl.DateTimeFormat(locale, options).format(newDate);
- }
- function toISO(adapter, value) {
- const date = adapter.toJsDate(value);
- const year = date.getFullYear();
- const month = padStart(String(date.getMonth() + 1), 2, '0');
- const day = padStart(String(date.getDate()), 2, '0');
- return `${year}-${month}-${day}`;
- }
- function parseISO(value) {
- const [year, month, day] = value.split('-').map(Number);
- return new Date(year, month - 1, day);
- }
- function addMinutes(date, amount) {
- const d = new Date(date);
- d.setMinutes(d.getMinutes() + amount);
- return d;
- }
- function addHours(date, amount) {
- const d = new Date(date);
- d.setHours(d.getHours() + amount);
- return d;
- }
- function addDays(date, amount) {
- const d = new Date(date);
- d.setDate(d.getDate() + amount);
- return d;
- }
- function addWeeks(date, amount) {
- const d = new Date(date);
- d.setDate(d.getDate() + amount * 7);
- return d;
- }
- function addMonths(date, amount) {
- const d = new Date(date);
- d.setDate(1);
- d.setMonth(d.getMonth() + amount);
- return d;
- }
- function getYear(date) {
- return date.getFullYear();
- }
- function getMonth(date) {
- return date.getMonth();
- }
- function getDate(date) {
- return date.getDate();
- }
- function getNextMonth(date) {
- return new Date(date.getFullYear(), date.getMonth() + 1, 1);
- }
- function getPreviousMonth(date) {
- return new Date(date.getFullYear(), date.getMonth() - 1, 1);
- }
- function getHours(date) {
- return date.getHours();
- }
- function getMinutes(date) {
- return date.getMinutes();
- }
- function startOfYear(date) {
- return new Date(date.getFullYear(), 0, 1);
- }
- function endOfYear(date) {
- return new Date(date.getFullYear(), 11, 31);
- }
- function isWithinRange(date, range) {
- return isAfter(date, range[0]) && isBefore(date, range[1]);
- }
- function isValid(date) {
- const d = new Date(date);
- return d instanceof Date && !isNaN(d.getTime());
- }
- function isAfter(date, comparing) {
- return date.getTime() > comparing.getTime();
- }
- function isAfterDay(date, comparing) {
- return isAfter(startOfDay(date), startOfDay(comparing));
- }
- function isBefore(date, comparing) {
- return date.getTime() < comparing.getTime();
- }
- function isEqual(date, comparing) {
- return date.getTime() === comparing.getTime();
- }
- function isSameDay(date, comparing) {
- return date.getDate() === comparing.getDate() && date.getMonth() === comparing.getMonth() && date.getFullYear() === comparing.getFullYear();
- }
- function isSameMonth(date, comparing) {
- return date.getMonth() === comparing.getMonth() && date.getFullYear() === comparing.getFullYear();
- }
- function isSameYear(date, comparing) {
- return date.getFullYear() === comparing.getFullYear();
- }
- function getDiff(date, comparing, unit) {
- const d = new Date(date);
- const c = new Date(comparing);
- switch (unit) {
- case 'years':
- return d.getFullYear() - c.getFullYear();
- case 'quarters':
- return Math.floor((d.getMonth() - c.getMonth() + (d.getFullYear() - c.getFullYear()) * 12) / 4);
- case 'months':
- return d.getMonth() - c.getMonth() + (d.getFullYear() - c.getFullYear()) * 12;
- case 'weeks':
- return Math.floor((d.getTime() - c.getTime()) / (1000 * 60 * 60 * 24 * 7));
- case 'days':
- return Math.floor((d.getTime() - c.getTime()) / (1000 * 60 * 60 * 24));
- case 'hours':
- return Math.floor((d.getTime() - c.getTime()) / (1000 * 60 * 60));
- case 'minutes':
- return Math.floor((d.getTime() - c.getTime()) / (1000 * 60));
- case 'seconds':
- return Math.floor((d.getTime() - c.getTime()) / 1000);
- default:
- {
- return d.getTime() - c.getTime();
- }
- }
- }
- function setHours(date, count) {
- const d = new Date(date);
- d.setHours(count);
- return d;
- }
- function setMinutes(date, count) {
- const d = new Date(date);
- d.setMinutes(count);
- return d;
- }
- function setMonth(date, count) {
- const d = new Date(date);
- d.setMonth(count);
- return d;
- }
- function setDate(date, day) {
- const d = new Date(date);
- d.setDate(day);
- return d;
- }
- function setYear(date, year) {
- const d = new Date(date);
- d.setFullYear(year);
- return d;
- }
- function startOfDay(date) {
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0);
- }
- function endOfDay(date) {
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999);
- }
- export class VuetifyDateAdapter {
- constructor(options) {
- this.locale = options.locale;
- this.formats = options.formats;
- }
- date(value) {
- return date(value);
- }
- toJsDate(date) {
- return date;
- }
- toISO(date) {
- return toISO(this, date);
- }
- parseISO(date) {
- return parseISO(date);
- }
- addMinutes(date, amount) {
- return addMinutes(date, amount);
- }
- addHours(date, amount) {
- return addHours(date, amount);
- }
- addDays(date, amount) {
- return addDays(date, amount);
- }
- addWeeks(date, amount) {
- return addWeeks(date, amount);
- }
- addMonths(date, amount) {
- return addMonths(date, amount);
- }
- getWeekArray(date, firstDayOfWeek) {
- return getWeekArray(date, this.locale, firstDayOfWeek ? Number(firstDayOfWeek) : undefined);
- }
- startOfWeek(date, firstDayOfWeek) {
- return startOfWeek(date, this.locale, firstDayOfWeek ? Number(firstDayOfWeek) : undefined);
- }
- endOfWeek(date) {
- return endOfWeek(date, this.locale);
- }
- startOfMonth(date) {
- return startOfMonth(date);
- }
- endOfMonth(date) {
- return endOfMonth(date);
- }
- format(date, formatString) {
- return format(date, formatString, this.locale, this.formats);
- }
- isEqual(date, comparing) {
- return isEqual(date, comparing);
- }
- isValid(date) {
- return isValid(date);
- }
- isWithinRange(date, range) {
- return isWithinRange(date, range);
- }
- isAfter(date, comparing) {
- return isAfter(date, comparing);
- }
- isAfterDay(date, comparing) {
- return isAfterDay(date, comparing);
- }
- isBefore(date, comparing) {
- return !isAfter(date, comparing) && !isEqual(date, comparing);
- }
- isSameDay(date, comparing) {
- return isSameDay(date, comparing);
- }
- isSameMonth(date, comparing) {
- return isSameMonth(date, comparing);
- }
- isSameYear(date, comparing) {
- return isSameYear(date, comparing);
- }
- setMinutes(date, count) {
- return setMinutes(date, count);
- }
- setHours(date, count) {
- return setHours(date, count);
- }
- setMonth(date, count) {
- return setMonth(date, count);
- }
- setDate(date, day) {
- return setDate(date, day);
- }
- setYear(date, year) {
- return setYear(date, year);
- }
- getDiff(date, comparing, unit) {
- return getDiff(date, comparing, unit);
- }
- getWeekdays(firstDayOfWeek) {
- return getWeekdays(this.locale, firstDayOfWeek ? Number(firstDayOfWeek) : undefined);
- }
- getYear(date) {
- return getYear(date);
- }
- getMonth(date) {
- return getMonth(date);
- }
- getDate(date) {
- return getDate(date);
- }
- getNextMonth(date) {
- return getNextMonth(date);
- }
- getPreviousMonth(date) {
- return getPreviousMonth(date);
- }
- getHours(date) {
- return getHours(date);
- }
- getMinutes(date) {
- return getMinutes(date);
- }
- startOfDay(date) {
- return startOfDay(date);
- }
- endOfDay(date) {
- return endOfDay(date);
- }
- startOfYear(date) {
- return startOfYear(date);
- }
- endOfYear(date) {
- return endOfYear(date);
- }
- }
- //# sourceMappingURL=vuetify.mjs.map
|