type DateLike = Date | number | string; export type { DateLike, }; /** * Defines an abstract class with date utilities. */ export declare abstract class Dates { /** * Contains the number of days in a year. */ static readonly DAYS_IN_YEAR: number; /** * Contains the maximal number of milliseconds allowed. */ static readonly MAX_ALLOWED_TIME: number; /** * Contains the number of minutes in a day. */ static readonly MINS_IN_DAY: number; /** * Contains the number of minutes in an hour. */ static readonly MINS_IN_HOUR: number; /** * Contains the number of minutes in a month. */ static readonly MINS_IN_MONTH: number; /** * Contains the number of minutes in a year. */ static readonly MINS_IN_YEAR: number; /** * Contains the number of milliseconds in a day. */ static readonly MS_IN_DAY: number; /** * Contains the number of milliseconds in an hour. */ static readonly MS_IN_HOUR: number; /** * Contains the number of milliseconds in a minute. */ static readonly MS_IN_MINUTE: number; /** * Contains the number of milliseconds in a second. */ static readonly MS_IN_SECOND: number; /** * Contains the number of milliseconds in a week. */ static readonly MS_IN_WEEK: number; /** * Contains the number of seconds in a day. */ static readonly SECS_IN_DAY: number; /** * Contains the number of seconds in a month. */ static readonly SECS_IN_MONTH: number; /** * Contains the number of seconds in a week. */ static readonly SECS_IN_WEEK: number; /** * Contains the number of seconds in a year. */ static readonly SECS_IN_YEAR: number; /** * @constructor * * @private */ private constructor(); /** * Adds the specified number of days to the specified date object, an ISO 8601 * date string or the milliseconds from midnight, January 1, 1970 UTC. * * @param {Date} date Contains a date object, an ISO 8601 date string or the * milliseconds from midnight, January 1, 1970 UTC. * @param {Number} days Contains the number of days to add to the specified * date. * @return {Date} a date object. */ static addDays(date: DateLike, days: number): Date; /** * Adds the specified number of milliseconds to the specified date object. * * @param {Date} date Contains a date object, an ISO 8601 date string or the * milliseconds from midnight, January 1, 1970 UTC. * @param {Number} milliseconds Contains the number of milliseconds to add * to the specified date. * @return {Date} a date object. */ static addMilliseconds(date: DateLike, milliseconds: number): Date; /** * Adds the specified number of minutes to the given date. * * @param {Date} date Contains a date object, an ISO 8601 date * string or the milliseconds from midnight, January 1, 1970 UTC. * @param {Number} minutes Contains the number of minutes to add * to the specified date. * @return {Date} a date object. */ static addMinutes(date: DateLike, minutes: number): Date; /** * Adds the specified number of months to the given date. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Number} months Contains the number of months to add to the * specified date. * @return {Date} a date object. */ static addMonths(date: DateLike, months: number): Date; /** * Adds the specified number of seconds to the given date object. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Number} seconds Contains the number of seconds to add to * the specified date. * @return {Date} a date object. */ static addSeconds(date: DateLike, seconds: number): Date; /** * Adds the specified number of weeks to the given date. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Number} weeks Contains the number of weeks to add to the * specified date. * @return {Date} a date object. */ static addWeeks(date: DateLike, weeks: number): Date; /** * Adds the specified number of years to the given date object. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Number} years Contains the number of years to add to the * specified date. * @return {Date} a date object. */ static addYears(date: DateLike, years: number): Date; /** * Gets the start of the day i. e. the midnight date. * * **Usage Examples:** * ```typescript * const date = new Date("2023-05-06T11:59:04.623Z"); * const midnight = Dates.atStartOfDay(date); // "2023-05-06T00:00:00.000Z" * ``` * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. If this is not * defined the midnight date of the current date is used. * @return {Date} a date object. */ static atStartOfDay(date?: string | number | Date): Date; /** * Clones a date object. * * @param {Date} date Contains some date object. * @return {Date} a cloned copy of the given date object. */ static clone(date: Date): Date; /** * Compares two date objects. Useful for array sorting. * * @param {Date} a Contains some date object. * @param {Date} b Contains some other date object. * @return {Number} * * `-1` if `a` is before than `b`. * * `0` if `a` equals `b`. * * `1` if `a` is after than `b`. */ static compare(a: Date, b: Date): number; /** * Gets the current week number. * * @since `v2.1.1` */ static get currentWeek(): number; /** * Gets the date part of the date object i. e. the time is zeroed. * * @param {*} date Contains some date object, the milliseconds from * midnight, January 1, 1970 UTC or an ISO 8601 date string. * @return {Date} only the date part of the date object i. e. the time * is zeroed. * * @see `Dates.atStartOfDay()` */ static dateOnly(date: DateLike): Date; /** * Gets the days difference between the two dates. * * _Note:_ The time of the day object is not taken into account from this * method. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Date} other Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Boolean} round Contains whether to round the days difference. * Defaults to `false`. * @return {Number} the days difference between the two dates. */ static daysDifference(date: DateLike, other: DateLike, round?: boolean): number; /** * Gets the number of days in the specified month of the specified year. * * @param {Number} month Contains the month index. The indexes start from * 1 (January). * @param {Number} year Contains the year. * @return {Number} the number of days in the given month of the given year. */ static daysOfMonth(month: number, year: number): number; /** * Checks whether the two date objects are equal. * * @param {*} a Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {*} b Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Boolean} ignoreTime Contains whether to ignore the time part * of both date objects during the comparison. * @return {Boolean} whether the two date objects are equal. */ static equals(a: DateLike, b: DateLike, ignoreTime?: boolean): boolean; /** * Gets the first day of the specified week of the specified year. * * @param {Number} year Contains the year number. * @param {Number} weekNo Contains the week number. * * @return {Date} the first day of the specified week of the specified year. * * @since `v2.1.1` */ static firstDayOfWeek(year: number, weekNo: number): Date; /** * Gets the Standard Time timezone offset. * * @param {DateLike} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @return {Number} the standard timezone offset. * * @since `v2.1.1` */ static getStdTimezoneOffset(date: DateLike): number; /** * Returns the number of ms between midnight, January 1, 1970 Universal * Coordinated Time a. k. a. GMT and the given date. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds between midnight, January 1, 1970 UTC and the * specified date. * @return {Number} the number of ms between midnight, January 1, 1970 * Universal Coordinated Time a. k. a. GMT and the given date. */ static getUTC(date: DateLike): number; /** * Gets the ISO week number of the specified date. * * **Usage Examples:** * ```typescript * Dates.getWeek("2023-05-05T11:13:27.000Z"); // 18 * Dates.getWeek("2024-01-01T11:13:27.000Z"); // 1 * Dates.getWeek("2023-10-03T11:13:27.000Z"); // 40 * ``` * * @param {DateLike} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @return {Number} the ISO week number. */ static getWeek(date: DateLike): number; /** * Gets the difference in hours between the two specified dates. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Date} other Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Boolean} round Contains whether to round the hours difference. * Defaults to `false`. * @return {Number} the difference in hours between the two specified dates. */ static hoursDifference(date: DateLike, other: DateLike, round?: boolean): number; /** * Checks whether the first date is after the second one. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Date} other Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Boolean} ignoreTime Contains whether to ignore the time part * of both date objects during the comparison. * @return {Boolean} whether the first date is after the second one. */ static isAfter(date: DateLike, other: DateLike, ignoreTime?: boolean): boolean; /** * Checks whether the first date is before the second one. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Date} other Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Boolean} ignoreTime Contains whether to ignore the time part * of both date objects during the comparison. * @return {Boolean} whether the first date is before the second one. */ static isBefore(date: DateLike, other: DateLike, ignoreTime?: boolean): boolean; /** * Checks whether the given date is between the given date range. * * @param {Date} date Contains some date object. * @param {Date} from Contains the lower date. * @param {Date} to Contains the upper date. * @param {String} incl Contains the inclusivity type of the dates range. * - `(]`: Not including the date `from` but including the date `to`. * - `()`: Not including the dates `from` and `to`. * - `[]`: Including the dates `from` and `to`. * - `[)`: Including only the date `from` but not the date `to`. * @return {Boolean} whether the given date is between the given date range. */ static isBetween(date: DateLike, from: DateLike, to: DateLike, incl?: '(]' | '()' | '[]' | '[)'): boolean; /** * Checks whether the given value is a date object. * **Note:** This method simply checks whether the given value * is a date object, it doesn't check whether it represents a * valid date object. In order to check for date validity use * the @see `Dates.isValid(date)` method. * * **Example** * ```typescript * Dates.isDateObject(new Date('I am not valid')); // true * Dates.isDateObject(new Date()); // true * ``` * * @param {*} value Contains some value. * @return {Boolean} whether the given value is a date object. */ static isDateObject(value?: any): value is Date; /** * Checks whether the specified date belongs to the Daylight Saving * Time (DST). * * @param {DateLike} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @return {Boolean} whether the specified date belongs to the Daylight * Saving Time (DST). * * @since `v2.1.1` */ static isDST(date: DateLike): boolean; /** * Checks whether the given date is in the future. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Boolean} ignoreTime Contains whether to ignore the time part * of both date objects during the comparison. * @return {Boolean} whether the given date is in the future. */ static isFuture(date: DateLike, ignoreTime?: boolean): boolean; /** * Checks whether the specified string is a valid UTC ISO 8601 date string * which has the format `YYYY-MM-DDTHH:mm:ss.sssZ`. * * **Usage Examples:** * ```typescript * Dates.isISOString('2023-11-11T23:15:22.999Z'); // true * Dates.isISOString('2023-13-11T23:15:22.999Z'); // false * ``` * * @param {String} str Contains some string. * @return {Boolean} whether the specified string is a valid ISO 8601 * date string. */ static isISOString(str?: string): str is string; /** * Checks whether the given value is a date object and is valid i. e. * it represents a valid date. * * @param {Date} date Contains some date object. * @return {Boolean} whether the given value is a valid date object. */ static isValid(date: Date): boolean; /** * Gets the difference in milliseconds between the two specified dates. * * @param {*} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {*} other Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @return {Number} the difference in milliseconds between the two * specified dates. */ static millisecondsDifference(date: DateLike, other: DateLike): number; /** * Gets the difference in minutes between the two specified dates. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Date} other Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Boolean} round Contains whether to round the minutes difference. * Defaults to `false`. * @return {Number} the difference in minutes between the two specified dates. */ static minutesDifference(date: DateLike, other: DateLike, round?: boolean): number; /** * Gets the difference in months between the two specified dates. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Date} other Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @return {Number} the difference in months between the two specified dates. */ static monthsDifference(date: DateLike, other: DateLike): number; /** * Gets the local date and time now. */ static get now(): Date; /** * Parses a value as a date. * * @param {*} value Contains some value. * @return {Date} a date object in case the given value represents * a valid date; otherwise `null`. */ static parse(value?: any): Date | null; /** * Removes the given number of days from the specified date. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Number} days Contains the number of days to remove. * @return {Date} a date object. */ static removeDays(date: DateLike, days: number): Date; /** * Removes the given number of milliseconds from the specified date. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Number} milliseconds Contains the number of milliseconds to remove. * @return {Date} a date object. * * @since `v2.1.1` */ static removeMilliseconds(date: DateLike, milliseconds: number): Date; /** * Removes the given number of minutes from the specified date. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Number} minutes Contains the number of minutes to remove. * @return {Date} a date object. * * @since `v2.1.1` */ static removeMinutes(date: DateLike, minutes: number): Date; /** * Removes the given number of months from the specified date. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Number} months Contains the number of months to remove. * @return {Date} a date object. * * @since `v2.1.1` */ static removeMonths(date: DateLike, months: number): Date; /** * Removes the given number of seconds from the specified date. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Number} seconds Contains the number of seconds to remove. * @return {Date} a date object. * * @since `v2.1.1` */ static removeSeconds(date: DateLike, seconds: number): Date; /** * Removes the given number of weeks from the specified date. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Number} weeks Contains the number of weeks to remove. * @return {Date} a date object. * * @since `v2.1.1` */ static removeWeeks(date: DateLike, weeks: number): Date; /** * Removes the given number of years from the specified date. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Number} years Contains the number of years to remove. * @return {Date} a date object. * * @since `v2.1.1` */ static removeYears(date: DateLike, years: number): Date; /** * Gets the days difference between the two specified dates. * * @param {DateLike} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {DateLike} other Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Number} round Contains whether to round the number of days * difference. * @return {Number} the days difference. */ static secondsDifference(date: DateLike, other: DateLike, round?: boolean): number; /** * Gets the Coordinated Universal Time (UTC) right now. */ static get utcNow(): Date; /** * Gets the weeks difference between the two specified dates. * * @param {DateLike} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {DateLike} other Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Number} round Contains whether to round the number of weeks * difference. * @return {Number} the weeks difference. * * @since `v2.1.2` */ static weeksDifference(date: DateLike, other: DateLike, round?: boolean): number; /** * Gets the difference in years between the two specified dates. * * @param {Date} date Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Date} other Contains a date object, an ISO 8601 date string * or the milliseconds from midnight, January 1, 1970 UTC. * @param {Boolean} round Contains whether to round the years difference. * Defaults to `false`. * @return {Number} the difference in years between the two specified dates. */ static yearsDifference(date: DateLike, other: DateLike, round?: boolean): number; /** * Gets the timezone offset in milliseconds. * * @param {Date} date Contains some date object. * @return {Number} the timezone offset in milliseconds. */ private static getTimezoneOffset; /** * Tries to parse the specified value of either of the types `string`, * `number` or `Date` as a `Date` object; otherwise throws `TypeError`. * * @param {Date} value Contains some date. * @return {Date} the parsed date. * * @private */ private static tryParse; /** * Checks whether the specified number is positive or zero; otheriwse * throws `TypeError`. * * @param {Number} nr Contains some number. * * @private */ private static nonNegative; }