@tongziyang/uni-calendar-plugin
Version:
A comprehensive calendar plugin for uniapp with support for Gregorian and Lunar calendars, date selection, hotel booking, check-in functionality, and more.
148 lines (147 loc) • 4.27 kB
TypeScript
import { DateInfo } from '../types';
export interface DateOptions {
firstDayOfWeek?: number;
selectedDate?: Date | null;
rangeStart?: Date | null;
rangeEnd?: Date | null;
priceData?: Record<string, number>;
checkInData?: Record<string, boolean>;
disabledDate?: ((date: Date) => boolean) | null;
}
/**
* 格式化日期为字符串
* @param date 日期对象
* @param format 格式字符串
* @returns 格式化后的日期字符串
*/
export declare function formatDate(date: Date, format?: string): string;
/**
* 解析日期字符串为Date对象
* @param dateStr 日期字符串
* @returns Date对象
*/
export declare function parseDate(dateStr: string): Date;
/**
* 获取两个日期之间的天数
* @param start 开始日期
* @param end 结束日期
* @returns 天数
*/
export declare function getDaysBetween(start: Date, end: Date): number;
/**
* 判断两个日期是否是同一天
* @param date1 日期1
* @param date2 日期2
* @returns 是否同一天
*/
export declare function isSameDay(date1: Date | null, date2: Date | null): boolean;
/**
* 判断两个日期是否是同一个月
* @param date1 日期1
* @param date2 日期2
* @returns 是否同一个月
*/
export declare function isSameMonth(date1: Date | null, date2: Date | null): boolean;
/**
* 判断日期是否在日期范围内
* @param date 日期
* @param start 开始日期
* @param end 结束日期
* @returns 是否在范围内
*/
export declare function isDateInRange(date: Date, start: Date, end: Date): boolean;
/**
* 获取某月的第一天
* @param year 年
* @param month 月(0-11)
* @returns 第一天的Date对象
*/
export declare function getFirstDayOfMonth(year: number, month: number): Date;
/**
* 获取某月的最后一天
* @param year 年
* @param month 月(0-11)
* @returns 最后一天的Date对象
*/
export declare function getLastDayOfMonth(year: number, month: number): Date;
/**
* 获取某月的天数
* @param year 年
* @param month 月(0-11)
* @returns 天数
*/
export declare function getDaysInMonth(year: number, month: number): number;
/**
* 获取星期几的名称数组
* @param firstDayOfWeek 一周的第一天(0表示周日,1表示周一)
* @param abbreviated 是否使用缩写
* @returns 星期几的名称数组
*/
export declare function getWeekDayNames(firstDayOfWeek?: number, abbreviated?: boolean): string[];
/**
* 获取某个日期的详细信息
* @param date 日期
* @param options 选项
* @returns 日期信息
*/
export declare function getDayInfo(date: Date, options?: DateOptions): DateInfo;
/**
* 获取某月的所有日期信息
* @param year 年
* @param month 月(0-11)
* @param options 选项
* @returns 日期信息数组
*/
export declare function getMonthDays(year: number, month: number, options?: DateOptions): DateInfo[];
/**
* 获取某周的所有日期信息
* @param date 周内的某一天
* @param options 选项
* @returns 日期信息数组
*/
export declare function getWeekDays(date: Date, options?: DateOptions): DateInfo[];
/**
* 获取某年的所有月份信息
* @param year 年份
* @returns 月份信息数组
*/
export declare function getYearMonths(year: number): {
year: number;
month: number;
name: string;
}[];
/**
* 获取日期范围内的所有日期
* @param start 开始日期
* @param end 结束日期
* @returns 日期数组
*/
export declare function getDateRange(start: Date, end: Date): Date[];
/**
* 添加天数到日期
* @param date 日期
* @param days 天数
* @returns 新日期
*/
export declare function addDays(date: Date, days: number): Date;
/**
* 添加月数到日期
* @param date 日期
* @param months 月数
* @returns 新日期
*/
export declare function addMonths(date: Date, months: number): Date;
/**
* 添加年数到日期
* @param date 日期
* @param years 年数
* @returns 新日期
*/
export declare function addYears(date: Date, years: number): Date;
/**
* 获取日期是一年中的第几周
* @param date 日期
* @param firstDayOfWeek 一周的第一天(0表示周日,1表示周一)
* @returns 周数
*/
export declare function getWeekNumber(date: Date, firstDayOfWeek?: number): number;