duration.d.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { PluginFunc } from 'dayjs'
  2. import { OpUnitType, UnitTypeLongPlural } from 'dayjs';
  3. declare const plugin: PluginFunc
  4. export as namespace plugin;
  5. export = plugin
  6. declare namespace plugin {
  7. /**
  8. * @deprecated Please use more strict types
  9. */
  10. type DurationInputType = string | number | object
  11. /**
  12. * @deprecated Please use more strict types
  13. */
  14. type DurationAddType = number | object | Duration
  15. type DurationUnitsObjectType = Partial<{
  16. [unit in Exclude<UnitTypeLongPlural, "dates"> | "weeks"]: number
  17. }>;
  18. type DurationUnitType = Exclude<OpUnitType, "date" | "dates">
  19. type CreateDurationType =
  20. ((units: DurationUnitsObjectType) => Duration)
  21. & ((time: number, unit?: DurationUnitType) => Duration)
  22. & ((ISO_8601: string) => Duration)
  23. type AddDurationType = CreateDurationType & ((duration: Duration) => Duration)
  24. interface Duration {
  25. new (input: string | number | object, unit?: string, locale?: string): Duration
  26. clone(): Duration
  27. humanize(withSuffix?: boolean): string
  28. milliseconds(): number
  29. asMilliseconds(): number
  30. seconds(): number
  31. asSeconds(): number
  32. minutes(): number
  33. asMinutes(): number
  34. hours(): number
  35. asHours(): number
  36. days(): number
  37. asDays(): number
  38. weeks(): number
  39. asWeeks(): number
  40. months(): number
  41. asMonths(): number
  42. years(): number
  43. asYears(): number
  44. as(unit: DurationUnitType): number
  45. get(unit: DurationUnitType): number
  46. add: AddDurationType
  47. subtract: AddDurationType
  48. toJSON(): string
  49. toISOString(): string
  50. format(formatStr?: string): string
  51. locale(locale: string): Duration
  52. }
  53. }
  54. declare module 'dayjs' {
  55. interface Dayjs {
  56. add(duration: plugin.Duration): Dayjs
  57. subtract(duration: plugin.Duration): Dayjs
  58. }
  59. /**
  60. * @param time If unit is not present, time treated as number of milliseconds
  61. */
  62. export const duration: plugin.CreateDurationType;
  63. export function isDuration(d: any): d is plugin.Duration
  64. }