UNPKG

sussy-util

Version:
161 lines (160 loc) 6.57 kB
declare class DateUtil { private static readonly instance; private static readonly monthAbrs; private static readonly mFullNames; private static readonly dayAbrs; private static readonly dFullNames; private constructor(); /** * Returns a new Date object with the current date and time. * @returns {Date} A new Date object with the current date and time. */ getCurrentDate(): Date; /** * Returns a new Date object with the time set to midnight. * @returns {Date} A Date object with the current date and time. */ today(): Date; /** * Returns a new Date object that is set to tomorrow's date. * @returns {Date} A date object that is the current date plus one day. */ tomorrow(): Date; /** * Returns a new Date object that is set to yesterday's date. * @returns {Date} A date object that is yesterday's date. */ yesterday(): Date; /** * Compares two dates and returns the difference between them in milliseconds. * @param {T | number | Date} dt1 - The first date. * @param {T | number | Date} dt2 - The second date. * @returns {number} The difference between the two dates in milliseconds. */ compareDates<T extends Date>(dt1: T | number | Date, dt2: T | number | Date): number; /** * Checks if two dates are equal. * @param {T | number | Date} dt1 - The first date. * @param {T | number | Date} dt2 - The second date. * @returns {boolean} True if the two dates are equal, false otherwise. */ equals<T extends Date>(dt1: T | number | Date, dt2: T | number | Date): boolean; /** * Returns the month abbreviation for the given month number (1-12). * @param {number} number - The month number (1-12). * @returns {string} The month abbreviation. */ getMonthAbbr(number: number): string; /** * Returns the full name of the month for the given month number (1-12). * @param {number} number - The month number (1-12). * @returns {string} The full name of the month. */ getMonthFullName(number: number): string; /** * Returns the day abbreviation for the given day number (0-6, where 0 is Sunday). * @param {number} number - The day number (0-6). * @returns {string} The day abbreviation. */ getDayAbbr(number: number): string; /** * Returns the full name of the day for the given day number (0-6, where 0 is Sunday). * @param {number} number - The day number (0-6). * @returns {string} The full name of the day. */ getDayFullName(number: number): string; /** * Checks if a given year is a leap year. * @param {number} year - The year. * @returns {boolean} True if the year is a leap year, false otherwise. */ isLeapYear(year: number): boolean; /** * It returns the first day of the week (Monday) based on the current date. * @returns The first day of the week. */ weekFirstDay(): Date; /** * It returns the last day of the week. * @returns The last day of the week. */ weekLastDay(): Date; /** * Returns an array of leap years between a start and end year (inclusive). * @param {number} startYear - The start year. * @param {number} endYear - The end year. * @returns {number[]} An array of leap years. */ leapYearsInRange(startYear: number, endYear: number): number[]; /** * Returns the first day of the current month. * @returns {Date} A Date object representing the first day of the current month. */ getMonthFirstDay(): Date; /** * Returns the last day of the current month. * @returns {Date} A Date object representing the last day of the current month. */ getMonthLastDay(): Date; /** * Converts the input to a Date object. * @param {T | number | Date} input - The input value. * @returns {Date} A Date object. */ toDate<T extends Date>(input: T | number): Date; /** * If date1 is before date2, return true, else return false. * @param {T | number | Date} date1 - T | number | Date * @param {T | number | Date} date2 - T | number | Date * @returns A boolean value. */ isAfter<T extends Date>(date1: T | number | Date, date2: T | number | Date): boolean; /** * If date1 is before date2, return true, else return false. * @param {number | Date} date1 - T | number | Date * @param {number | Date} date2 - T | number | Date * @returns A boolean value. */ isBefore<T extends Date>(date1: T | number | Date, date2: T | number | Date): boolean; /** * This function takes a number of years and returns the number of months in that number of years. * @param {number} years - number * @returns The number of months in the given number of years. */ yearsToMonths(years: number): number; /** * Checks if a given date falls on a weekend (Saturday or Sunday). * @param {T | number | Date} dt - The date to check. * @returns {boolean} True if the date falls on a weekend, false otherwise. */ isWeekend<T extends Date>(dt: T | number | Date): boolean; /** * Calculates the difference in days between two dates. * @param {T | number | Date} dt1 - The first date. * @param {T | number | Date} dt2 - The second date. * @returns {number} The difference in days between the two dates. */ getDaysDiff<T extends Date>(dt1: T | number | Date, dt2: T | number | Date): number; /** * Adds the specified number of days to a given date. * @param {T | number | Date} dt - The date to add days to. * @param {number} days - The number of days to add. * @returns {Date} The resulting date after adding the specified number of days. */ addDays<T extends Date>(dt: T | number | Date, days: number): Date; /** * Formats a given date object into a string representation using the specified format. * @param {number | Date} dt - The date object to format. * @param {string} format - The format string. (e.g., 'YYYY-MM-DD') * @returns {string} The formatted date string. */ formatDate<T extends Date>(dt: T | number | Date, format: string): string; /** * Returns the current timestamp in milliseconds. * @returns {number} The current timestamp in milliseconds. */ getCurrentTimestamp(): number; static getInstance(): DateUtil; } declare const _default: DateUtil; export default _default;