index.d.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. /* eslint-disable */
  2. /// <reference path="./locale/index.d.ts" />
  3. export = dayjs;
  4. declare function dayjs (date?: dayjs.ConfigType): dayjs.Dayjs
  5. declare function dayjs (date?: dayjs.ConfigType, format?: dayjs.OptionType, strict?: boolean): dayjs.Dayjs
  6. declare function dayjs (date?: dayjs.ConfigType, format?: dayjs.OptionType, locale?: string, strict?: boolean): dayjs.Dayjs
  7. declare namespace dayjs {
  8. interface ConfigTypeMap {
  9. default: string | number | Date | Dayjs | null | undefined
  10. }
  11. export type ConfigType = ConfigTypeMap[keyof ConfigTypeMap]
  12. export interface FormatObject { locale?: string, format?: string, utc?: boolean }
  13. export type OptionType = FormatObject | string | string[]
  14. export type UnitTypeShort = 'd' | 'D' | 'M' | 'y' | 'h' | 'm' | 's' | 'ms'
  15. export type UnitTypeLong = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year' | 'date'
  16. export type UnitTypeLongPlural = 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years' | 'dates'
  17. export type UnitType = UnitTypeLong | UnitTypeLongPlural | UnitTypeShort;
  18. export type OpUnitType = UnitType | "week" | "weeks" | 'w';
  19. export type QUnitType = UnitType | "quarter" | "quarters" | 'Q';
  20. export type ManipulateType = Exclude<OpUnitType, 'date' | 'dates'>;
  21. class Dayjs {
  22. constructor (config?: ConfigType)
  23. /**
  24. * All Day.js objects are immutable. Still, `dayjs#clone` can create a clone of the current object if you need one.
  25. * ```
  26. * dayjs().clone()// => Dayjs
  27. * dayjs(dayjs('2019-01-25')) // passing a Dayjs object to a constructor will also clone it
  28. * ```
  29. * Docs: https://day.js.org/docs/en/parse/dayjs-clone
  30. */
  31. clone(): Dayjs
  32. /**
  33. * This returns a `boolean` indicating whether the Day.js object contains a valid date or not.
  34. * ```
  35. * dayjs().isValid()// => boolean
  36. * ```
  37. * Docs: https://day.js.org/docs/en/parse/is-valid
  38. */
  39. isValid(): boolean
  40. /**
  41. * Get the year.
  42. * ```
  43. * dayjs().year()// => 2020
  44. * ```
  45. * Docs: https://day.js.org/docs/en/get-set/year
  46. */
  47. year(): number
  48. /**
  49. * Set the year.
  50. * ```
  51. * dayjs().year(2000)// => Dayjs
  52. * ```
  53. * Docs: https://day.js.org/docs/en/get-set/year
  54. */
  55. year(value: number): Dayjs
  56. /**
  57. * Get the month.
  58. *
  59. * Months are zero indexed, so January is month 0.
  60. * ```
  61. * dayjs().month()// => 0-11
  62. * ```
  63. * Docs: https://day.js.org/docs/en/get-set/month
  64. */
  65. month(): number
  66. /**
  67. * Set the month.
  68. *
  69. * Months are zero indexed, so January is month 0.
  70. *
  71. * Accepts numbers from 0 to 11. If the range is exceeded, it will bubble up to the next year.
  72. * ```
  73. * dayjs().month(0)// => Dayjs
  74. * ```
  75. * Docs: https://day.js.org/docs/en/get-set/month
  76. */
  77. month(value: number): Dayjs
  78. /**
  79. * Get the date of the month.
  80. * ```
  81. * dayjs().date()// => 1-31
  82. * ```
  83. * Docs: https://day.js.org/docs/en/get-set/date
  84. */
  85. date(): number
  86. /**
  87. * Set the date of the month.
  88. *
  89. * Accepts numbers from 1 to 31. If the range is exceeded, it will bubble up to the next months.
  90. * ```
  91. * dayjs().date(1)// => Dayjs
  92. * ```
  93. * Docs: https://day.js.org/docs/en/get-set/date
  94. */
  95. date(value: number): Dayjs
  96. /**
  97. * Get the day of the week.
  98. *
  99. * Returns numbers from 0 (Sunday) to 6 (Saturday).
  100. * ```
  101. * dayjs().day()// 0-6
  102. * ```
  103. * Docs: https://day.js.org/docs/en/get-set/day
  104. */
  105. day(): 0 | 1 | 2 | 3 | 4 | 5 | 6
  106. /**
  107. * Set the day of the week.
  108. *
  109. * Accepts numbers from 0 (Sunday) to 6 (Saturday). If the range is exceeded, it will bubble up to next weeks.
  110. * ```
  111. * dayjs().day(0)// => Dayjs
  112. * ```
  113. * Docs: https://day.js.org/docs/en/get-set/day
  114. */
  115. day(value: number): Dayjs
  116. /**
  117. * Get the hour.
  118. * ```
  119. * dayjs().hour()// => 0-23
  120. * ```
  121. * Docs: https://day.js.org/docs/en/get-set/hour
  122. */
  123. hour(): number
  124. /**
  125. * Set the hour.
  126. *
  127. * Accepts numbers from 0 to 23. If the range is exceeded, it will bubble up to the next day.
  128. * ```
  129. * dayjs().hour(12)// => Dayjs
  130. * ```
  131. * Docs: https://day.js.org/docs/en/get-set/hour
  132. */
  133. hour(value: number): Dayjs
  134. /**
  135. * Get the minutes.
  136. * ```
  137. * dayjs().minute()// => 0-59
  138. * ```
  139. * Docs: https://day.js.org/docs/en/get-set/minute
  140. */
  141. minute(): number
  142. /**
  143. * Set the minutes.
  144. *
  145. * Accepts numbers from 0 to 59. If the range is exceeded, it will bubble up to the next hour.
  146. * ```
  147. * dayjs().minute(59)// => Dayjs
  148. * ```
  149. * Docs: https://day.js.org/docs/en/get-set/minute
  150. */
  151. minute(value: number): Dayjs
  152. /**
  153. * Get the seconds.
  154. * ```
  155. * dayjs().second()// => 0-59
  156. * ```
  157. * Docs: https://day.js.org/docs/en/get-set/second
  158. */
  159. second(): number
  160. /**
  161. * Set the seconds.
  162. *
  163. * Accepts numbers from 0 to 59. If the range is exceeded, it will bubble up to the next minutes.
  164. * ```
  165. * dayjs().second(1)// Dayjs
  166. * ```
  167. */
  168. second(value: number): Dayjs
  169. /**
  170. * Get the milliseconds.
  171. * ```
  172. * dayjs().millisecond()// => 0-999
  173. * ```
  174. * Docs: https://day.js.org/docs/en/get-set/millisecond
  175. */
  176. millisecond(): number
  177. /**
  178. * Set the milliseconds.
  179. *
  180. * Accepts numbers from 0 to 999. If the range is exceeded, it will bubble up to the next seconds.
  181. * ```
  182. * dayjs().millisecond(1)// => Dayjs
  183. * ```
  184. * Docs: https://day.js.org/docs/en/get-set/millisecond
  185. */
  186. millisecond(value: number): Dayjs
  187. /**
  188. * Generic setter, accepting unit as first argument, and value as second, returns a new instance with the applied changes.
  189. *
  190. * In general:
  191. * ```
  192. * dayjs().set(unit, value) === dayjs()[unit](value)
  193. * ```
  194. * Units are case insensitive, and support plural and short forms.
  195. * ```
  196. * dayjs().set('date', 1)
  197. * dayjs().set('month', 3) // April
  198. * dayjs().set('second', 30)
  199. * ```
  200. * Docs: https://day.js.org/docs/en/get-set/set
  201. */
  202. set(unit: UnitType, value: number): Dayjs
  203. /**
  204. * String getter, returns the corresponding information getting from Day.js object.
  205. *
  206. * In general:
  207. * ```
  208. * dayjs().get(unit) === dayjs()[unit]()
  209. * ```
  210. * Units are case insensitive, and support plural and short forms.
  211. * ```
  212. * dayjs().get('year')
  213. * dayjs().get('month') // start 0
  214. * dayjs().get('date')
  215. * ```
  216. * Docs: https://day.js.org/docs/en/get-set/get
  217. */
  218. get(unit: UnitType): number
  219. /**
  220. * Returns a cloned Day.js object with a specified amount of time added.
  221. * ```
  222. * dayjs().add(7, 'day')// => Dayjs
  223. * ```
  224. * Units are case insensitive, and support plural and short forms.
  225. *
  226. * Docs: https://day.js.org/docs/en/manipulate/add
  227. */
  228. add(value: number, unit?: ManipulateType): Dayjs
  229. /**
  230. * Returns a cloned Day.js object with a specified amount of time subtracted.
  231. * ```
  232. * dayjs().subtract(7, 'year')// => Dayjs
  233. * ```
  234. * Units are case insensitive, and support plural and short forms.
  235. *
  236. * Docs: https://day.js.org/docs/en/manipulate/subtract
  237. */
  238. subtract(value: number, unit?: ManipulateType): Dayjs
  239. /**
  240. * Returns a cloned Day.js object and set it to the start of a unit of time.
  241. * ```
  242. * dayjs().startOf('year')// => Dayjs
  243. * ```
  244. * Units are case insensitive, and support plural and short forms.
  245. *
  246. * Docs: https://day.js.org/docs/en/manipulate/start-of
  247. */
  248. startOf(unit: OpUnitType): Dayjs
  249. /**
  250. * Returns a cloned Day.js object and set it to the end of a unit of time.
  251. * ```
  252. * dayjs().endOf('month')// => Dayjs
  253. * ```
  254. * Units are case insensitive, and support plural and short forms.
  255. *
  256. * Docs: https://day.js.org/docs/en/manipulate/end-of
  257. */
  258. endOf(unit: OpUnitType): Dayjs
  259. /**
  260. * Get the formatted date according to the string of tokens passed in.
  261. *
  262. * To escape characters, wrap them in square brackets (e.g. [MM]).
  263. * ```
  264. * dayjs().format()// => current date in ISO8601, without fraction seconds e.g. '2020-04-02T08:02:17-05:00'
  265. * dayjs('2019-01-25').format('[YYYYescape] YYYY-MM-DDTHH:mm:ssZ[Z]')// 'YYYYescape 2019-01-25T00:00:00-02:00Z'
  266. * dayjs('2019-01-25').format('DD/MM/YYYY') // '25/01/2019'
  267. * ```
  268. * Docs: https://day.js.org/docs/en/display/format
  269. */
  270. format(template?: string): string
  271. /**
  272. * This indicates the difference between two date-time in the specified unit.
  273. *
  274. * To get the difference in milliseconds, use `dayjs#diff`
  275. * ```
  276. * const date1 = dayjs('2019-01-25')
  277. * const date2 = dayjs('2018-06-05')
  278. * date1.diff(date2) // 20214000000 default milliseconds
  279. * date1.diff() // milliseconds to current time
  280. * ```
  281. *
  282. * To get the difference in another unit of measurement, pass that measurement as the second argument.
  283. * ```
  284. * const date1 = dayjs('2019-01-25')
  285. * date1.diff('2018-06-05', 'month') // 7
  286. * ```
  287. * Units are case insensitive, and support plural and short forms.
  288. *
  289. * Docs: https://day.js.org/docs/en/display/difference
  290. */
  291. diff(date?: ConfigType, unit?: QUnitType | OpUnitType, float?: boolean): number
  292. /**
  293. * This returns the number of **milliseconds** since the Unix Epoch of the Day.js object.
  294. * ```
  295. * dayjs('2019-01-25').valueOf() // 1548381600000
  296. * +dayjs(1548381600000) // 1548381600000
  297. * ```
  298. * To get a Unix timestamp (the number of seconds since the epoch) from a Day.js object, you should use Unix Timestamp `dayjs#unix()`.
  299. *
  300. * Docs: https://day.js.org/docs/en/display/unix-timestamp-milliseconds
  301. */
  302. valueOf(): number
  303. /**
  304. * This returns the Unix timestamp (the number of **seconds** since the Unix Epoch) of the Day.js object.
  305. * ```
  306. * dayjs('2019-01-25').unix() // 1548381600
  307. * ```
  308. * This value is floored to the nearest second, and does not include a milliseconds component.
  309. *
  310. * Docs: https://day.js.org/docs/en/display/unix-timestamp
  311. */
  312. unix(): number
  313. /**
  314. * Get the number of days in the current month.
  315. * ```
  316. * dayjs('2019-01-25').daysInMonth() // 31
  317. * ```
  318. * Docs: https://day.js.org/docs/en/display/days-in-month
  319. */
  320. daysInMonth(): number
  321. /**
  322. * To get a copy of the native `Date` object parsed from the Day.js object use `dayjs#toDate`.
  323. * ```
  324. * dayjs('2019-01-25').toDate()// => Date
  325. * ```
  326. */
  327. toDate(): Date
  328. /**
  329. * To serialize as an ISO 8601 string.
  330. * ```
  331. * dayjs('2019-01-25').toJSON() // '2019-01-25T02:00:00.000Z'
  332. * ```
  333. * Docs: https://day.js.org/docs/en/display/as-json
  334. */
  335. toJSON(): string
  336. /**
  337. * To format as an ISO 8601 string.
  338. * ```
  339. * dayjs('2019-01-25').toISOString() // '2019-01-25T02:00:00.000Z'
  340. * ```
  341. * Docs: https://day.js.org/docs/en/display/as-iso-string
  342. */
  343. toISOString(): string
  344. /**
  345. * Returns a string representation of the date.
  346. * ```
  347. * dayjs('2019-01-25').toString() // 'Fri, 25 Jan 2019 02:00:00 GMT'
  348. * ```
  349. * Docs: https://day.js.org/docs/en/display/as-string
  350. */
  351. toString(): string
  352. /**
  353. * Get the UTC offset in minutes.
  354. * ```
  355. * dayjs().utcOffset()
  356. * ```
  357. * Docs: https://day.js.org/docs/en/manipulate/utc-offset
  358. */
  359. utcOffset(): number
  360. /**
  361. * This indicates whether the Day.js object is before the other supplied date-time.
  362. * ```
  363. * dayjs().isBefore(dayjs('2011-01-01')) // default milliseconds
  364. * ```
  365. * If you want to limit the granularity to a unit other than milliseconds, pass it as the second parameter.
  366. * ```
  367. * dayjs().isBefore('2011-01-01', 'year')// => boolean
  368. * ```
  369. * Units are case insensitive, and support plural and short forms.
  370. *
  371. * Docs: https://day.js.org/docs/en/query/is-before
  372. */
  373. isBefore(date?: ConfigType, unit?: OpUnitType): boolean
  374. /**
  375. * This indicates whether the Day.js object is the same as the other supplied date-time.
  376. * ```
  377. * dayjs().isSame(dayjs('2011-01-01')) // default milliseconds
  378. * ```
  379. * If you want to limit the granularity to a unit other than milliseconds, pass it as the second parameter.
  380. * ```
  381. * dayjs().isSame('2011-01-01', 'year')// => boolean
  382. * ```
  383. * Docs: https://day.js.org/docs/en/query/is-same
  384. */
  385. isSame(date?: ConfigType, unit?: OpUnitType): boolean
  386. /**
  387. * This indicates whether the Day.js object is after the other supplied date-time.
  388. * ```
  389. * dayjs().isAfter(dayjs('2011-01-01')) // default milliseconds
  390. * ```
  391. * If you want to limit the granularity to a unit other than milliseconds, pass it as the second parameter.
  392. * ```
  393. * dayjs().isAfter('2011-01-01', 'year')// => boolean
  394. * ```
  395. * Units are case insensitive, and support plural and short forms.
  396. *
  397. * Docs: https://day.js.org/docs/en/query/is-after
  398. */
  399. isAfter(date?: ConfigType, unit?: OpUnitType): boolean
  400. locale(): string
  401. locale(preset: string | ILocale, object?: Partial<ILocale>): Dayjs
  402. }
  403. export type PluginFunc<T = unknown> = (option: T, c: typeof Dayjs, d: typeof dayjs) => void
  404. export function extend<T = unknown>(plugin: PluginFunc<T>, option?: T): Dayjs
  405. export function locale(preset?: string | ILocale, object?: Partial<ILocale>, isLocal?: boolean): string
  406. export function isDayjs(d: any): d is Dayjs
  407. export function unix(t: number): Dayjs
  408. const Ls : { [key: string] : ILocale }
  409. }