UNPKG

@cute-dw/core

Version:

This TypeScript library is the main part of a more powerfull package designed for the fast WEB software development. The cornerstone of the library is the **DataStore** class, which might be useful when you need a full control of the data, but do not need

198 lines (197 loc) 8.73 kB
/** * This class consists exclusively of the static methods that operate on or return date/time values */ export declare class Dates { private static msPerDay; /** * Gets the current date and time * @returns Current date/time value */ static getDate(): Date; /** * Calculates the number of days in the month * @param date Base date * @returns Count of days */ static daysInMonth(date: Date): number; /** * Calculates the number of days in the `quarter` * @param year The number of the year. * @param quarter The number of the quarter. * @returns Count of days */ static daysInQuarter(year?: number, quarter?: number): number; /** * Calculates the number of days in the `year` * @param year The number of the year. Default is the current year. * @returns Count of days */ static daysInYear(year?: number): number; /** * Calculates the date of the first week's day in the month * @param day Day of the week in range 0 Sunday to 6 Saturday * @param month Month * @param year Year * @returns Date */ static firstDayInMonth(day: 0 | 1 | 2 | 3 | 4 | 5 | 6, month: number, year: number): Date; /** * Calculates the date of n-th week's day in the month * @param n Ordered number * @param day Day of week in range 0 Sunday to 6 Saturday * @param month Month * @param year Year * @returns Date */ static nthDayInMonth(n: number, day: 0 | 1 | 2 | 3 | 4 | 5 | 6, month: number, year: number): Date; /** * Calculates the number of days to fixed `day` number * @param day The day number in the current month * @returns Number of days */ static daysFromFixedDay(day: number): number; /** * Determines the number of days one date occurs after another. * @param date1 A date value that is the start date of the interval being measured * @param date2 A date value that is the end date of the interval * @returns {number} Returns a number of days date2 occurs after date1. If date2 occurs before date1, DaysAfter returns a negative number. If any argument's value is null, DaysAfter returns null. */ static daysAfter(date1: Date, date2: Date): number | null; /** * Determines the number of seconds one date occurs after another. * @param date1 A date value that is the start date of the interval being measured * @param date2 A date value that is the end date of the interval * @returns {number} Returns a number of seconds date2 occurs after date1. If date2 occurs before date1, DaysAfter returns a negative number. If any argument's value is null, DaysAfter returns null. */ static secondsAfter(date1: Date, date2: Date): number | null; /** * Obtains the date that occurs a specified number of days after or before another date * @param date A value of type date * @param days An integer indicating a number of days * @returns The date that occurs `days` after date if `days` is greater than 0. Returns the date that occurs `days` before date if `days` is less than 0. If any argument's value is null, {@link relativeDate} returns null. * @see {@link relativeTime} */ static relativeDate(date: Date, days: number): Date | null; /** * Obtains a time that occurs a specified number of seconds after or before another time within a 24-hour period * @param date A value of type time * @param secs A long number of seconds * @returns The time that occurs `secs` seconds after time if `secs` is greater than 0. Returns the time that occurs `secs` seconds before time if `secs` is less than 0. The maximum return value is 23:59:59. If any argument's value is null, {@link relativeTime} returns null * @see {@link relativeDate} */ static relativeTime(date: Date, secs: number): Date | null; /** * Converts milliseconds to number of days * @param ms Number of milliseconds * @returns Number/interval of days */ static toDays(ms: number): number; /** * Converts date to UTC * @param date The base date * @returns The number of milliseconds, or `NaN` if the `date` is _null_. */ static toUTC(date: Date | null): number; /** * Converts Date to localized ISO-string */ static toString(date: Date | null, showTime?: boolean): string | null; /** * Gets the first date of the month * @param date The base date. Default is the current date. * @returns The calculated date, or _null_ if the `date` is _null_ * @see {@link dateEOM} */ static dateBOM(date?: Date | null): Date | null; /** * Gets the last date of the month * @param date The base date. Default is the current date. * @returns The calculated date, or _null_ if the `date` is _null_. * @see {@link dateBOM} */ static dateEOM(date?: Date | null): Date | null; /** * Gets the first date of the year * @param date The base date. Default is the current date. * @returns The calculated date, or _null_ if the `date` is _null_. * @see {@link dateEOY} */ static dateBOY(date?: Date | null): Date | null; /** * Gets the last date of the year * @param date The base date. Default is the current date. * @returns The calculated date, or _null_ if the `date` is _null_. * @see {@link dateBOY} */ static dateEOY(date?: Date | null): Date | null; /** * Gets the first date of quarter * @param date The base date. Default is the current date. * @returns The calculated date, or _null_ if the `date` is _null_. * @see {@link dateEOQ} */ static dateBOQ(date?: Date | null): Date | null; /** * Gets the last date of the quarter * @param date The base date. Default is the current date. * @returns The calculated date, or _null_ if the `date` is _null_. * @see {@link dateBOQ} */ static dateEOQ(date?: Date | null): Date | null; /** * Gets the quarter number to which the `date` belongs * @param date The base date. Default is the current date. * @returns The quarter number starting from 0, or _null_ if the `date` is _null_. */ static getQuarter(date?: Date | null): number | null; /** * Return whether the provided year is a leap year * @param year Year number to check * @returns _true_ if `year` is a leap year, else _false_. */ static isLeapYear(year: number): boolean; /** * Returns the result of checking whether the number of hours in the specified date is less than 12 * @param date Date to check. Default is the current date * @returns _true_ if hours of `date` is less than 12, else _false_. */ static isAM(date?: Date | null): boolean | null; /** * Returns the result of checking whether the number of hours in the specified date is greater than or equal to 12 * @param date Date to check. Default is the current date * @returns _true_ if hours of `date` is greater than or equal to 12, else _false_. */ static isPM(date?: Date | null): boolean | null; /** * Get ISO-8601 numeric representation of the day of the week * 1 (for Monday) through 7 (for Sunday) * @param date Source date. Default is current date. * @returns The day of the week starting from 1, or _null_ if the `date` is _null_. * @since 0.5.0 */ static getDayOfWeek(date?: Date | null): number | null; /** * Gets a day number in year * @param date Source date. Default is the current date * @returns Day number in year, or _null_ if the `date` is _null_. * @since 0.5.0 */ static getDayOfYear(date?: Date): number | null; /** * Gets a week number of month * @param date Source date. Default is the current date * @returns Week number of month, or _null_ if the `date` is _null_. * @since 0.5.0 */ static getWeekOfMonth(date?: Date | null): number | null; /** * Get the ISO 8601 week number of year * Based on comments from * http://techblog.procurios.nl/k/n618/news/view/33796/14863/Calculate-ISO-8601-week-and-year-in-javascript.html * * @param date Source date. Default is the current date * @returns ISO 8601 week number of year, or _null_ if the `date` is _null_. * @since 0.5.0 */ static getWeek(date?: Date | null): number | null; }