index.d.ts 13 KB

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