1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.extractTime = void 0;
|
4 | const MIN_MS = 60 * 1000;
|
5 | const HR_MS = MIN_MS * 60;
|
6 | const DAY_MS = HR_MS * 24;
|
7 | const ZERO = { days: 0, hours: 0, milliseconds: 0, minutes: 0, seconds: 0 };
|
8 |
|
9 | function add(a, b) {
|
10 | return {
|
11 | days: (a.days || 0) + b.days,
|
12 | hours: (a.hours || 0) + b.hours,
|
13 | milliseconds: (a.milliseconds || 0) + b.milliseconds,
|
14 | minutes: (a.minutes || 0) + b.minutes,
|
15 | seconds: (a.seconds || 0) + b.seconds
|
16 | };
|
17 | }
|
18 |
|
19 | function extractSecs(ms) {
|
20 | const s = ms / 1000;
|
21 | if (s < 60) {
|
22 | const seconds = ~~s;
|
23 | return add({ seconds }, extractTime(ms - (seconds * 1000)));
|
24 | }
|
25 | const m = s / 60;
|
26 | if (m < 60) {
|
27 | const minutes = ~~m;
|
28 | return add({ minutes }, extractTime(ms - (minutes * MIN_MS)));
|
29 | }
|
30 | const h = m / 60;
|
31 | if (h < 24) {
|
32 | const hours = ~~h;
|
33 | return add({ hours }, extractTime(ms - (hours * HR_MS)));
|
34 | }
|
35 | const days = ~~(h / 24);
|
36 | return add({ days }, extractTime(ms - (days * DAY_MS)));
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | function extractTime(milliseconds) {
|
51 | return !milliseconds
|
52 | ? ZERO
|
53 | : milliseconds < 1000
|
54 | ? add({ milliseconds }, ZERO)
|
55 | : extractSecs(milliseconds);
|
56 | }
|
57 | exports.extractTime = extractTime;
|