diff-ymd-package
Version:
A javascript library for calculating the difference between two dates in formatted ways like (aY bM cD)(aYears bMonths cDays) or customized desired formats like aY-bM-cD or aYears-bMonths-cDays or kDays or mWeeks or nMonths etc.
42 lines (36 loc) • 932 B
TypeScript
declare class DatesYMD {
constructor(
firstDate: string | number | Date,
secondDate: string | number | Date,
);
diffArray(): [number, number, number, string];
formattedYMD(): string;
customizeFormat(
yearUnit: string,
monthUnit: string,
dayUnit: string,
partSeparator: string,
): string;
diffInMonths(): number;
diffInWeeks(): number;
diffInDays(): number;
diffInYears(): number;
diffInHours(): number;
diffInMinutes(): number;
diffInSeconds(): number;
}
declare function diffDates(
firstDate: string | number | Date,
secondDate: string | number | Date,
): DatesYMD;
// Extend the global Date interface to add the `diff` method
declare global {
interface Date {
diff(secondDate: string | number | Date): DatesYMD;
}
}
// The hybrid CommonJS module export:
declare const diffYMDPackage: typeof DatesYMD & {
diffDates: typeof diffDates;
};
export = diffYMDPackage;