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;
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.
*
* @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.
*
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;
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.
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.*/
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;