index.d.ts 1.7 KB

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