index.d.ts 14 KB

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