forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
moment-node.d.ts
479 lines (395 loc) · 14.2 KB
/
moment-node.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
// Type definitions for Moment.js 2.8.0
// Project: https://github.com/timrwood/moment
// Definitions by: Michael Lakerveld <https://github.com/Lakerfield>, Aaron King <https://github.com/kingdango>, Hiroki Horiuchi <https://github.com/horiuchi>, Dick van den Brink <https://github.com/DickvdBrink>, Adi Dahiya <https://github.com/adidahiya>, Matt Brooks <https://github.com/EnableSoftware>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module moment {
interface MomentInput {
/** Year */
years?: number;
/** Year */
year?: number;
/** Year */
y?: number;
/** Month */
months?: number;
/** Month */
month?: number;
/** Month */
M?: number;
/** Day/Date */
days?: number;
/** Day/Date */
day?: number;
/** Day/Date */
date?: number;
/** Day/Date */
d?: number;
/** Hour */
hours?: number;
/** Hour */
hour?: number;
/** Hour */
h?: number;
/** Minute */
minutes?: number;
/** Minute */
minute?: number;
/** Minute */
m?: number;
/** Second */
seconds?: number;
/** Second */
second?: number;
/** Second */
s?: number;
/** Millisecond */
milliseconds?: number;
/** Millisecond */
millisecond?: number;
/** Millisecond */
ms?: number;
}
interface Duration {
humanize(withSuffix?: boolean): string;
as(units: string): number;
milliseconds(): number;
asMilliseconds(): number;
seconds(): number;
asSeconds(): number;
minutes(): number;
asMinutes(): number;
hours(): number;
asHours(): number;
days(): number;
asDays(): number;
months(): number;
asMonths(): number;
years(): number;
asYears(): number;
add(n: number, p: string): Duration;
add(n: number): Duration;
add(d: Duration): Duration;
subtract(n: number, p: string): Duration;
subtract(n: number): Duration;
subtract(d: Duration): Duration;
toISOString(): string;
toJSON(): string;
}
interface Moment {
format(format: string): string;
format(): string;
fromNow(withoutSuffix?: boolean): string;
startOf(unitOfTime: string): Moment;
endOf(unitOfTime: string): 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;
/**
* 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;
/**
* 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;
/**
* Mutates the original moment by adding time.
*
* @param objectLiteral an object literal that describes multiple time units {days:7,months:1}
*/
add(objectLiteral: MomentInput): Moment;
/**
* Mutates the original moment by adding time.
*
* @param duration a length of time
*/
add(duration: Duration): Moment;
/**
* Mutates the original moment by subtracting time. (deprecated in 2.8.0)
*
* @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;
/**
* 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;
/**
* 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;
/**
* Mutates the original moment by subtracting time.
*
* @param objectLiteral an object literal that describes multiple time units {days:7,months:1}
*/
subtract(objectLiteral: MomentInput): Moment;
/**
* Mutates the original moment by subtracting time.
*
* @param duration a length of time
*/
subtract(duration: Duration): Moment;
calendar(): string;
calendar(start: Moment): string;
clone(): Moment;
/**
* @return Unix timestamp, or milliseconds since the epoch.
*/
valueOf(): number;
local(): Moment; // current date/time in local mode
utc(): Moment; // current date/time in UTC mode
isValid(): boolean;
invalidAt(): number;
year(y: number): Moment;
year(): number;
quarter(): number;
quarter(q: number): Moment;
month(M: number): Moment;
month(M: string): Moment;
month(): number;
day(d: number): Moment;
day(d: string): Moment;
day(): number;
date(d: number): Moment;
date(): number;
hour(h: number): Moment;
hour(): number;
hours(h: number): Moment;
hours(): number;
minute(m: number): Moment;
minute(): number;
minutes(m: number): Moment;
minutes(): number;
second(s: number): Moment;
second(): number;
seconds(s: number): Moment;
seconds(): number;
millisecond(ms: number): Moment;
millisecond(): number;
milliseconds(ms: number): Moment;
milliseconds(): number;
weekday(): number;
weekday(d: number): Moment;
isoWeekday(): number;
isoWeekday(d: number): Moment;
weekYear(): number;
weekYear(d: number): Moment;
isoWeekYear(): number;
isoWeekYear(d: number): Moment;
week(): number;
week(d: number): Moment;
weeks(): number;
weeks(d: number): Moment;
isoWeek(): number;
isoWeek(d: number): Moment;
isoWeeks(): number;
isoWeeks(d: number): Moment;
weeksInYear(): number;
isoWeeksInYear(): number;
dayOfYear(): number;
dayOfYear(d: number): Moment;
from(f: Moment|string|number|Date|number[], suffix?: boolean): string;
to(f: Moment|string|number|Date|number[], suffix?: boolean): string;
diff(b: Moment): number;
diff(b: Moment, unitOfTime: string): number;
diff(b: Moment, unitOfTime: string, round: boolean): number;
toArray(): number[];
toDate(): Date;
toISOString(): string;
toJSON(): string;
unix(): number;
isLeapYear(): boolean;
zone(): number;
zone(b: number): Moment;
zone(b: string): Moment;
utcOffset(): number;
utcOffset(b: number): Moment;
utcOffset(b: string): Moment;
daysInMonth(): number;
isDST(): boolean;
isBefore(): boolean;
isBefore(b: Moment|string|number|Date|number[], granularity?: string): boolean;
isAfter(): boolean;
isAfter(b: Moment|string|number|Date|number[], granularity?: string): boolean;
isSame(b: Moment|string|number|Date|number[], granularity?: string): boolean;
isBetween(a: Moment|string|number|Date|number[], b: Moment|string|number|Date|number[], granularity?: string): boolean;
// Deprecated as of 2.8.0.
lang(language: string): Moment;
lang(reset: boolean): Moment;
lang(): MomentLanguage;
locale(language: string): Moment;
locale(reset: boolean): Moment;
locale(): string;
localeData(language: string): Moment;
localeData(reset: boolean): Moment;
localeData(): MomentLanguage;
// Deprecated as of 2.7.0.
max(date: Moment|string|number|Date|any[]): Moment;
max(date: string, format: string): Moment;
// Deprecated as of 2.7.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;
}
interface MomentCalendar {
lastDay: any;
sameDay: any;
nextDay: any;
lastWeek: any;
nextWeek: any;
sameElse: any;
}
interface BaseMomentLanguage {
months ?: any;
monthsShort ?: any;
weekdays ?: any;
weekdaysShort ?: any;
weekdaysMin ?: any;
relativeTime ?: MomentRelativeTime;
meridiem ?: (hour: number, minute: number, isLowercase: boolean) => string;
calendar ?: MomentCalendar;
ordinal ?: (num: number) => string;
}
interface MomentLanguage extends BaseMomentLanguage {
longDateFormat?: MomentLongDateFormat;
}
interface MomentLanguageData extends BaseMomentLanguage {
/**
* @param formatType should be L, LL, LLL, LLLL.
*/
longDateFormat(formatType: string): string;
}
interface MomentLongDateFormat {
L: string;
LL: string;
LLL: string;
LLLL: string;
LT: string;
l?: string;
ll?: string;
lll?: string;
llll?: string;
lt?: string;
}
interface MomentRelativeTime {
future: any;
past: any;
s: any;
m: any;
mm: any;
h: any;
hh: any;
d: any;
dd: any;
M: any;
MM: any;
y: any;
yy: any;
}
interface MomentStatic {
version: string;
fn: Moment;
(): Moment;
(date: number): Moment;
(date: number[]): Moment;
(date: string, format?: string, strict?: boolean): Moment;
(date: string, format?: string, language?: string, strict?: boolean): Moment;
(date: string, formats: string[], strict?: boolean): Moment;
(date: string, formats: string[], language?: string, strict?: boolean): Moment;
(date: string, specialFormat: () => void, strict?: boolean): Moment;
(date: string, specialFormat: () => void, language?: string, strict?: boolean): Moment;
(date: string, formatsIncludingSpecial: any[], strict?: boolean): Moment;
(date: string, formatsIncludingSpecial: any[], language?: string, strict?: boolean): Moment;
(date: Date): Moment;
(date: Moment): Moment;
(date: Object): Moment;
utc(): Moment;
utc(date: number): Moment;
utc(date: number[]): Moment;
utc(date: string, format?: string, strict?: boolean): Moment;
utc(date: string, format?: string, language?: string, strict?: boolean): Moment;
utc(date: string, formats: string[], strict?: boolean): Moment;
utc(date: string, formats: string[], language?: string, strict?: boolean): Moment;
utc(date: Date): Moment;
utc(date: Moment): Moment;
utc(date: Object): Moment;
unix(timestamp: number): Moment;
invalid(parsingFlags?: Object): Moment;
isMoment(): boolean;
isMoment(m: any): boolean;
isDate(m: any): boolean;
isDuration(): boolean;
isDuration(d: any): boolean;
// Deprecated in 2.8.0.
lang(language?: string): string;
lang(language?: string, definition?: MomentLanguage): string;
locale(language?: string): string;
locale(language?: string[]): string;
locale(language?: string, definition?: MomentLanguage): string;
localeData(language?: string): MomentLanguageData;
longDateFormat: any;
relativeTime: any;
meridiem: (hour: number, minute: number, isLowercase: boolean) => string;
calendar: any;
ordinal: (num: number) => string;
duration(milliseconds: Number): Duration;
duration(num: Number, unitOfTime: string): Duration;
duration(input: MomentInput): Duration;
duration(object: any): Duration;
duration(): Duration;
parseZone(date: string): Moment;
months(): string[];
months(index: number): string;
months(format: string): string[];
months(format: string, index: number): string;
monthsShort(): string[];
monthsShort(index: number): string;
monthsShort(format: string): string[];
monthsShort(format: string, index: number): string;
weekdays(): string[];
weekdays(index: number): string;
weekdays(format: string): string[];
weekdays(format: string, index: number): string;
weekdaysShort(): string[];
weekdaysShort(index: number): string;
weekdaysShort(format: string): string[];
weekdaysShort(format: string, index: number): string;
weekdaysMin(): string[];
weekdaysMin(index: number): string;
weekdaysMin(format: string): string[];
weekdaysMin(format: string, index: number): string;
min(moments: Moment[]): Moment;
max(moments: Moment[]): Moment;
normalizeUnits(unit: string): string;
relativeTimeThreshold(threshold: string): number|boolean;
relativeTimeThreshold(threshold: string, limit:number): boolean;
/**
* Constant used to enable explicit ISO_8601 format parsing.
*/
ISO_8601(): void;
defaultFormat: string;
}
}
declare module 'moment' {
var moment: moment.MomentStatic;
export = moment;
}