Skip to content

Commit

Permalink
Merge pull request #3213 from david-driscoll:patch-2
Browse files Browse the repository at this point in the history
Added `type UnitOfTime`
  • Loading branch information
ichernev committed Jun 14, 2016
2 parents b06f137 + 171ce25 commit 76c0c23
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions moment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -204,36 +204,46 @@ 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)
*
* @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.
*
Expand All @@ -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.
*
Expand Down Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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.*/
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 76c0c23

Please sign in to comment.