@pvorona/duration 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +188 -0
- package/dist/lib/duration.d.ts +55 -0
- package/dist/lib/duration.d.ts.map +1 -0
- package/package.json +27 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
function i(t) {
|
|
2
|
+
return t !== null && typeof t == "object";
|
|
3
|
+
}
|
|
4
|
+
var f = /* @__PURE__ */ ((t) => (t[t.MilliSecond = 0] = "MilliSecond", t[t.Second = 1] = "Second", t[t.Minute = 2] = "Minute", t[t.Hour = 3] = "Hour", t[t.Day = 4] = "Day", t[t.Week = 5] = "Week", t[t.Month = 6] = "Month", t[t.Year = 7] = "Year", t))(f || {});
|
|
5
|
+
const e = /* @__PURE__ */ Symbol("milliSeconds"), u = {
|
|
6
|
+
0: 1,
|
|
7
|
+
1: 1e3,
|
|
8
|
+
2: 60 * 1e3,
|
|
9
|
+
3: 3600 * 1e3,
|
|
10
|
+
/** Note: Does not account for leap second */
|
|
11
|
+
4: 1440 * 60 * 1e3,
|
|
12
|
+
5: 10080 * 60 * 1e3,
|
|
13
|
+
/** Note: Does not account for leap year */
|
|
14
|
+
6: (
|
|
15
|
+
/* 30 days */
|
|
16
|
+
720 * 60 * 60 * 1e3
|
|
17
|
+
),
|
|
18
|
+
/** Note: Does not account for leap year */
|
|
19
|
+
7: (
|
|
20
|
+
/* 365.25 days */
|
|
21
|
+
365.25 * 24 * 60 * 60 * 1e3
|
|
22
|
+
)
|
|
23
|
+
}, a = {
|
|
24
|
+
[e]: 0,
|
|
25
|
+
isFinite: !1,
|
|
26
|
+
isInfinite: !1,
|
|
27
|
+
isInstant: !1,
|
|
28
|
+
to(t) {
|
|
29
|
+
return this[e] / u[t];
|
|
30
|
+
},
|
|
31
|
+
toMilliSeconds() {
|
|
32
|
+
return this.to(
|
|
33
|
+
0
|
|
34
|
+
/* MilliSecond */
|
|
35
|
+
);
|
|
36
|
+
},
|
|
37
|
+
toSeconds() {
|
|
38
|
+
return this.to(
|
|
39
|
+
1
|
|
40
|
+
/* Second */
|
|
41
|
+
);
|
|
42
|
+
},
|
|
43
|
+
toMinutes() {
|
|
44
|
+
return this.to(
|
|
45
|
+
2
|
|
46
|
+
/* Minute */
|
|
47
|
+
);
|
|
48
|
+
},
|
|
49
|
+
toHours() {
|
|
50
|
+
return this.to(
|
|
51
|
+
3
|
|
52
|
+
/* Hour */
|
|
53
|
+
);
|
|
54
|
+
},
|
|
55
|
+
toDays() {
|
|
56
|
+
return this.to(
|
|
57
|
+
4
|
|
58
|
+
/* Day */
|
|
59
|
+
);
|
|
60
|
+
},
|
|
61
|
+
toWeeks() {
|
|
62
|
+
return this.to(
|
|
63
|
+
5
|
|
64
|
+
/* Week */
|
|
65
|
+
);
|
|
66
|
+
},
|
|
67
|
+
toMonths() {
|
|
68
|
+
return this.to(
|
|
69
|
+
6
|
|
70
|
+
/* Month */
|
|
71
|
+
);
|
|
72
|
+
},
|
|
73
|
+
toYears() {
|
|
74
|
+
return this.to(
|
|
75
|
+
7
|
|
76
|
+
/* Year */
|
|
77
|
+
);
|
|
78
|
+
},
|
|
79
|
+
equals(t) {
|
|
80
|
+
return this[e] === t[e];
|
|
81
|
+
},
|
|
82
|
+
lessThan(t) {
|
|
83
|
+
return this[e] < t[e];
|
|
84
|
+
},
|
|
85
|
+
lessThanOrEqual(t) {
|
|
86
|
+
return this[e] <= t[e];
|
|
87
|
+
},
|
|
88
|
+
greaterThan(t) {
|
|
89
|
+
return this[e] > t[e];
|
|
90
|
+
},
|
|
91
|
+
greaterThanOrEqual(t) {
|
|
92
|
+
return this[e] >= t[e];
|
|
93
|
+
},
|
|
94
|
+
compare(t) {
|
|
95
|
+
return this.lessThan(t) ? -1 : this.greaterThan(t) ? 1 : 0;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
function s(t, r) {
|
|
99
|
+
const o = Object.create(a);
|
|
100
|
+
return o[e] = t * u[r], o.isFinite = t !== 1 / 0, o.isInfinite = t === 1 / 0, o.isInstant = t === 0, Object.freeze(o);
|
|
101
|
+
}
|
|
102
|
+
const n = Object.freeze({
|
|
103
|
+
of(t, r) {
|
|
104
|
+
return s(t, r);
|
|
105
|
+
},
|
|
106
|
+
ofMilliSeconds(t) {
|
|
107
|
+
return n.of(
|
|
108
|
+
t,
|
|
109
|
+
0
|
|
110
|
+
/* MilliSecond */
|
|
111
|
+
);
|
|
112
|
+
},
|
|
113
|
+
ofSeconds(t) {
|
|
114
|
+
return n.of(
|
|
115
|
+
t,
|
|
116
|
+
1
|
|
117
|
+
/* Second */
|
|
118
|
+
);
|
|
119
|
+
},
|
|
120
|
+
ofMinutes(t) {
|
|
121
|
+
return n.of(
|
|
122
|
+
t,
|
|
123
|
+
2
|
|
124
|
+
/* Minute */
|
|
125
|
+
);
|
|
126
|
+
},
|
|
127
|
+
ofHours(t) {
|
|
128
|
+
return n.of(
|
|
129
|
+
t,
|
|
130
|
+
3
|
|
131
|
+
/* Hour */
|
|
132
|
+
);
|
|
133
|
+
},
|
|
134
|
+
ofDays(t) {
|
|
135
|
+
return n.of(
|
|
136
|
+
t,
|
|
137
|
+
4
|
|
138
|
+
/* Day */
|
|
139
|
+
);
|
|
140
|
+
},
|
|
141
|
+
ofWeeks(t) {
|
|
142
|
+
return n.of(
|
|
143
|
+
t,
|
|
144
|
+
5
|
|
145
|
+
/* Week */
|
|
146
|
+
);
|
|
147
|
+
},
|
|
148
|
+
ofMonths(t) {
|
|
149
|
+
return n.of(
|
|
150
|
+
t,
|
|
151
|
+
6
|
|
152
|
+
/* Month */
|
|
153
|
+
);
|
|
154
|
+
},
|
|
155
|
+
ofYears(t) {
|
|
156
|
+
return n.of(
|
|
157
|
+
t,
|
|
158
|
+
7
|
|
159
|
+
/* Year */
|
|
160
|
+
);
|
|
161
|
+
},
|
|
162
|
+
between: (t, r) => n.of(
|
|
163
|
+
r.getTime() - t.getTime(),
|
|
164
|
+
0
|
|
165
|
+
/* MilliSecond */
|
|
166
|
+
),
|
|
167
|
+
since: (t) => n.between(t, /* @__PURE__ */ new Date()),
|
|
168
|
+
add: (t, r) => n.ofMilliSeconds(t[e] + r[e]),
|
|
169
|
+
subtract: (t, r) => n.ofMilliSeconds(t[e] - r[e]),
|
|
170
|
+
multiply: (t, r) => n.ofMilliSeconds(t[e] * r),
|
|
171
|
+
divide: (t, r) => n.ofMilliSeconds(t[e] / r),
|
|
172
|
+
ofInfinite: s(
|
|
173
|
+
1 / 0,
|
|
174
|
+
0
|
|
175
|
+
/* MilliSecond */
|
|
176
|
+
),
|
|
177
|
+
ofInstant: s(
|
|
178
|
+
0,
|
|
179
|
+
0
|
|
180
|
+
/* MilliSecond */
|
|
181
|
+
),
|
|
182
|
+
isDuration: (t) => i(t) && e in t,
|
|
183
|
+
isEqual: (t, r) => t[e] === r[e]
|
|
184
|
+
});
|
|
185
|
+
export {
|
|
186
|
+
n as Duration,
|
|
187
|
+
f as TimeUnit
|
|
188
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export declare const enum TimeUnit {
|
|
2
|
+
MilliSecond = 0,
|
|
3
|
+
Second = 1,
|
|
4
|
+
Minute = 2,
|
|
5
|
+
Hour = 3,
|
|
6
|
+
Day = 4,
|
|
7
|
+
Week = 5,
|
|
8
|
+
Month = 6,
|
|
9
|
+
Year = 7
|
|
10
|
+
}
|
|
11
|
+
declare const milliSeconds: unique symbol;
|
|
12
|
+
export type Duration = {
|
|
13
|
+
readonly [milliSeconds]: number;
|
|
14
|
+
readonly isFinite: boolean;
|
|
15
|
+
readonly isInfinite: boolean;
|
|
16
|
+
readonly isInstant: boolean;
|
|
17
|
+
to(unit: TimeUnit): number;
|
|
18
|
+
toMilliSeconds(): number;
|
|
19
|
+
toSeconds(): number;
|
|
20
|
+
toMinutes(): number;
|
|
21
|
+
toHours(): number;
|
|
22
|
+
toDays(): number;
|
|
23
|
+
toWeeks(): number;
|
|
24
|
+
toMonths(): number;
|
|
25
|
+
toYears(): number;
|
|
26
|
+
equals(other: Duration): boolean;
|
|
27
|
+
lessThan(other: Duration): boolean;
|
|
28
|
+
lessThanOrEqual(other: Duration): boolean;
|
|
29
|
+
greaterThan(other: Duration): boolean;
|
|
30
|
+
greaterThanOrEqual(other: Duration): boolean;
|
|
31
|
+
compare(other: Duration): -1 | 0 | 1;
|
|
32
|
+
};
|
|
33
|
+
export declare const Duration: Readonly<{
|
|
34
|
+
of(value: number, unit: TimeUnit): Duration;
|
|
35
|
+
ofMilliSeconds(value: number): Duration;
|
|
36
|
+
ofSeconds(value: number): Duration;
|
|
37
|
+
ofMinutes(value: number): Duration;
|
|
38
|
+
ofHours(value: number): Duration;
|
|
39
|
+
ofDays(value: number): Duration;
|
|
40
|
+
ofWeeks(value: number): Duration;
|
|
41
|
+
ofMonths(value: number): Duration;
|
|
42
|
+
ofYears(value: number): Duration;
|
|
43
|
+
between: (start: Date, end: Date) => Duration;
|
|
44
|
+
since: (start: Date) => Duration;
|
|
45
|
+
add: (a: Duration, b: Duration) => Duration;
|
|
46
|
+
subtract: (a: Duration, b: Duration) => Duration;
|
|
47
|
+
multiply: (a: Duration, b: number) => Duration;
|
|
48
|
+
divide: (a: Duration, b: number) => Duration;
|
|
49
|
+
ofInfinite: Duration;
|
|
50
|
+
ofInstant: Duration;
|
|
51
|
+
isDuration: (value: unknown) => value is Duration;
|
|
52
|
+
isEqual: (a: Duration, b: Duration) => boolean;
|
|
53
|
+
}>;
|
|
54
|
+
export {};
|
|
55
|
+
//# sourceMappingURL=duration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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AQ;0BAGrB,MAAM,GAAG,QAAQ;qBAGtB,MAAM,GAAG,QAAQ;qBAGjB,MAAM,GAAG,QAAQ;mBAGnB,MAAM,GAAG,QAAQ;kBAGlB,MAAM,GAAG,QAAQ;mBAGhB,MAAM,GAAG,QAAQ;oBAGhB,MAAM,GAAG,QAAQ;mBAGlB,MAAM,GAAG,QAAQ;qBAGf,IAAI,OAAO,IAAI,KAAG,QAAQ;mBAG5B,IAAI,KAAG,QAAQ;aAGrB,QAAQ,KAAK,QAAQ,KAAG,QAAQ;kBAG3B,QAAQ,KAAK,QAAQ,KAAG,QAAQ;kBAGhC,QAAQ,KAAK,MAAM,KAAG,QAAQ;gBAGhC,QAAQ,KAAK,MAAM,KAAG,QAAQ;;;wBAStB,OAAO,KAAG,KAAK,IAAI,QAAQ;iBAGlC,QAAQ,KAAK,QAAQ,KAAG,OAAO;EAG5C,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pvorona/duration",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./package.json": "./package.json",
|
|
10
|
+
".": {
|
|
11
|
+
"@pvorona/source": "./src/index.ts",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"!**/*.tsbuildinfo"
|
|
20
|
+
],
|
|
21
|
+
"nx": {
|
|
22
|
+
"name": "duration"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@pvorona/assert": "^0.0.1"
|
|
26
|
+
}
|
|
27
|
+
}
|