UNPKG

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