@sheetxl/models
Version:
Models - A Headless javascript spreadsheet library.
99 lines • 4.06 kB
TypeScript
/**
* Test if a type is a date
* @remarks
* Dates across frame boundaries loose instanceof and new Date('test') is an invalid date.
* @param Values across frame boundary
* @returns
*/
export declare const isValidDate: (d: any) => boolean;
export declare const dayDiff: (d1: Date, d2: Date) => number;
export declare const monthDiff: (startDate: Date, endDate: Date) => number;
export declare const yearDiff: (d1: Date, d2: Date) => number;
export declare const dateUnitDiff: (d1: Date, d2: Date, unit: string) => number;
export declare enum DateUnit {
day = "d",
month = "m",
year = "y"
}
export declare const addDateUnit: (date: Date, count: number, unit: string) => Date;
export declare const stringToLocalDate: (value: string | String) => Date;
export declare const isISODateString: (value: string | String) => boolean;
export declare const toUTCDate: (utc: Date) => Date;
export declare const toLocalDate: (utc: Date) => Date;
export declare const toISODateString: (date: Date) => string;
export declare const toMidnight: (date: Date | number) => Date;
export declare const today: () => Date;
export declare const largestDateUnit: (datesOrig: Date[], sorted?: boolean, _date1904?: boolean) => DateUnit;
/**
* Returns the time as a string
*
* @param precision the precision of time. Set to 1 if exact
* @defaultValue - to the nearest minute
*/
export declare const nowAsTimeString: (date1904?: boolean, precision?: number) => string;
/**
* Returns the date as a string
*
* @param precision the precision of time. Set to 1 if exact
* @defaultValue - to the nearest minute
*/
export declare const nowAsDateString: (date1904?: boolean, precision?: number) => string;
export interface ParsedDateTime {
/** year */
year: number;
/** month. 1 based. 1 = Jan, 12 = Dec */
month: number;
/** day of month. 1 based */
day: number;
/** hour. a 24 hour clock */
hour: number;
/** minute. a 0 based */
minute: number;
/** second. 0 based */
second: number;
/** second. 0 based */
millis: number;
/** second. 1 based from Monday. 1 = Mon, 2 = Tue, ..., 7 = Sun */
dow: number;
/** date component without the time */
/** data and time component */
oaDateTime: number;
}
export declare const parseOADate: (oaDate: number, date1904?: boolean) => ParsedDateTime;
/**
* Note - This function currently only supports the leap year bug for hours.
*/
export declare const oaDateFromParsed: (parsed: ParsedDateTime, date1904?: boolean) => number;
export declare const fromOADate: (oaDate: number, date1904?: boolean) => Date;
/**
* Encode date to oa date (ole automation, used by Excel)
* @param {Date} date
* @param {boolean} [date1904] Whether to use the 1904 Date System. See https://bettersolutions.com/excel/dates-times/1904-date-system.htm
*
* http://markitondemand.github.io/moment-msdate/
*
* https://docs.microsoft.com/en-US/office/troubleshoot/excel/wrongly-assumes-1900-is-leap-year
* https://docs.microsoft.com/en-us/dotnet/api/system.datetime.tooadate?redirectedfrom=MSDN&view=net-5.0#System_DateTime_ToOADate
* https://bettersolutions.com/excel/dates-times/1904-date-system.htm
*/
export declare const toOADate: (date: Date, date1904?: boolean) => number;
export interface DateNumberInput {
numberFormat: string;
asOADate: number;
asJSDate: Date;
}
export interface ParsedDateTimeInput {
numberFormat: string;
parsed: Partial<ParsedDateTime>;
leadingText: string;
}
export declare const parseAsTimeInput: (strValue: string, date1904?: boolean, allowLeadingText?: boolean) => ParsedDateTimeInput | null;
/**
* Will return a DateNumberInput or null
* @param strValue
* @returns DateNumberInput is parsable as a date or null if not
*/
export declare const parseAsDateInput: (strValue: string, date1904?: boolean, currentTime?: number) => DateNumberInput | null;
export declare function isDateFormatter(fmt: string): boolean;
export declare function isTimeFormatter(fmt: string): boolean;
//# sourceMappingURL=DateUtils.d.ts.map