UNPKG

@cainiaofe/cn-ui-m

Version:
86 lines (85 loc) 3.13 kB
import * as cnUtils from '@cainiaofe/cn-utils'; import { TLanguage } from '@cainiaofe/cn-i18n'; import { dayjs } from './dayjs'; export declare function isInvalidValue(val: any): boolean; type IntervalMode = '()' | '[]' | '[)' | '(]'; export type AvailableDate = Date | string | dayjs.Dayjs | number; export declare function formatDate(d: AvailableDate, format: string, invalidStr?: string): string; export declare function isValidDate(obj?: Date): obj is Date; export declare function toValidDate(from?: AvailableDate, defaultDate?: Date): Date; export declare function toDate(from?: AvailableDate): Date; /** * 日期是否在指定区间 * @param date * @param startDate * @param endDate * @param unit * @param intervalMode */ export declare function isBetween(date: dayjs.ConfigType, startDate: dayjs.ConfigType, endDate: dayjs.ConfigType, unit?: dayjs.OpUnitType, intervalMode?: IntervalMode): boolean; export declare function toDay(from: AvailableDate): dayjs.Dayjs; export declare function cloneDate(d: Date): Date; type DateNumType = 'y' | 'm' | 'd' | 'h' | 'i' | 's'; export declare function getDateNum(type: DateNumType, d: Date): number; export declare function isTypeSame(type: DateNumType, d1: Date, d2: Date): boolean; export declare enum RANGE_CHECK_RESULT { IN_RANGE = 0, SMALL_THAN_HOUR = 1, BIGGER_THAN_HOUR = 2, SMALL_THAN_MIN = 3, BIGGER_THAN_MIN = 4, SMALL_THAN_SEC = 5, BIGGER_THAN_SEC = 6, SMALL_THAN_YEAR = 7, BIGGER_THAN_YEAR = 8, SMALL_THAN_MONTH = 9, BIGGER_THAN_MONTH = 10, SMALL_THAN_DAY = 11, BIGGER_THAN_DAY = 12 } export interface TimeOptions { hasHour?: boolean; hasMinute?: boolean; hasSecond?: boolean; } export interface DateCheckOptions { date?: { hasYear: boolean; hasMonth: boolean; hasDay: boolean; }; time?: TimeOptions; } /** * 检查某个日期 d 是否在 validRange 范围中 * 这里的 bigger/smaller,都指的是范围的最大(小)值比日期 d 大/小 * @param d 待检查的日期 * @param options 选项,具体检查哪些内容 * @param validRange 预期范围 */ export declare function checkDateRange(d: Date, options: DateCheckOptions, validRange?: [Date, Date]): RANGE_CHECK_RESULT; /** * 获取在范围内最接近 d 的日期 * @param d 原始日期 * @param options 检查选项 * @param validRange 范围 */ export declare function getRangeDate(d: Date, options: DateCheckOptions, validRange?: [Date, Date]): Date; interface TimeExtraOptions { hourStep?: number; minuteStep?: number; secondStep?: number; } export declare function getNearestDate(options: TimeOptions, extra: TimeExtraOptions, d: Date, calcType: 'auto' | 'plus' | 'minus'): Date; export declare function getRealRange(options: TimeOptions, extra: TimeExtraOptions, validRange?: [Date, Date]): [Date, Date] | undefined; export declare const getDateFormatConf: (adapterLocale?: boolean | TLanguage) => cnUtils.DateFormatConf | { D: string; W: string; M: string; Q: string; Y: string; H: string; m: string; s: string; }; export {};