You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

536 lines
17 KiB

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