moment.d.ts 17 KB

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