UNPKG

@coreui/vue-pro

Version:

UI Components Library for Vue.js

263 lines (262 loc) 11.5 kB
import type { DisabledDate, SelectionTypes, ViewTypes } from './types'; export type BaseGroups = { year: string; month: string; day: string; }; export type WeekGroups = { year: string; week: string; }; export type MonthGroups = { year: string; month: string; }; export type YearGroups = { year: string; }; /** * Converts an ISO week string to a Date object representing the Monday of that week. * @param isoWeek - The ISO week string (e.g., "2023W05" or "2023w05"). * @returns The Date object for the Monday of the specified week. */ export declare const convertIsoWeekToDate: (isoWeek: string) => Date; /** * Converts a date string or Date object to a Date object based on selection type. * @param date - The date to convert. * @param selectionType - The type of selection ('day', 'week', 'month', 'year'). * @param locale - The locale to use for date parsing (for day parsing). * @param includeTime - Whether to include time parsing (for day parsing). * @returns The corresponding Date object or null if invalid. */ export declare const convertToDateObject: (date: Date | string, selectionType?: SelectionTypes, locale?: string, includeTime?: boolean) => Date | null; /** * Enhanced locale-aware date parsing function (replaces getLocalDateFromString). * @param dateString - The date string to parse. * @param locale - The locale to use for date format patterns. * @param includeTime - Whether to include time parsing. * @param selectionType - The selection type ('day', 'week', 'month', 'year'). * @returns A Date object if parsing succeeds, null if parsing fails. */ export declare const getLocalDateFromString: (dateString: string, locale?: string, includeTime?: boolean, selectionType?: SelectionTypes) => Date | null; /** * Creates groups from an array. * @param arr - The array to group. * @param numberOfGroups - Number of groups to create. * @returns An array of grouped arrays. */ export declare const createGroupsInArray: <T>(arr: T[], numberOfGroups: number) => T[][]; /** * Adjusts the calendar date based on order and view type. * @param calendarDate - The current calendar date. * @param order - The order to adjust by. * @param view - The current view type. * @returns The adjusted Date object. */ export declare const getCalendarDate: (calendarDate: Date, order: number, view: ViewTypes) => Date; /** * Formats a date based on the selection type. * @param date - The date to format. * @param selectionType - The type of selection ('day', 'week', 'month', 'year'). * @returns A formatted date string or the original Date object. */ export declare const getDateBySelectionType: (date: Date | null, selectionType: SelectionTypes) => string | Date | null; /** * Retrieves the first available date within a range that is not disabled. * @param startDate - Start date of the range. * @param endDate - End date of the range. * @param min - Minimum allowed date. * @param max - Maximum allowed date. * @param disabledDates - Criteria for disabled dates. * @returns The first available Date object or null if none found. */ export declare const getFirstAvailableDateInRange: (startDate: Date, endDate: Date, min?: Date | null, max?: Date | null, disabledDates?: DisabledDate | DisabledDate[]) => Date | null; /** * Retrieves an array of month names based on locale and format. * @param locale - The locale string (e.g., 'en-US'). * @param format - The format of the month names ('short' or 'long'). * @returns An array of month names. */ export declare const getMonthsNames: (locale: string, format?: "short" | "long") => string[]; /** * Retrieves an array of selectable dates from the given element. * @param element - The HTML element to search for selectable dates. * @param selector - The CSS selector used to identify selectable dates. Defaults to 'tr[tabindex="0"], td[tabindex="0"]'. * @returns An array of HTMLElements representing the selectable dates. */ export declare const getSelectableDates: (element: HTMLElement, selector?: string) => HTMLElement[]; /** * Generates an array of years centered around a given year. * @param year - The central year. * @param range - The number of years before and after the central year. * @returns An array of years. */ export declare const getYears: (year: number, range?: number) => number[]; /** * Calculates the ISO 8601 week number and year for a given date. * * In the ISO 8601 standard: * - Weeks start on Monday. * - The first week of the year is the one that contains January 4th. * - The year of the week may differ from the calendar year (e.g., Dec 29, 2025 is in ISO year 2026). * * @param {Date} date - The date for which to calculate the ISO week number and year. * @returns {{ weekNumber: number, year: number }} An object containing: * - `weekNumber`: the ISO week number (1–53), * - `year`: the ISO year (may differ from the calendar year of the date). */ export declare const getISOWeekNumberAndYear: (date: Date) => { weekNumber: number; year: number; }; /** * Retrieves detailed information about each week in a month for calendar rendering. * @param year - The year. * @param month - The month (0-11). * @param firstDayOfWeek - The first day of the week (0-6, where 0 is Sunday). * @returns An array of week objects containing week numbers and day details. */ export declare const getMonthDetails: (year: number, month: number, firstDayOfWeek: number) => { week: { number: number; year: number; }; days: { date: Date; month: string; }[]; }[]; /** * Checks if a date is disabled based on the 'date' period type. * @param date - The date to check. * @param min - Minimum allowed date. * @param max - Maximum allowed date. * @param disabledDates - Criteria for disabled dates. * @returns True if the date is disabled, false otherwise. */ export declare const isDateDisabled: (date: Date, min?: Date | null, max?: Date | null, disabledDates?: DisabledDate | DisabledDate[]) => boolean; /** * Checks if a date is within a specified range. * @param date - The date to check. * @param start - Start date of the range. * @param end - End date of the range. * @returns True if the date is within the range, false otherwise. */ export declare const isDateInRange: (date: Date, start: Date | null, end: Date | null) => boolean; /** * Checks if a date is selected based on start and end dates. * @param date - The date to check. * @param start - Start date. * @param end - End date. * @returns True if the date is selected, false otherwise. */ export declare const isDateSelected: (date: Date, start: Date | null, end: Date | null) => boolean; /** * Determines if any date within a range is disabled. * @param startDate - Start date of the range. * @param endDate - End date of the range. * @param disabledDates - Criteria for disabled dates. * @returns True if any date in the range is disabled, false otherwise. */ export declare const isDisableDateInRange: (startDate?: Date | null, endDate?: Date | null, disabledDates?: DisabledDate | DisabledDate[]) => boolean; /** * Checks if a month is disabled based on the 'month' period type. * @param date - The date representing the month to check. * @param min - Minimum allowed date. * @param max - Maximum allowed date. * @param disabledDates - Criteria for disabled dates. * @returns True if the month is disabled, false otherwise. */ export declare const isMonthDisabled: (date: Date, min?: Date | null, max?: Date | null, disabledDates?: DisabledDate | DisabledDate[]) => boolean; /** * Checks if a month is selected based on start and end dates. * @param date - The date representing the month. * @param start - Start date. * @param end - End date. * @returns True if the month is selected, false otherwise. */ export declare const isMonthSelected: (date: Date, start: Date | null, end: Date | null) => boolean; /** * Checks if a month is within a specified range. * @param date - The date representing the month. * @param start - Start date. * @param end - End date. * @returns True if the month is within the range, false otherwise. */ export declare const isMonthInRange: (date: Date, start: Date | null, end: Date | null) => boolean; /** * Checks if two dates are the same calendar date. * @param date - First date. * @param date2 - Second date. * @returns True if both dates are the same, false otherwise. */ export declare const isSameDateAs: (date: Date | null, date2: Date | null) => boolean; /** * Checks if a date is today. * @param date - The date to check. * @returns True if the date is today, false otherwise. */ export declare const isToday: (date: Date) => boolean; /** * Checks if a year is disabled based on the 'year' period type. * @param date - The date representing the year to check. * @param min - Minimum allowed date. * @param max - Maximum allowed date. * @param disabledDates - Criteria for disabled dates. * @returns True if the year is disabled, false otherwise. */ export declare const isYearDisabled: (date: Date, min?: Date | null, max?: Date | null, disabledDates?: DisabledDate | DisabledDate[]) => boolean; /** * Checks if a year is selected based on start and end dates. * @param date - The date representing the year. * @param start - Start date. * @param end - End date. * @returns True if the year matches the start's or end's year, false otherwise. */ export declare const isYearSelected: (date: Date, start: Date | null, end: Date | null) => boolean; /** * Checks if a year is within a specified range. * @param date - The date representing the year. * @param start - Start date. * @param end - End date. * @returns True if the year's value lies between start's year and end's year, false otherwise. */ export declare const isYearInRange: (date: Date, start: Date | null, end: Date | null) => boolean; /** * Removes the time component from a Date object. * @param date - The original date. * @returns A new Date object with the time set to 00:00:00. */ export declare const removeTimeFromDate: (date: Date) => Date; /** * Copies the time (hours, minutes, seconds, milliseconds) from one Date to another. * * @param {Date} target - The date whose time will be updated. * @param {Date | null} source - The date to copy the time from. * @returns {Date} A new Date instance with the date from `target` and time from `source`. */ export declare const setTimeFromDate: (target: Date | null, source: Date | null) => Date | null; /** * Parses a year string with smart 2-digit handling. * @param yearString - The year string to parse. * @returns The parsed year as a number with intelligent century assignment. */ export declare const parseYearSmart: (yearString: string) => number; /** * Creates a date from year groups. * @param groups - The year groups containing year string. * @returns A Date object for January 1st of the year. */ export declare const createDateFromYear: (groups: YearGroups) => Date; /** * Creates a date from month groups. * @param groups - The month groups containing year and month strings. * @returns A Date object for the first day of the month. */ export declare const createDateFromMonth: (groups: MonthGroups) => Date; /** * Creates a date from week groups. * @param groups - The week groups containing year and week strings. * @returns A Date object for the Monday of the specified week. */ export declare const createDateFromWeek: (groups: WeekGroups) => Date;