routie dev init since i didn't adhere to any proper guidance up until now

This commit is contained in:
2026-04-29 22:27:29 -06:00
commit e1dabb71e2
15301 changed files with 3562618 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
export interface DateAdapter<T = unknown> {
date(value?: any): T | null;
format(date: T, formatString: string): string;
toJsDate(value: T): Date;
parseISO(date: string): T;
toISO(date: T): string;
startOfDay(date: T): T;
endOfDay(date: T): T;
startOfWeek(date: T, firstDayOfWeek?: number | string): T;
endOfWeek(date: T): T;
startOfMonth(date: T): T;
endOfMonth(date: T): T;
startOfYear(date: T): T;
endOfYear(date: T): T;
isAfter(date: T, comparing: T): boolean;
isAfterDay(date: T, comparing: T): boolean;
isSameDay(date: T, comparing: T): boolean;
isSameMonth(date: T, comparing: T): boolean;
isSameYear(date: T, comparing: T): boolean;
isBefore(date: T, comparing: T): boolean;
isEqual(date: T, comparing: T): boolean;
isValid(date: any): boolean;
isWithinRange(date: T, range: [T, T]): boolean;
addMinutes(date: T, amount: number): T;
addHours(date: T, amount: number): T;
addDays(date: T, amount: number): T;
addWeeks(date: T, amount: number): T;
addMonths(date: T, amount: number): T;
getYear(date: T): number;
setYear(date: T, year: number): T;
getDiff(date: T, comparing: T | string, unit?: string): number;
getWeekArray(date: T, firstDayOfWeek?: number | string): T[][];
getWeekdays(firstDayOfWeek?: number | string, weekdayFormat?: 'long' | 'short' | 'narrow'): string[];
getWeek(date: T, firstDayOfWeek?: number | string, firstDayOfYear?: number | string): number;
getMonth(date: T): number;
setMonth(date: T, month: number): T;
getDate(date: T): number;
setDate(date: T, day: number): T;
getNextMonth(date: T): T;
getPreviousMonth(date: T): T;
getHours(date: T): number;
setHours(date: T, hours: number): T;
getMinutes(date: T): number;
setMinutes(date: T, minutes: number): T;
}
+2
View File
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=DateAdapter.js.map
@@ -0,0 +1 @@
{"version":3,"file":"DateAdapter.js","names":[],"sources":["../../../src/composables/date/DateAdapter.ts"],"sourcesContent":["export interface DateAdapter<T = unknown> {\n date (value?: any): T | null\n format (date: T, formatString: string): string\n toJsDate (value: T): Date\n parseISO (date: string): T\n toISO (date: T): string\n\n startOfDay (date: T): T\n endOfDay (date: T): T\n startOfWeek (date: T, firstDayOfWeek?: number | string): T\n endOfWeek (date: T): T\n startOfMonth (date: T): T\n endOfMonth (date: T): T\n startOfYear (date: T): T\n endOfYear (date: T): T\n\n isAfter (date: T, comparing: T): boolean\n isAfterDay(date: T, comparing: T): boolean\n\n isSameDay (date: T, comparing: T): boolean\n isSameMonth (date: T, comparing: T): boolean\n isSameYear(date: T, comparing: T): boolean\n\n isBefore (date: T, comparing: T): boolean\n isEqual (date: T, comparing: T): boolean\n isValid (date: any): boolean\n isWithinRange (date: T, range: [T, T]): boolean\n\n addMinutes (date: T, amount: number): T\n addHours (date: T, amount: number): T\n addDays (date: T, amount: number): T\n addWeeks (date: T, amount: number): T\n addMonths (date: T, amount: number): T\n\n getYear (date: T): number\n setYear (date: T, year: number): T\n getDiff (date: T, comparing: T | string, unit?: string): number\n getWeekArray (date: T, firstDayOfWeek?: number | string): T[][]\n getWeekdays (firstDayOfWeek?: number | string, weekdayFormat?: 'long' | 'short' | 'narrow'): string[]\n getWeek (date: T, firstDayOfWeek?: number | string, firstDayOfYear?: number | string): number\n getMonth (date: T): number\n setMonth (date: T, month: number): T\n getDate (date: T): number\n setDate (date: T, day: number): T\n getNextMonth (date: T): T\n getPreviousMonth(date: T): T\n\n getHours (date: T): number\n setHours (date: T, hours: number): T\n getMinutes (date: T): number\n setMinutes (date: T, minutes: number): T\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,54 @@
import { VuetifyDateAdapter } from './vuetify.js';
import type { DateAdapter } from '../index.js';
type CustomDateFormat = Intl.DateTimeFormatOptions | ((date: string, formatString: string, locale: string) => string);
export declare class StringDateAdapter implements DateAdapter<string> {
base: VuetifyDateAdapter;
constructor(options: {
locale: string;
formats?: Record<string, CustomDateFormat>;
});
addDays(date: string, amount: number): string;
addHours(date: string, amount: number): string;
addMinutes(date: string, amount: number): string;
addMonths(date: string, amount: number): string;
addWeeks(date: string, amount: number): string;
date(value?: any): string | null;
endOfDay(date: string): string;
endOfMonth(date: string): string;
endOfWeek(date: string): string;
endOfYear(date: string): string;
format(date: string, formatString: string): string;
getDate(date: string): number;
getDiff(date: string, comparing: string, unit?: string): number;
getHours(date: string): number;
getMinutes(date: string): number;
getMonth(date: string): number;
getWeek(date: string, firstDayOfWeek?: number | string, firstDayOfYear?: number | string): number;
getNextMonth(date: string): string;
getPreviousMonth(date: string): string;
getWeekArray(date: string, firstDayOfWeek?: number | string): string[][];
getWeekdays(firstDayOfWeek?: number | string, weekdayFormat?: 'long' | 'short' | 'narrow'): string[];
getYear(date: string): number;
isAfter(date: string, comparing: string): boolean;
isAfterDay(date: string, comparing: string): boolean;
isBefore(date: string, comparing: string): boolean;
isEqual(date: string, comparing: string): boolean;
isSameDay(date: string, comparing: string): boolean;
isSameMonth(date: string, comparing: string): boolean;
isSameYear(date: string, comparing: string): boolean;
isValid(date: any): boolean;
isWithinRange(date: string, range: [string, string]): boolean;
parseISO(date: string): string;
setDate(date: string, day: number): string;
setHours(date: string, hours: number): string;
setMinutes(date: string, minutes: number): string;
setMonth(date: string, month: number): string;
setYear(date: string, year: number): string;
startOfDay(date: string): string;
startOfMonth(date: string): string;
startOfWeek(date: string, firstDayOfWeek?: number | string): string;
startOfYear(date: string): string;
toISO(date: string): string;
toJsDate(value: string): Date;
}
+146
View File
@@ -0,0 +1,146 @@
// Composables
import { VuetifyDateAdapter } from "./vuetify.js"; // Types
export class StringDateAdapter {
constructor(options) {
this.base = new VuetifyDateAdapter({
locale: options.locale,
formats: options.formats && Object.fromEntries(Object.entries(options.formats).map(([k, v]) => {
return [k, typeof v === 'function' ? (date, ...args) => v(this.base.toISO(date), ...args) : v];
}))
});
}
addDays(date, amount) {
return this.base.toISO(this.base.addDays(this.base.date(date), amount));
}
addHours(date, amount) {
return this.base.toISO(this.base.addHours(this.base.date(date), amount));
}
addMinutes(date, amount) {
return this.base.toISO(this.base.addMinutes(this.base.date(date), amount));
}
addMonths(date, amount) {
return this.base.toISO(this.base.addMonths(this.base.date(date), amount));
}
addWeeks(date, amount) {
return this.base.toISO(this.base.addWeeks(this.base.date(date), amount));
}
date(value) {
return this.base.toISO(this.base.date(value));
}
endOfDay(date) {
return this.base.toISO(this.base.endOfDay(this.base.date(date)));
}
endOfMonth(date) {
return this.base.toISO(this.base.endOfMonth(this.base.date(date)));
}
endOfWeek(date) {
return this.base.toISO(this.base.endOfWeek(this.base.date(date)));
}
endOfYear(date) {
return this.base.toISO(this.base.endOfYear(this.base.date(date)));
}
format(date, formatString) {
return this.base.format(this.base.date(date), formatString);
}
getDate(date) {
return this.base.getDate(this.base.date(date));
}
getDiff(date, comparing, unit) {
return this.base.getDiff(this.base.date(date), comparing, unit);
}
getHours(date) {
return this.base.getHours(this.base.date(date));
}
getMinutes(date) {
return this.base.getMinutes(this.base.date(date));
}
getMonth(date) {
return this.base.getMonth(this.base.date(date));
}
getWeek(date, firstDayOfWeek, firstDayOfYear) {
return this.base.getWeek(this.base.date(date), firstDayOfWeek, firstDayOfYear);
}
getNextMonth(date) {
return this.base.toISO(this.base.getNextMonth(this.base.date(date)));
}
getPreviousMonth(date) {
return this.base.toISO(this.base.getPreviousMonth(this.base.date(date)));
}
getWeekArray(date, firstDayOfWeek) {
return this.base.getWeekArray(this.base.date(date), firstDayOfWeek).map(week => {
return week.map(day => {
return this.base.toISO(day);
});
});
}
getWeekdays(firstDayOfWeek, weekdayFormat) {
return this.base.getWeekdays(firstDayOfWeek, weekdayFormat);
}
getYear(date) {
return this.base.getYear(this.base.date(date));
}
isAfter(date, comparing) {
return this.base.isAfter(this.base.date(date), this.base.date(comparing));
}
isAfterDay(date, comparing) {
return this.base.isAfterDay(this.base.date(date), this.base.date(comparing));
}
isBefore(date, comparing) {
return this.base.isBefore(this.base.date(date), this.base.date(comparing));
}
isEqual(date, comparing) {
return this.base.isEqual(this.base.date(date), this.base.date(comparing));
}
isSameDay(date, comparing) {
return this.base.isSameDay(this.base.date(date), this.base.date(comparing));
}
isSameMonth(date, comparing) {
return this.base.isSameMonth(this.base.date(date), this.base.date(comparing));
}
isSameYear(date, comparing) {
return this.base.isSameYear(this.base.date(date), this.base.date(comparing));
}
isValid(date) {
return this.base.isValid(date);
}
isWithinRange(date, range) {
return this.base.isWithinRange(this.base.date(date), [this.base.date(range[0]), this.base.date(range[1])]);
}
parseISO(date) {
return this.base.toISO(this.base.parseISO(date));
}
setDate(date, day) {
return this.base.toISO(this.base.setDate(this.base.date(date), day));
}
setHours(date, hours) {
return this.base.toISO(this.base.setHours(this.base.date(date), hours));
}
setMinutes(date, minutes) {
return this.base.toISO(this.base.setMinutes(this.base.date(date), minutes));
}
setMonth(date, month) {
return this.base.toISO(this.base.setMonth(this.base.date(date), month));
}
setYear(date, year) {
return this.base.toISO(this.base.setYear(this.base.date(date), year));
}
startOfDay(date) {
return this.base.toISO(this.base.startOfDay(this.base.date(date)));
}
startOfMonth(date) {
return this.base.toISO(this.base.startOfMonth(this.base.date(date)));
}
startOfWeek(date, firstDayOfWeek) {
return this.base.toISO(this.base.startOfWeek(this.base.date(date), firstDayOfWeek));
}
startOfYear(date) {
return this.base.toISO(this.base.startOfYear(this.base.date(date)));
}
toISO(date) {
return this.base.toISO(this.base.date(date));
}
toJsDate(value) {
return this.base.date(value);
}
}
//# sourceMappingURL=string.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,54 @@
import type { DateAdapter } from '../DateAdapter.js';
type CustomDateFormat = Intl.DateTimeFormatOptions | ((date: Date, formatString: string, locale: string) => string);
export declare class VuetifyDateAdapter implements DateAdapter<Date> {
locale: string;
formats?: Record<string, CustomDateFormat>;
constructor(options: {
locale: string;
formats?: Record<string, CustomDateFormat>;
});
date(value?: any): Date | null;
toJsDate(date: Date): Date;
toISO(date: Date): string;
parseISO(date: string): Date;
addMinutes(date: Date, amount: number): Date;
addHours(date: Date, amount: number): Date;
addDays(date: Date, amount: number): Date;
addWeeks(date: Date, amount: number): Date;
addMonths(date: Date, amount: number): Date;
getWeekArray(date: Date, firstDayOfWeek?: number | string): Date[][];
startOfWeek(date: Date, firstDayOfWeek?: number | string): Date;
endOfWeek(date: Date): Date;
startOfMonth(date: Date): Date;
endOfMonth(date: Date): Date;
format(date: Date, formatString: string): string;
isEqual(date: Date, comparing: Date): boolean;
isValid(date: any): boolean;
isWithinRange(date: Date, range: [Date, Date]): boolean;
isAfter(date: Date, comparing: Date): boolean;
isAfterDay(date: Date, comparing: Date): boolean;
isBefore(date: Date, comparing: Date): boolean;
isSameDay(date: Date, comparing: Date): boolean;
isSameMonth(date: Date, comparing: Date): boolean;
isSameYear(date: Date, comparing: Date): boolean;
setMinutes(date: Date, count: number): Date;
setHours(date: Date, count: number): Date;
setMonth(date: Date, count: number): Date;
setDate(date: Date, day: number): Date;
setYear(date: Date, year: number): Date;
getDiff(date: Date, comparing: Date | string, unit?: string): number;
getWeekdays(firstDayOfWeek?: number | string, weekdayFormat?: 'long' | 'short' | 'narrow'): string[];
getYear(date: Date): number;
getMonth(date: Date): number;
getWeek(date: Date, firstDayOfWeek?: number | string, firstDayOfYear?: number | string): number;
getDate(date: Date): number;
getNextMonth(date: Date): Date;
getPreviousMonth(date: Date): Date;
getHours(date: Date): number;
getMinutes(date: Date): number;
startOfDay(date: Date): Date;
endOfDay(date: Date): Date;
startOfYear(date: Date): Date;
endOfYear(date: Date): Date;
}
+690
View File
@@ -0,0 +1,690 @@
// Utilities
import { consoleWarn, createRange, padStart } from "../../../util/index.js"; // Types
function weekInfo(locale) {
// https://simplelocalize.io/data/locales/
// then `new Intl.Locale(...).getWeekInfo()`
const code = locale.slice(-2).toUpperCase();
switch (true) {
case locale === 'GB-alt-variant':
{
return {
firstDay: 0,
firstWeekSize: 4
};
}
case locale === '001':
{
return {
firstDay: 1,
firstWeekSize: 1
};
}
case `AG AS BD BR BS BT BW BZ CA CO DM DO ET GT GU HK HN ID IL IN JM JP KE
KH KR LA MH MM MO MT MX MZ NI NP PA PE PH PK PR PY SA SG SV TH TT TW UM US
VE VI WS YE ZA ZW`.includes(code):
{
return {
firstDay: 0,
firstWeekSize: 1
};
}
case `AI AL AM AR AU AZ BA BM BN BY CL CM CN CR CY EC GE HR KG KZ LB LK LV
MD ME MK MN MY NZ RO RS SI TJ TM TR UA UY UZ VN XK`.includes(code):
{
return {
firstDay: 1,
firstWeekSize: 1
};
}
case `AD AN AT AX BE BG CH CZ DE DK EE ES FI FJ FO FR GB GF GP GR HU IE IS
IT LI LT LU MC MQ NL NO PL RE RU SE SK SM VA`.includes(code):
{
return {
firstDay: 1,
firstWeekSize: 4
};
}
case `AE AF BH DJ DZ EG IQ IR JO KW LY OM QA SD SY`.includes(code):
{
return {
firstDay: 6,
firstWeekSize: 1
};
}
case code === 'MV':
{
return {
firstDay: 5,
firstWeekSize: 1
};
}
case code === 'PT':
{
return {
firstDay: 0,
firstWeekSize: 4
};
}
default:
return null;
}
}
function getWeekArray(date, locale, firstDayOfWeek) {
const weeks = [];
let currentWeek = [];
const firstDayOfMonth = startOfMonth(date);
const lastDayOfMonth = endOfMonth(date);
const first = firstDayOfWeek ?? weekInfo(locale)?.firstDay ?? 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) {
let day = (firstDayOfWeek ?? weekInfo(locale)?.firstDay ?? 0) % 7;
// prevent infinite loop
if (![0, 1, 2, 3, 4, 5, 6].includes(day)) {
consoleWarn('Invalid firstDayOfWeek, expected discrete number in range [0-6]');
day = 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 = ((weekInfo(locale)?.firstDay ?? 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, weekdayFormat) {
const daysFromSunday = firstDayOfWeek ?? weekInfo(locale)?.firstDay ?? 0;
return createRange(7).map(i => {
const weekday = new Date(sundayJanuarySecond2000);
weekday.setDate(sundayJanuarySecond2000.getDate() + daysFromSunday + i);
return new Intl.DateTimeFormat(locale, {
weekday: weekdayFormat ?? '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: 'short',
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'
};
break;
case 'fullTime12h':
options = {
hour: 'numeric',
minute: 'numeric',
hour12: true
};
break;
case 'fullTime24h':
options = {
hour: 'numeric',
minute: 'numeric',
hour12: false
};
break;
case 'fullDateTime':
options = {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: 'numeric'
};
break;
case 'fullDateTime12h':
options = {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
hour12: true
};
break;
case 'fullDateTime24h':
options = {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: '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'
};
return new Intl.DateTimeFormat(locale, options).format(newDate).replace(/, /g, ' ');
case 'keyboardDateTime12h':
options = {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: 'numeric',
minute: 'numeric',
hour12: true
};
return new Intl.DateTimeFormat(locale, options).format(newDate).replace(/, /g, ' ');
case 'keyboardDateTime24h':
options = {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: 'numeric',
minute: 'numeric',
hour12: false
};
return new Intl.DateTimeFormat(locale, options).format(newDate).replace(/, /g, ' ');
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 getWeek(date, locale, firstDayOfWeek, firstDayOfYear) {
const weekInfoFromLocale = weekInfo(locale);
const weekStart = firstDayOfWeek ?? weekInfoFromLocale?.firstDay ?? 0;
const minWeekSize = weekInfoFromLocale?.firstWeekSize ?? 1;
return firstDayOfYear !== undefined ? calculateWeekWithFirstDayOfYear(date, locale, weekStart, firstDayOfYear) : calculateWeekWithMinWeekSize(date, locale, weekStart, minWeekSize);
}
function calculateWeekWithFirstDayOfYear(date, locale, weekStart, firstDayOfYear) {
const firstDayOfYearOffset = (7 + firstDayOfYear - weekStart) % 7;
const currentWeekStart = startOfWeek(date, locale, weekStart);
const currentWeekEnd = addDays(currentWeekStart, 6);
function yearStartWeekdayOffset(year) {
return (7 + new Date(year, 0, 1).getDay() - weekStart) % 7;
}
let year = getYear(currentWeekStart);
if (year < getYear(currentWeekEnd) && yearStartWeekdayOffset(year + 1) <= firstDayOfYearOffset) {
year++;
}
const yearStart = new Date(year, 0, 1);
const offset = yearStartWeekdayOffset(year);
const d1w1 = offset <= firstDayOfYearOffset ? addDays(yearStart, -offset) : addDays(yearStart, 7 - offset);
return 1 + getDiff(endOfDay(currentWeekStart), startOfDay(d1w1), 'weeks');
}
function calculateWeekWithMinWeekSize(date, locale, weekStart, minWeekSize) {
const currentWeekStart = startOfWeek(date, locale, weekStart);
const currentWeekEnd = addDays(startOfWeek(date, locale, weekStart), 6);
function firstWeekSize(year) {
const yearStart = new Date(year, 0, 1);
return 7 - getDiff(yearStart, startOfWeek(yearStart, locale, weekStart), 'days');
}
let year = getYear(currentWeekStart);
if (year < getYear(currentWeekEnd) && firstWeekSize(year + 1) >= minWeekSize) {
year++;
}
const yearStart = new Date(year, 0, 1);
const size = firstWeekSize(year);
const d1w1 = size >= minWeekSize ? addDays(yearStart, size - 7) : addDays(yearStart, size);
return 1 + getDiff(endOfDay(currentWeekStart), startOfDay(d1w1), 'weeks');
}
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 isEqual(date, range[0]) || isEqual(date, range[1]) || 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) {
const firstDay = firstDayOfWeek !== undefined ? Number(firstDayOfWeek) : undefined;
return getWeekArray(date, this.locale, firstDay);
}
startOfWeek(date, firstDayOfWeek) {
const firstDay = firstDayOfWeek !== undefined ? Number(firstDayOfWeek) : undefined;
return startOfWeek(date, this.locale, firstDay);
}
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, weekdayFormat) {
const firstDay = firstDayOfWeek !== undefined ? Number(firstDayOfWeek) : undefined;
return getWeekdays(this.locale, firstDay, weekdayFormat);
}
getYear(date) {
return getYear(date);
}
getMonth(date) {
return getMonth(date);
}
getWeek(date, firstDayOfWeek, firstDayOfYear) {
const firstDay = firstDayOfWeek !== undefined ? Number(firstDayOfWeek) : undefined;
const firstWeekStart = firstDayOfYear !== undefined ? Number(firstDayOfYear) : undefined;
return getWeek(date, this.locale, firstDay, firstWeekStart);
}
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.js.map
File diff suppressed because one or more lines are too long
+76
View File
@@ -0,0 +1,76 @@
import type { InjectionKey } from 'vue';
import type { DateAdapter } from './DateAdapter.js';
import type { LocaleInstance } from '../locale.js';
export interface DateInstance extends DateModule.InternalAdapter {
locale?: any;
}
/** Supports module augmentation to specify date adapter types */
export declare namespace DateModule {
interface Adapter {
}
export type InternalAdapter = {} extends Adapter ? DateAdapter : Adapter;
}
export type InternalDateOptions = {
adapter: (new (options: {
locale: any;
formats?: any;
}) => DateInstance) | DateInstance;
formats?: Record<string, any>;
locale: Record<string, any>;
};
export type DateOptions = Partial<InternalDateOptions>;
export declare const DateOptionsSymbol: InjectionKey<InternalDateOptions>;
export declare const DateAdapterSymbol: InjectionKey<DateInstance>;
export declare function createDate(options: DateOptions | undefined, locale: LocaleInstance): {
options: InternalDateOptions;
instance: {
date: (value?: any) => unknown;
format: (date: unknown, formatString: string) => string;
toJsDate: (value: unknown) => Date;
parseISO: (date: string) => unknown;
toISO: (date: unknown) => string;
startOfDay: (date: unknown) => unknown;
endOfDay: (date: unknown) => unknown;
startOfWeek: (date: unknown, firstDayOfWeek?: number | string) => unknown;
endOfWeek: (date: unknown) => unknown;
startOfMonth: (date: unknown) => unknown;
endOfMonth: (date: unknown) => unknown;
startOfYear: (date: unknown) => unknown;
endOfYear: (date: unknown) => unknown;
isAfter: (date: unknown, comparing: unknown) => boolean;
isAfterDay: (date: unknown, comparing: unknown) => boolean;
isSameDay: (date: unknown, comparing: unknown) => boolean;
isSameMonth: (date: unknown, comparing: unknown) => boolean;
isSameYear: (date: unknown, comparing: unknown) => boolean;
isBefore: (date: unknown, comparing: unknown) => boolean;
isEqual: (date: unknown, comparing: unknown) => boolean;
isValid: (date: any) => boolean;
isWithinRange: (date: unknown, range: [unknown, unknown]) => boolean;
addMinutes: (date: unknown, amount: number) => unknown;
addHours: (date: unknown, amount: number) => unknown;
addDays: (date: unknown, amount: number) => unknown;
addWeeks: (date: unknown, amount: number) => unknown;
addMonths: (date: unknown, amount: number) => unknown;
getYear: (date: unknown) => number;
setYear: (date: unknown, year: number) => unknown;
getDiff: (date: unknown, comparing: unknown, unit?: string) => number;
getWeekArray: (date: unknown, firstDayOfWeek?: number | string) => unknown[][];
getWeekdays: (firstDayOfWeek?: number | string, weekdayFormat?: 'long' | 'short' | 'narrow') => string[];
getWeek: (date: unknown, firstDayOfWeek?: number | string, firstDayOfYear?: number | string) => number;
getMonth: (date: unknown) => number;
setMonth: (date: unknown, month: number) => unknown;
getDate: (date: unknown) => number;
setDate: (date: unknown, day: number) => unknown;
getNextMonth: (date: unknown) => unknown;
getPreviousMonth: (date: unknown) => unknown;
getHours: (date: unknown) => number;
setHours: (date: unknown, hours: number) => unknown;
getMinutes: (date: unknown) => number;
setMinutes: (date: unknown, minutes: number) => unknown;
locale?: any;
};
};
export declare function createDateRange(adapter: DateInstance, start: unknown, stop?: unknown): unknown[];
export declare function daysDiff(adapter: DateInstance, start: unknown, stop?: unknown): number;
export declare function useDate(): DateInstance;
+98
View File
@@ -0,0 +1,98 @@
// Composables
import { useLocale } from "../locale.js"; // Utilities
import { inject, reactive, watch } from 'vue';
import { mergeDeep } from "../../util/index.js"; // Types
// Adapters
import { VuetifyDateAdapter } from "./adapters/vuetify.js";
/** Supports module augmentation to specify date adapter types */
export let DateModule;
export const DateOptionsSymbol = Symbol.for('vuetify:date-options');
export const DateAdapterSymbol = Symbol.for('vuetify:date-adapter');
export function createDate(options, locale) {
const _options = mergeDeep({
adapter: VuetifyDateAdapter,
locale: {
af: 'af-ZA',
// ar: '', # not the same value for all variants
bg: 'bg-BG',
ca: 'ca-ES',
ckb: '',
cs: 'cs-CZ',
de: 'de-DE',
el: 'el-GR',
en: 'en-US',
// es: '', # not the same value for all variants
et: 'et-EE',
fa: 'fa-IR',
fi: 'fi-FI',
// fr: '', #not the same value for all variants
hr: 'hr-HR',
hu: 'hu-HU',
he: 'he-IL',
id: 'id-ID',
it: 'it-IT',
ja: 'ja-JP',
ko: 'ko-KR',
lv: 'lv-LV',
lt: 'lt-LT',
nl: 'nl-NL',
no: 'no-NO',
pl: 'pl-PL',
pt: 'pt-PT',
ro: 'ro-RO',
ru: 'ru-RU',
sk: 'sk-SK',
sl: 'sl-SI',
srCyrl: 'sr-SP',
srLatn: 'sr-SP',
sv: 'sv-SE',
th: 'th-TH',
tr: 'tr-TR',
az: 'az-AZ',
uk: 'uk-UA',
vi: 'vi-VN',
zhHans: 'zh-CN',
zhHant: 'zh-TW'
}
}, options);
return {
options: _options,
instance: createInstance(_options, locale)
};
}
export function createDateRange(adapter, start, stop) {
const diff = daysDiff(adapter, start, stop);
const datesInRange = [start];
for (let i = 1; i < diff; i++) {
const nextDate = adapter.addDays(start, i);
datesInRange.push(nextDate);
}
if (stop) {
datesInRange.push(adapter.endOfDay(stop));
}
return datesInRange;
}
export function daysDiff(adapter, start, stop) {
const iso = [`${adapter.toISO(stop ?? start).split('T')[0]}T00:00:00Z`, `${adapter.toISO(start).split('T')[0]}T00:00:00Z`];
return typeof adapter.date() === 'string' ? adapter.getDiff(iso[0], iso[1], 'days') // for StringDateAdapter
: adapter.getDiff(adapter.date(iso[0]), adapter.date(iso[1]), 'days');
}
function createInstance(options, locale) {
const instance = reactive(typeof options.adapter === 'function'
// eslint-disable-next-line new-cap
? new options.adapter({
locale: options.locale[locale.current.value] ?? locale.current.value,
formats: options.formats
}) : options.adapter);
watch(locale.current, value => {
instance.locale = options.locale[value] ?? value ?? instance.locale;
});
return instance;
}
export function useDate() {
const options = inject(DateOptionsSymbol);
if (!options) throw new Error('[Vuetify] Could not find injected date options');
const locale = useLocale();
return createInstance(options, locale);
}
//# sourceMappingURL=date.js.map
File diff suppressed because one or more lines are too long
+4
View File
@@ -0,0 +1,4 @@
export { createDate, useDate, DateAdapterSymbol } from './date.js';
export type { DateAdapter } from './DateAdapter.js';
export type { DateOptions, DateInstance, DateModule } from './date.js';
export { VuetifyDateAdapter } from './adapters/vuetify.js';
+3
View File
@@ -0,0 +1,3 @@
export { createDate, useDate, DateAdapterSymbol } from "./date.js";
export { VuetifyDateAdapter } from "./adapters/vuetify.js";
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","names":["createDate","useDate","DateAdapterSymbol","VuetifyDateAdapter"],"sources":["../../../src/composables/date/index.ts"],"sourcesContent":["export { createDate, useDate, DateAdapterSymbol } from './date'\nexport type { DateAdapter } from './DateAdapter'\nexport type { DateOptions, DateInstance, DateModule } from './date'\nexport { VuetifyDateAdapter } from './adapters/vuetify'\n"],"mappings":"SAASA,UAAU,EAAEC,OAAO,EAAEC,iBAAiB;AAAA,SAGtCC,kBAAkB","ignoreList":[]}