moment-node.d.ts 14 KB

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