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