From: David Driscoll Date: Mon, 6 Jun 2016 19:24:43 +0000 (-0400) Subject: Update moment.d.ts X-Git-Tag: 2.14.0~20^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=171ce25542ffbbb6bb8f905093b4fae39e1c7b50;p=thirdparty%2Fmoment.git Update moment.d.ts --- diff --git a/moment.d.ts b/moment.d.ts index 52f139554..77c3504f4 100644 --- a/moment.d.ts +++ b/moment.d.ts @@ -61,11 +61,11 @@ declare namespace moment { years(): number; asYears(): number; - add(n: number, p: string): Duration; + add(n: number, p: UnitOfTime): Duration; add(n: number): Duration; add(d: Duration): Duration; - subtract(n: number, p: string): Duration; + subtract(n: number, p: UnitOfTime): Duration; subtract(n: number): Duration; subtract(d: Duration): Duration; @@ -204,14 +204,24 @@ declare namespace moment { longDateFormat?: MomentLongDateFormat; } + type UnitOfTime = ("year" | "years" | "y" | + "quarter" | "quarters" | "Q" | + "month" | "months" | "M" | + "week" | "weeks" | "w" | + "day" | "days" | "d" | + "hour" | "hours" | "h" | + "minute" | "minutes" | "m" | + "second" | "seconds" | "s" | + "millisecond" | "milliseconds" | "ms"); + interface Moment { format(format: string): string; format(): string; fromNow(withoutSuffix?: boolean): string; - startOf(unitOfTime: string): Moment; - endOf(unitOfTime: string): Moment; + startOf(unitOfTime: UnitOfTime): Moment; + endOf(unitOfTime: UnitOfTime): Moment; /** * Mutates the original moment by adding time. (deprecated in 2.8.0) @@ -219,21 +229,21 @@ declare namespace moment { * @param unitOfTime the unit of time you want to add (eg "years" / "hours" etc) * @param amount the amount you want to add */ - add(unitOfTime: string, amount: number): Moment; + add(unitOfTime: UnitOfTime, amount: number): Moment; /** * Mutates the original moment by adding time. * * @param amount the amount you want to add * @param unitOfTime the unit of time you want to add (eg "years" / "hours" etc) */ - add(amount: number, unitOfTime: string): Moment; + add(amount: number, unitOfTime: UnitOfTime): Moment; /** * Mutates the original moment by adding time. Note that the order of arguments can be flipped. * * @param amount the amount you want to add * @param unitOfTime the unit of time you want to add (eg "years" / "hours" etc) */ - add(amount: string, unitOfTime: string): Moment; + add(amount: string, unitOfTime: UnitOfTime): Moment; /** * Mutates the original moment by adding time. * @@ -253,21 +263,21 @@ declare namespace moment { * @param unitOfTime the unit of time you want to subtract (eg "years" / "hours" etc) * @param amount the amount you want to subtract */ - subtract(unitOfTime: string, amount: number): Moment; + subtract(unitOfTime: UnitOfTime, amount: number): Moment; /** * Mutates the original moment by subtracting time. * * @param unitOfTime the unit of time you want to subtract (eg "years" / "hours" etc) * @param amount the amount you want to subtract */ - subtract(amount: number, unitOfTime: string): Moment; + subtract(amount: number, unitOfTime: UnitOfTime): Moment; /** * Mutates the original moment by subtracting time. Note that the order of arguments can be flipped. * * @param amount the amount you want to add * @param unitOfTime the unit of time you want to subtract (eg "years" / "hours" etc) */ - subtract(amount: string, unitOfTime: string): Moment; + subtract(amount: string, unitOfTime: UnitOfTime): Moment; /** * Mutates the original moment by subtracting time. * @@ -355,8 +365,8 @@ declare namespace moment { toNow(withoutPrefix?: boolean): string; diff(b: Moment): number; - diff(b: Moment, unitOfTime: string): number; - diff(b: Moment, unitOfTime: string, precise: boolean): number; + diff(b: Moment, unitOfTime: UnitOfTime): number; + diff(b: Moment, unitOfTime: UnitOfTime, precise: boolean): number; toArray(): number[]; toDate(): Date; @@ -383,7 +393,7 @@ declare namespace moment { isSame(b: Moment | string | number | Date | number[], granularity?: string): boolean; isSameOrAfter(b: Moment | string | number | Date | number[], granularity?: string): boolean; isSameOrBefore(b: Moment | string | number | Date | number[], granularity?: string): boolean; - + isBetween(a: Moment | string | number | Date | number[], b: Moment | string | number | Date | number[], granularity?: string, inclusivity?: string): boolean; // Deprecated as of 2.8.0. @@ -410,8 +420,8 @@ declare namespace moment { min(date: Moment | string | number | Date | any[]): Moment; min(date: string, format: string): Moment; - get(unit: string): number; - set(unit: string, value: number): Moment; + get(unit: UnitOfTime): number; + set(unit: UnitOfTime, value: number): Moment; set(objectLiteral: MomentInput): Moment; /*This returns an object containing year, month, day-of-month, hour, minute, seconds, milliseconds.*/ @@ -459,7 +469,7 @@ declare namespace moment { export var ordinal: (num: number) => string; export function duration(milliseconds: Number): Duration; - export function duration(num: Number, unitOfTime: string): Duration; + export function duration(num: Number, unitOfTime: UnitOfTime): Duration; export function duration(input: MomentInput): Duration; export function duration(object: any): Duration; export function duration(): Duration;