duration.d.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { PluginFunc } from 'dayjs'
  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' {
  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. }