@barchart/common-js
Version:
Library of common JavaScript utilities
259 lines (258 loc) • 7.55 kB
TypeScript
/**
* A data structure that represents a day (year, month, and day)
* without consideration for time or timezone.
*
* @public
*/
export default class Day {
/**
* Clones a {@link Day} instance.
*
* @public
* @static
* @param {Day} value
* @returns {Day}
*/
public static clone(value: Day): Day;
/**
* Converts a string (which matches the output of {@link Day#format}) into
* a {@link Day} instance.
*
* @public
* @static
* @param {string} value
* @param {DayFormatType=} type
* @returns {Day}
*/
public static parse(value: string, type?: DayFormatType | undefined): Day;
/**
* Creates a {@link Day} from the year, month, and day properties (in local time)
* of the {@link Date} argument.
*
* @public
* @static
* @param {Date} date
* @returns {Day}
*/
public static fromDate(date: Date): Day;
/**
* Creates a {@link Day} from the year, month, and day properties (in UTC)
* of the {@link Date} argument.
*
* @public
* @static
* @param {Date} date
* @returns {Day}
*/
public static fromDateUtc(date: Date): Day;
/**
* Returns a {@link Day} instance using today's local date.
*
* @public
* @static
* @returns {Day}
*/
public static getToday(): Day;
/**
* Returns true if the year, month, and day combination is valid; otherwise false.
*
* @public
* @static
* @param {number} year
* @param {number} month
* @param {number} day
* @returns {boolean}
*/
public static validate(year: number, month: number, day: number): boolean;
/**
* Returns the number of days in a given month.
*
* @public
* @static
* @param {number} year - The year number (e.g. 2017)
* @param {number} month - The month number (e.g. 2 is February)
* @returns {number}
*/
public static getDaysInMonth(year: number, month: number): number;
/**
* A comparator function for {@link Day} instances.
*
* @public
* @static
* @param {Day} a
* @param {Day} b
* @returns {number}
*/
public static compareDays(a: Day, b: Day): number;
/**
* Calculates the number of days between two {@link Day} instances (may return
* a negative value).
*
* @public
* @static
* @param {Day} a
* @param {Day} b
* @returns {number}
*/
public static countDaysBetween(a: Day, b: Day): number;
/**
* @param {number} year
* @param {number} month
* @param {number} day
*/
constructor(year: number, month: number, day: number);
/**
* Calculates a new {@link Day} in the future (or past).
*
* @public
* @param {number} days - The number of days to add (negative numbers can be used for subtraction).
* @param {boolean=} inverse - If true, the sign of the "days" value will be flipped.
* @returns {Day}
*/
public addDays(days: number, inverse?: boolean | undefined): Day;
/**
* Calculates a new {@link Day} in the past (or future).
*
* @public
* @param {number} days - The number of days to subtract (negative numbers can be used for addition).
* @returns {Day}
*/
public subtractDays(days: number): Day;
/**
* Calculates a new {@link Day} in the future (or past). If the new date is at the end of
* the month and the new month has fewer days than the current month, days will be subtracted
* as necessary (e.g. adding one month to March 31 will return April 30).
*
* @public
* @param {number} months - The number of months to add (negative numbers can be used for subtraction).
* @param {boolean=} inverse - If true, the sign of the "days" value will be flipped.
* @returns {Day}
*/
public addMonths(months: number, inverse?: boolean | undefined): Day;
/**
* Calculates a new {@link Day} in the past (or future).
*
* @public
* @param {number} months - The number of months to subtract (negative numbers can be used for addition).
* @returns {Day}
*/
public subtractMonths(months: number): Day;
/**
* Calculates a new {@link Day} in the future (or past). If the new date is at the end of
* the month and the new month has fewer days than the current month, days will be subtracted
* as necessary (e.g. adding one year to February 29 will return February 28).
*
* @public
* @param {number} years - The number of years to add (negative numbers can be used for subtraction).
* @param {boolean=} inverse - If true, the sign of the "days" value will be flipped.
* @returns {Day}
*/
public addYears(years: number, inverse?: boolean | undefined): Day;
/**
* Calculates a new {@link Day} in the past (or future).
*
* @public
* @param {number} years - The number of years to subtract (negative numbers can be used for addition).
* @returns {Day}
*/
public subtractYears(years: number): Day;
/**
* Returns a new {@link Day} instance for the start of the month referenced by the current instance.
*
* @public
* @returns {Day}
*/
public getStartOfMonth(): Day;
/**
* Returns a new instance for the {@link Day} end of the month referenced by the current instance.
*
* @public
* @returns {Day}
*/
public getEndOfMonth(): Day;
/**
* Indicates if the current {@link Day} instance occurs before another day.
*
* @public
* @param {Day} other
* @returns {boolean}
*/
public getIsBefore(other: Day): boolean;
/**
* Indicates if the current {@link Day} instance occurs after another day.
*
* @public
* @param {Day} other
* @returns {boolean}
*/
public getIsAfter(other: Day): boolean;
/**
* Indicates the current day falls between two other days, inclusive
* of the range boundaries.
*
* @public
* @param {Day=} first
* @param {Day=} last
* @returns {boolean}
*/
public getIsContained(first?: Day | undefined, last?: Day | undefined): boolean;
/**
* Indicates if another {@link Day} refers to the same moment.
*
* @public
* @param {Day} other
* @returns {boolean}
*/
public getIsEqual(other: Day): boolean;
/**
* Calculates and returns name of the day of the week (e.g. Monday, Tuesday, Wednesday, etc.).
*
* @public
* @returns {string}
*/
public getName(): string;
/**
* The year.
*
* @public
* @returns {number}
*/
public get year(): number;
/**
* The month of the year (January is one, December is twelve).
*
* @public
* @returns {number}
*/
public get month(): number;
/**
* The day of the month.
*
* @public
* @returns {number}
*/
public get day(): number;
/**
* Outputs the date as the formatted string: {year}-{month}-{day}.
*
* @public
* @returns {string}
*/
public format(): string;
/**
* Returns the JSON representation.
*
* @public
* @returns {string}
*/
public toJSON(): string;
/**
* Returns a string representation.
*
* @public
* @returns {string}
*/
public toString(): string;
#private;
}
import DayFormatType from './DayFormatType.js';