namirasoft-cost 1.4.11 → 1.4.12
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/dist/TimeUtil.d.ts +1 -1
- package/dist/TimeUtil.js +19 -16
- package/dist/TimeUtil.js.map +1 -1
- package/package.json +2 -2
- package/src/TimeUtil.ts +22 -19
package/dist/TimeUtil.d.ts
CHANGED
@@ -3,5 +3,5 @@ import { Period } from "./type/Period";
|
|
3
3
|
export declare class TimeUtil {
|
4
4
|
static trialEndsAt(trial: Trial): Date;
|
5
5
|
static isTrial(trial: Trial, date: Date): boolean;
|
6
|
-
static loopHourly(trial: Trial | null, period: Period, estimate_hour: (period: Period) => Promise<void>): Promise<void>;
|
6
|
+
static loopHourly(trial: Trial | null, period: Period, estimate_hour: (period: Period, trial: boolean) => Promise<void>): Promise<void>;
|
7
7
|
}
|
package/dist/TimeUtil.js
CHANGED
@@ -11,16 +11,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
12
|
exports.TimeUtil = void 0;
|
13
13
|
const namirasoft_core_1 = require("namirasoft-core");
|
14
|
-
const TrialUnit_1 = require("./enum/TrialUnit");
|
15
14
|
class TimeUtil {
|
16
15
|
static trialEndsAt(trial) {
|
17
|
-
|
18
|
-
return namirasoft_core_1.TimeOperation.daysLater(trial.duration.value, trial.started_at);
|
19
|
-
if (trial.duration.unit == TrialUnit_1.TrialUnit.Week)
|
20
|
-
return namirasoft_core_1.TimeOperation.daysLater(trial.duration.value * 7, trial.started_at);
|
21
|
-
if (trial.duration.unit == TrialUnit_1.TrialUnit.Month)
|
22
|
-
return namirasoft_core_1.TimeOperation.monthsLater(trial.duration.value, trial.started_at);
|
23
|
-
return trial.started_at;
|
16
|
+
return namirasoft_core_1.TimeUnitOperation.later(trial.duration.value, trial.duration.unit, trial.started_at);
|
24
17
|
}
|
25
18
|
static isTrial(trial, date) {
|
26
19
|
return date <= TimeUtil.trialEndsAt(trial);
|
@@ -29,13 +22,9 @@ class TimeUtil {
|
|
29
22
|
return __awaiter(this, void 0, void 0, function* () {
|
30
23
|
if (period.end <= period.start)
|
31
24
|
return;
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
return;
|
36
|
-
if (period.start <= ends_at)
|
37
|
-
period.start = ends_at;
|
38
|
-
}
|
25
|
+
let trial_ends_at = null;
|
26
|
+
if (trial)
|
27
|
+
trial_ends_at = TimeUtil.trialEndsAt(trial);
|
39
28
|
let start = period.start;
|
40
29
|
let end = null;
|
41
30
|
do {
|
@@ -45,7 +34,21 @@ class TimeUtil {
|
|
45
34
|
end.setMinutes(0);
|
46
35
|
if (period.end < end)
|
47
36
|
end = period.end;
|
48
|
-
|
37
|
+
if (trial_ends_at) {
|
38
|
+
if (trial_ends_at < period.start)
|
39
|
+
yield estimate_hour({ start, end }, false);
|
40
|
+
else if (trial_ends_at <= period.end) {
|
41
|
+
let trial_ends_at_e = namirasoft_core_1.TimeOperation.secondsAgo(1, trial_ends_at);
|
42
|
+
let trial_ends_at_s = trial_ends_at;
|
43
|
+
if (start < trial_ends_at_e)
|
44
|
+
yield estimate_hour({ start, end: trial_ends_at_e }, true);
|
45
|
+
yield estimate_hour({ start: trial_ends_at_s, end }, false);
|
46
|
+
}
|
47
|
+
else if (period.end < trial_ends_at)
|
48
|
+
yield estimate_hour({ start: period.start, end: trial_ends_at }, true);
|
49
|
+
}
|
50
|
+
else
|
51
|
+
yield estimate_hour({ start, end }, false);
|
49
52
|
start = end;
|
50
53
|
} while (end < period.end);
|
51
54
|
});
|
package/dist/TimeUtil.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"TimeUtil.js","sourceRoot":"","sources":["../src/TimeUtil.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
1
|
+
{"version":3,"file":"TimeUtil.js","sourceRoot":"","sources":["../src/TimeUtil.ts"],"names":[],"mappings":";;;;;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C;wBACG,IAAI,eAAe,GAAG,+BAAa,CAAC,UAAU,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC;wBACjE,IAAI,eAAe,GAAG,aAAa,CAAC;wBACpC,IAAI,KAAK,GAAG,eAAe;4BACvB,MAAM,aAAa,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,eAAe,EAAE,EAAE,IAAI,CAAC,CAAC;wBAC/D,MAAM,aAAa,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,EAAE,KAAK,CAAC,CAAC;oBAChE,CAAC;yBACI,IAAI,MAAM,CAAC,GAAG,GAAG,aAAa;wBAC/B,MAAM,aAAa,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,EAAE,IAAI,CAAC,CAAC;gBAC/E,CAAC;;oBAEG,MAAM,aAAa,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,KAAK,CAAC,CAAC;gBAC/C,KAAK,GAAG,GAAG,CAAC;YAChB,CAAC,QACM,GAAG,GAAG,MAAM,CAAC,GAAG,EAAC;QAC5B,CAAC;KAAA;CACJ;AAnDD,4BAmDC"}
|
package/package.json
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
"framework": "npm",
|
9
9
|
"application": "package",
|
10
10
|
"private": false,
|
11
|
-
"version": "1.4.
|
11
|
+
"version": "1.4.12",
|
12
12
|
"author": "Amir Abolhasani",
|
13
13
|
"license": "MIT",
|
14
14
|
"main": "./dist/index.js",
|
@@ -17,7 +17,7 @@
|
|
17
17
|
"build": ""
|
18
18
|
},
|
19
19
|
"dependencies": {
|
20
|
-
"namirasoft-core": "^1.4.
|
20
|
+
"namirasoft-core": "^1.4.79",
|
21
21
|
"namirasoft-site": "^1.4.39",
|
22
22
|
"namirasoft-node-cli": "^1.4.7",
|
23
23
|
"namirasoft-account": "^1.4.84"
|
package/src/TimeUtil.ts
CHANGED
@@ -1,37 +1,25 @@
|
|
1
|
-
import { TimeOperation } from "namirasoft-core";
|
1
|
+
import { TimeOperation, TimeUnitOperation } from "namirasoft-core";
|
2
2
|
import { Trial } from "./type/Trial";
|
3
3
|
import { Period } from "./type/Period";
|
4
|
-
import { TrialUnit } from "./enum/TrialUnit";
|
5
4
|
|
6
5
|
export class TimeUtil
|
7
6
|
{
|
8
7
|
static trialEndsAt(trial: Trial)
|
9
8
|
{
|
10
|
-
|
11
|
-
return TimeOperation.daysLater(trial.duration.value, trial.started_at);
|
12
|
-
if (trial.duration.unit == TrialUnit.Week)
|
13
|
-
return TimeOperation.daysLater(trial.duration.value * 7, trial.started_at);
|
14
|
-
if (trial.duration.unit == TrialUnit.Month)
|
15
|
-
return TimeOperation.monthsLater(trial.duration.value, trial.started_at);
|
16
|
-
return trial.started_at;
|
9
|
+
return TimeUnitOperation.later(trial.duration.value, trial.duration.unit as any, trial.started_at);
|
17
10
|
}
|
18
11
|
static isTrial(trial: Trial, date: Date)
|
19
12
|
{
|
20
13
|
return date <= TimeUtil.trialEndsAt(trial);
|
21
14
|
}
|
22
|
-
static async loopHourly(trial: Trial | null, period: Period, estimate_hour: (period: Period) => Promise<void>): Promise<void>
|
15
|
+
static async loopHourly(trial: Trial | null, period: Period, estimate_hour: (period: Period, trial: boolean) => Promise<void>): Promise<void>
|
23
16
|
{
|
24
17
|
if (period.end <= period.start)
|
25
18
|
return;
|
26
19
|
|
20
|
+
let trial_ends_at: Date | null = null;
|
27
21
|
if (trial)
|
28
|
-
|
29
|
-
let ends_at = TimeUtil.trialEndsAt(trial);
|
30
|
-
if (period.end <= ends_at)
|
31
|
-
return;
|
32
|
-
if (period.start <= ends_at)
|
33
|
-
period.start = ends_at;
|
34
|
-
}
|
22
|
+
trial_ends_at = TimeUtil.trialEndsAt(trial);
|
35
23
|
|
36
24
|
let start = period.start;
|
37
25
|
let end = null;
|
@@ -44,8 +32,23 @@ export class TimeUtil
|
|
44
32
|
end.setMinutes(0);
|
45
33
|
if (period.end < end)
|
46
34
|
end = period.end;
|
47
|
-
|
48
|
-
|
35
|
+
if (trial_ends_at)
|
36
|
+
{
|
37
|
+
if (trial_ends_at < period.start)
|
38
|
+
await estimate_hour({ start, end }, false);
|
39
|
+
else if (trial_ends_at <= period.end)
|
40
|
+
{
|
41
|
+
let trial_ends_at_e = TimeOperation.secondsAgo(1, trial_ends_at);
|
42
|
+
let trial_ends_at_s = trial_ends_at;
|
43
|
+
if (start < trial_ends_at_e)
|
44
|
+
await estimate_hour({ start, end: trial_ends_at_e }, true);
|
45
|
+
await estimate_hour({ start: trial_ends_at_s, end }, false);
|
46
|
+
}
|
47
|
+
else if (period.end < trial_ends_at)
|
48
|
+
await estimate_hour({ start: period.start, end: trial_ends_at }, true);
|
49
|
+
}
|
50
|
+
else
|
51
|
+
await estimate_hour({ start, end }, false);
|
49
52
|
start = end;
|
50
53
|
}
|
51
54
|
while (end < period.end)
|