moment.d.ts 16 KB

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