namirasoft-cost 1.4.19 → 1.4.20

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.
Files changed (54) hide show
  1. package/.ns-sdkg-dir-deep +2 -2
  2. package/.ns-sdkg-file-keep +7 -7
  3. package/dist/TimeUtil.js +18 -11
  4. package/dist/TimeUtil.js.map +1 -1
  5. package/package.json +27 -27
  6. package/src/NamirasoftCostServer.ts +56 -56
  7. package/src/NamirasoftCostServerBase.ts +29 -29
  8. package/src/NamirasoftCostServerBillWatchAWS.ts +46 -46
  9. package/src/NamirasoftCostServerBillWatchAzure.ts +46 -46
  10. package/src/NamirasoftCostServerBillWatchGCP.ts +46 -46
  11. package/src/NamirasoftCostServerCost.ts +49 -49
  12. package/src/NamirasoftCostServerFieldCategory.ts +46 -46
  13. package/src/NamirasoftCostServerFieldField.ts +46 -46
  14. package/src/NamirasoftCostServerHealthz.ts +35 -35
  15. package/src/NamirasoftCostServerMetrics.ts +35 -35
  16. package/src/NamirasoftCostServerValue.ts +36 -36
  17. package/src/TimeUtil.ts +66 -56
  18. package/src/command/BillWatchAWSCommand.ts +33 -33
  19. package/src/command/BillWatchAWSEstimationCommand.ts +82 -82
  20. package/src/command/BillWatchAWS_CreateForCommand.ts +100 -100
  21. package/src/command/BillWatchAzureCommand.ts +33 -33
  22. package/src/command/BillWatchAzureEstimationCommand.ts +82 -82
  23. package/src/command/BillWatchAzure_CreateForCommand.ts +100 -100
  24. package/src/command/BillWatchGCPCommand.ts +33 -33
  25. package/src/command/BillWatchGCPEstimationCommand.ts +82 -82
  26. package/src/command/BillWatchGCP_CreateForCommand.ts +100 -100
  27. package/src/command/CostCommand.ts +33 -33
  28. package/src/command/CostListCommand.ts +44 -44
  29. package/src/command/Cost_CreateForCommand.ts +181 -181
  30. package/src/command/FieldCategoryCommand.ts +33 -33
  31. package/src/command/FieldCategoryEstimationCommand.ts +82 -82
  32. package/src/command/FieldCategory_CreateForCommand.ts +100 -100
  33. package/src/command/FieldFieldCommand.ts +33 -33
  34. package/src/command/FieldFieldEstimationCommand.ts +82 -82
  35. package/src/command/FieldField_CreateForCommand.ts +100 -100
  36. package/src/command/HealthzCommand.ts +31 -31
  37. package/src/command/HealthzGetCommand.ts +44 -44
  38. package/src/command/MetricsCommand.ts +31 -31
  39. package/src/command/MetricsGetCommand.ts +44 -44
  40. package/src/command/ValueCommand.ts +31 -31
  41. package/src/command/ValueListCommand.ts +44 -44
  42. package/src/command/cli.ts +48 -48
  43. package/src/enum/TrialUnit.ts +5 -5
  44. package/src/index.ts +66 -66
  45. package/src/meta/CostMetaTable.ts +81 -81
  46. package/src/meta/NamirasoftCostMetaDatabase.ts +50 -50
  47. package/src/row/CostCreateRow.ts +37 -37
  48. package/src/row/CostRow.ts +40 -40
  49. package/src/type/Estimation.ts +6 -6
  50. package/src/type/EstimationRow.ts +9 -9
  51. package/src/type/EstimationUsage.ts +5 -5
  52. package/src/type/Period.ts +4 -4
  53. package/src/type/Trial.ts +6 -6
  54. package/src/type/TrialDuration.ts +6 -6
@@ -1,50 +1,50 @@
1
- /****************************************************************/
2
- /* */
3
- /* This is an Auto-Generated File */
4
- /* Made By */
5
- /* Namirasoft SDK Generator NPM Package */
6
- /* */
7
- /****************************************************************/
8
- /****************************************************************/
9
- /* */
10
- /* Please do not make any change to this file */
11
- /* If any change is required, ns-sdkg command must be used */
12
- /* */
13
- /****************************************************************/
14
- /****************************************************************/
15
- /* */
16
- /* Namira Software Corporation */
17
- /* https://namirasoft.com */
18
- /* */
19
- /****************************************************************/
20
-
21
- import { CostCreateRow } from "./row/CostCreateRow";
22
- import { CostRow } from "./row/CostRow";
23
- import { FilterItem } from "namirasoft-core";
24
- import { NamirasoftCostServer } from "./NamirasoftCostServer";
25
- import { NamirasoftCostServerBase } from "./NamirasoftCostServerBase";
26
- import { SortItem } from "namirasoft-core";
27
-
28
- export class NamirasoftCostServerCost extends NamirasoftCostServerBase
29
- {
30
- constructor(server: NamirasoftCostServer)
31
- {
32
- super(server);
33
- this.List = this.List.bind(this);
34
- this._CreateFor = this._CreateFor.bind(this);
35
- }
36
- async List(filters: FilterItem[] | null, page: (number | null), size: (number | null), sorts: SortItem[]): Promise<{ rows: CostRow[], count: number }>
37
- {
38
- let filters_string_value: string = FilterItem.stringify(filters);
39
- let sorts_string_value: string = SortItem.stringify(sorts);
40
- let path = `/cost/list`;
41
- let { data } = await this.server._get<{ rows: CostRow[], count: number }>(path, { filters: filters_string_value, page, size, sorts: sorts_string_value });
42
- return data;
43
- }
44
- async _CreateFor(user_id: string, body: CostCreateRow): Promise<CostRow>
45
- {
46
- let path = `/application/user/${user_id}/cost`;
47
- let { data } = await this.server._post<CostRow>(path, {}, body);
48
- return data;
49
- }
1
+ /****************************************************************/
2
+ /* */
3
+ /* This is an Auto-Generated File */
4
+ /* Made By */
5
+ /* Namirasoft SDK Generator NPM Package */
6
+ /* */
7
+ /****************************************************************/
8
+ /****************************************************************/
9
+ /* */
10
+ /* Please do not make any change to this file */
11
+ /* If any change is required, ns-sdkg command must be used */
12
+ /* */
13
+ /****************************************************************/
14
+ /****************************************************************/
15
+ /* */
16
+ /* Namira Software Corporation */
17
+ /* https://namirasoft.com */
18
+ /* */
19
+ /****************************************************************/
20
+
21
+ import { CostCreateRow } from "./row/CostCreateRow";
22
+ import { CostRow } from "./row/CostRow";
23
+ import { FilterItem } from "namirasoft-core";
24
+ import { NamirasoftCostServer } from "./NamirasoftCostServer";
25
+ import { NamirasoftCostServerBase } from "./NamirasoftCostServerBase";
26
+ import { SortItem } from "namirasoft-core";
27
+
28
+ export class NamirasoftCostServerCost extends NamirasoftCostServerBase
29
+ {
30
+ constructor(server: NamirasoftCostServer)
31
+ {
32
+ super(server);
33
+ this.List = this.List.bind(this);
34
+ this._CreateFor = this._CreateFor.bind(this);
35
+ }
36
+ async List(filters: FilterItem[] | null, page: (number | null), size: (number | null), sorts: SortItem[]): Promise<{ rows: CostRow[], count: number }>
37
+ {
38
+ let filters_string_value: string = FilterItem.stringify(filters);
39
+ let sorts_string_value: string = SortItem.stringify(sorts);
40
+ let path = `/cost/list`;
41
+ let { data } = await this.server._get<{ rows: CostRow[], count: number }>(path, { filters: filters_string_value, page, size, sorts: sorts_string_value });
42
+ return data;
43
+ }
44
+ async _CreateFor(user_id: string, body: CostCreateRow): Promise<CostRow>
45
+ {
46
+ let path = `/application/user/${user_id}/cost`;
47
+ let { data } = await this.server._post<CostRow>(path, {}, body);
48
+ return data;
49
+ }
50
50
  };
@@ -1,47 +1,47 @@
1
- /****************************************************************/
2
- /* */
3
- /* This is an Auto-Generated File */
4
- /* Made By */
5
- /* Namirasoft SDK Generator NPM Package */
6
- /* */
7
- /****************************************************************/
8
- /****************************************************************/
9
- /* */
10
- /* Please do not make any change to this file */
11
- /* If any change is required, ns-sdkg command must be used */
12
- /* */
13
- /****************************************************************/
14
- /****************************************************************/
15
- /* */
16
- /* Namira Software Corporation */
17
- /* https://namirasoft.com */
18
- /* */
19
- /****************************************************************/
20
-
21
- import { CostRow } from "./row/CostRow";
22
- import { Estimation } from "./type/Estimation";
23
- import { NamirasoftCostServer } from "./NamirasoftCostServer";
24
- import { NamirasoftCostServerBase } from "./NamirasoftCostServerBase";
25
- import { Period } from "./type/Period";
26
-
27
- export class NamirasoftCostServerFieldCategory extends NamirasoftCostServerBase
28
- {
29
- constructor(server: NamirasoftCostServer)
30
- {
31
- super(server);
32
- this.Estimation = this.Estimation.bind(this);
33
- this._CreateFor = this._CreateFor.bind(this);
34
- }
35
- async Estimation(body: { first_entity_created_at: (Date | null), row_number: number, active: boolean, period: Period }): Promise<Estimation>
36
- {
37
- let path = `/estimation/field/category`;
38
- let { data } = await this.server._post<Estimation>(path, {}, body);
39
- return data;
40
- }
41
- async _CreateFor(user_id: string, body: { first_entity_created_at: (Date | null), row_number: number, active: boolean, period: Period, workspace_id: string, resource_id: string }): Promise<CostRow>
42
- {
43
- let path = `/application/user/${user_id}/cost/field/category`;
44
- let { data } = await this.server._post<CostRow>(path, {}, body);
45
- return data;
46
- }
1
+ /****************************************************************/
2
+ /* */
3
+ /* This is an Auto-Generated File */
4
+ /* Made By */
5
+ /* Namirasoft SDK Generator NPM Package */
6
+ /* */
7
+ /****************************************************************/
8
+ /****************************************************************/
9
+ /* */
10
+ /* Please do not make any change to this file */
11
+ /* If any change is required, ns-sdkg command must be used */
12
+ /* */
13
+ /****************************************************************/
14
+ /****************************************************************/
15
+ /* */
16
+ /* Namira Software Corporation */
17
+ /* https://namirasoft.com */
18
+ /* */
19
+ /****************************************************************/
20
+
21
+ import { CostRow } from "./row/CostRow";
22
+ import { Estimation } from "./type/Estimation";
23
+ import { NamirasoftCostServer } from "./NamirasoftCostServer";
24
+ import { NamirasoftCostServerBase } from "./NamirasoftCostServerBase";
25
+ import { Period } from "./type/Period";
26
+
27
+ export class NamirasoftCostServerFieldCategory extends NamirasoftCostServerBase
28
+ {
29
+ constructor(server: NamirasoftCostServer)
30
+ {
31
+ super(server);
32
+ this.Estimation = this.Estimation.bind(this);
33
+ this._CreateFor = this._CreateFor.bind(this);
34
+ }
35
+ async Estimation(body: { first_entity_created_at: (Date | null), row_number: number, active: boolean, period: Period }): Promise<Estimation>
36
+ {
37
+ let path = `/estimation/field/category`;
38
+ let { data } = await this.server._post<Estimation>(path, {}, body);
39
+ return data;
40
+ }
41
+ async _CreateFor(user_id: string, body: { first_entity_created_at: (Date | null), row_number: number, active: boolean, period: Period, workspace_id: string, resource_id: string }): Promise<CostRow>
42
+ {
43
+ let path = `/application/user/${user_id}/cost/field/category`;
44
+ let { data } = await this.server._post<CostRow>(path, {}, body);
45
+ return data;
46
+ }
47
47
  };
@@ -1,47 +1,47 @@
1
- /****************************************************************/
2
- /* */
3
- /* This is an Auto-Generated File */
4
- /* Made By */
5
- /* Namirasoft SDK Generator NPM Package */
6
- /* */
7
- /****************************************************************/
8
- /****************************************************************/
9
- /* */
10
- /* Please do not make any change to this file */
11
- /* If any change is required, ns-sdkg command must be used */
12
- /* */
13
- /****************************************************************/
14
- /****************************************************************/
15
- /* */
16
- /* Namira Software Corporation */
17
- /* https://namirasoft.com */
18
- /* */
19
- /****************************************************************/
20
-
21
- import { CostRow } from "./row/CostRow";
22
- import { Estimation } from "./type/Estimation";
23
- import { NamirasoftCostServer } from "./NamirasoftCostServer";
24
- import { NamirasoftCostServerBase } from "./NamirasoftCostServerBase";
25
- import { Period } from "./type/Period";
26
-
27
- export class NamirasoftCostServerFieldField extends NamirasoftCostServerBase
28
- {
29
- constructor(server: NamirasoftCostServer)
30
- {
31
- super(server);
32
- this.Estimation = this.Estimation.bind(this);
33
- this._CreateFor = this._CreateFor.bind(this);
34
- }
35
- async Estimation(body: { first_entity_created_at: (Date | null), row_number: number, active: boolean, period: Period }): Promise<Estimation>
36
- {
37
- let path = `/estimation/field/field`;
38
- let { data } = await this.server._post<Estimation>(path, {}, body);
39
- return data;
40
- }
41
- async _CreateFor(user_id: string, body: { first_entity_created_at: (Date | null), row_number: number, active: boolean, period: Period, workspace_id: string, resource_id: string }): Promise<CostRow>
42
- {
43
- let path = `/application/user/${user_id}/cost/field/field`;
44
- let { data } = await this.server._post<CostRow>(path, {}, body);
45
- return data;
46
- }
1
+ /****************************************************************/
2
+ /* */
3
+ /* This is an Auto-Generated File */
4
+ /* Made By */
5
+ /* Namirasoft SDK Generator NPM Package */
6
+ /* */
7
+ /****************************************************************/
8
+ /****************************************************************/
9
+ /* */
10
+ /* Please do not make any change to this file */
11
+ /* If any change is required, ns-sdkg command must be used */
12
+ /* */
13
+ /****************************************************************/
14
+ /****************************************************************/
15
+ /* */
16
+ /* Namira Software Corporation */
17
+ /* https://namirasoft.com */
18
+ /* */
19
+ /****************************************************************/
20
+
21
+ import { CostRow } from "./row/CostRow";
22
+ import { Estimation } from "./type/Estimation";
23
+ import { NamirasoftCostServer } from "./NamirasoftCostServer";
24
+ import { NamirasoftCostServerBase } from "./NamirasoftCostServerBase";
25
+ import { Period } from "./type/Period";
26
+
27
+ export class NamirasoftCostServerFieldField extends NamirasoftCostServerBase
28
+ {
29
+ constructor(server: NamirasoftCostServer)
30
+ {
31
+ super(server);
32
+ this.Estimation = this.Estimation.bind(this);
33
+ this._CreateFor = this._CreateFor.bind(this);
34
+ }
35
+ async Estimation(body: { first_entity_created_at: (Date | null), row_number: number, active: boolean, period: Period }): Promise<Estimation>
36
+ {
37
+ let path = `/estimation/field/field`;
38
+ let { data } = await this.server._post<Estimation>(path, {}, body);
39
+ return data;
40
+ }
41
+ async _CreateFor(user_id: string, body: { first_entity_created_at: (Date | null), row_number: number, active: boolean, period: Period, workspace_id: string, resource_id: string }): Promise<CostRow>
42
+ {
43
+ let path = `/application/user/${user_id}/cost/field/field`;
44
+ let { data } = await this.server._post<CostRow>(path, {}, body);
45
+ return data;
46
+ }
47
47
  };
@@ -1,36 +1,36 @@
1
- /****************************************************************/
2
- /* */
3
- /* This is an Auto-Generated File */
4
- /* Made By */
5
- /* Namirasoft SDK Generator NPM Package */
6
- /* */
7
- /****************************************************************/
8
- /****************************************************************/
9
- /* */
10
- /* Please do not make any change to this file */
11
- /* If any change is required, ns-sdkg command must be used */
12
- /* */
13
- /****************************************************************/
14
- /****************************************************************/
15
- /* */
16
- /* Namira Software Corporation */
17
- /* https://namirasoft.com */
18
- /* */
19
- /****************************************************************/
20
-
21
- import { NamirasoftCostServer } from "./NamirasoftCostServer";
22
- import { NamirasoftCostServerBase } from "./NamirasoftCostServerBase";
23
-
24
- export class NamirasoftCostServerHealthz extends NamirasoftCostServerBase
25
- {
26
- constructor(server: NamirasoftCostServer)
27
- {
28
- super(server);
29
- this.Get = this.Get.bind(this);
30
- }
31
- async Get(): Promise<void>
32
- {
33
- let path = `/healthz`;
34
- await this.server._get<void>(path, {});
35
- }
1
+ /****************************************************************/
2
+ /* */
3
+ /* This is an Auto-Generated File */
4
+ /* Made By */
5
+ /* Namirasoft SDK Generator NPM Package */
6
+ /* */
7
+ /****************************************************************/
8
+ /****************************************************************/
9
+ /* */
10
+ /* Please do not make any change to this file */
11
+ /* If any change is required, ns-sdkg command must be used */
12
+ /* */
13
+ /****************************************************************/
14
+ /****************************************************************/
15
+ /* */
16
+ /* Namira Software Corporation */
17
+ /* https://namirasoft.com */
18
+ /* */
19
+ /****************************************************************/
20
+
21
+ import { NamirasoftCostServer } from "./NamirasoftCostServer";
22
+ import { NamirasoftCostServerBase } from "./NamirasoftCostServerBase";
23
+
24
+ export class NamirasoftCostServerHealthz extends NamirasoftCostServerBase
25
+ {
26
+ constructor(server: NamirasoftCostServer)
27
+ {
28
+ super(server);
29
+ this.Get = this.Get.bind(this);
30
+ }
31
+ async Get(): Promise<void>
32
+ {
33
+ let path = `/healthz`;
34
+ await this.server._get<void>(path, {});
35
+ }
36
36
  };
@@ -1,36 +1,36 @@
1
- /****************************************************************/
2
- /* */
3
- /* This is an Auto-Generated File */
4
- /* Made By */
5
- /* Namirasoft SDK Generator NPM Package */
6
- /* */
7
- /****************************************************************/
8
- /****************************************************************/
9
- /* */
10
- /* Please do not make any change to this file */
11
- /* If any change is required, ns-sdkg command must be used */
12
- /* */
13
- /****************************************************************/
14
- /****************************************************************/
15
- /* */
16
- /* Namira Software Corporation */
17
- /* https://namirasoft.com */
18
- /* */
19
- /****************************************************************/
20
-
21
- import { NamirasoftCostServer } from "./NamirasoftCostServer";
22
- import { NamirasoftCostServerBase } from "./NamirasoftCostServerBase";
23
-
24
- export class NamirasoftCostServerMetrics extends NamirasoftCostServerBase
25
- {
26
- constructor(server: NamirasoftCostServer)
27
- {
28
- super(server);
29
- this.Get = this.Get.bind(this);
30
- }
31
- async Get(): Promise<void>
32
- {
33
- let path = `/metrics`;
34
- await this.server._get<void>(path, {});
35
- }
1
+ /****************************************************************/
2
+ /* */
3
+ /* This is an Auto-Generated File */
4
+ /* Made By */
5
+ /* Namirasoft SDK Generator NPM Package */
6
+ /* */
7
+ /****************************************************************/
8
+ /****************************************************************/
9
+ /* */
10
+ /* Please do not make any change to this file */
11
+ /* If any change is required, ns-sdkg command must be used */
12
+ /* */
13
+ /****************************************************************/
14
+ /****************************************************************/
15
+ /* */
16
+ /* Namira Software Corporation */
17
+ /* https://namirasoft.com */
18
+ /* */
19
+ /****************************************************************/
20
+
21
+ import { NamirasoftCostServer } from "./NamirasoftCostServer";
22
+ import { NamirasoftCostServerBase } from "./NamirasoftCostServerBase";
23
+
24
+ export class NamirasoftCostServerMetrics extends NamirasoftCostServerBase
25
+ {
26
+ constructor(server: NamirasoftCostServer)
27
+ {
28
+ super(server);
29
+ this.Get = this.Get.bind(this);
30
+ }
31
+ async Get(): Promise<void>
32
+ {
33
+ let path = `/metrics`;
34
+ await this.server._get<void>(path, {});
35
+ }
36
36
  };
@@ -1,37 +1,37 @@
1
- /****************************************************************/
2
- /* */
3
- /* This is an Auto-Generated File */
4
- /* Made By */
5
- /* Namirasoft SDK Generator NPM Package */
6
- /* */
7
- /****************************************************************/
8
- /****************************************************************/
9
- /* */
10
- /* Please do not make any change to this file */
11
- /* If any change is required, ns-sdkg command must be used */
12
- /* */
13
- /****************************************************************/
14
- /****************************************************************/
15
- /* */
16
- /* Namira Software Corporation */
17
- /* https://namirasoft.com */
18
- /* */
19
- /****************************************************************/
20
-
21
- import { NamirasoftCostServer } from "./NamirasoftCostServer";
22
- import { NamirasoftCostServerBase } from "./NamirasoftCostServerBase";
23
-
24
- export class NamirasoftCostServerValue extends NamirasoftCostServerBase
25
- {
26
- constructor(server: NamirasoftCostServer)
27
- {
28
- super(server);
29
- this.List = this.List.bind(this);
30
- }
31
- async List(table: string, column: string, search: (string | null), field_id: (string | null), limit: (number | null)): Promise<string[]>
32
- {
33
- let path = `/value/list/${table}/${column}`;
34
- let { data } = await this.server._get<string[]>(path, { search, field_id, limit });
35
- return data;
36
- }
1
+ /****************************************************************/
2
+ /* */
3
+ /* This is an Auto-Generated File */
4
+ /* Made By */
5
+ /* Namirasoft SDK Generator NPM Package */
6
+ /* */
7
+ /****************************************************************/
8
+ /****************************************************************/
9
+ /* */
10
+ /* Please do not make any change to this file */
11
+ /* If any change is required, ns-sdkg command must be used */
12
+ /* */
13
+ /****************************************************************/
14
+ /****************************************************************/
15
+ /* */
16
+ /* Namira Software Corporation */
17
+ /* https://namirasoft.com */
18
+ /* */
19
+ /****************************************************************/
20
+
21
+ import { NamirasoftCostServer } from "./NamirasoftCostServer";
22
+ import { NamirasoftCostServerBase } from "./NamirasoftCostServerBase";
23
+
24
+ export class NamirasoftCostServerValue extends NamirasoftCostServerBase
25
+ {
26
+ constructor(server: NamirasoftCostServer)
27
+ {
28
+ super(server);
29
+ this.List = this.List.bind(this);
30
+ }
31
+ async List(table: string, column: string, search: (string | null), field_id: (string | null), limit: (number | null)): Promise<string[]>
32
+ {
33
+ let path = `/value/list/${table}/${column}`;
34
+ let { data } = await this.server._get<string[]>(path, { search, field_id, limit });
35
+ return data;
36
+ }
37
37
  };
package/src/TimeUtil.ts CHANGED
@@ -1,57 +1,67 @@
1
- import { TimeOperation, TimeUnitOperation } from "namirasoft-core";
2
- import { Trial } from "./type/Trial";
3
- import { Period } from "./type/Period";
4
-
5
- export class TimeUtil
6
- {
7
- static trialEndsAt(trial: Trial)
8
- {
9
- return TimeUnitOperation.later(trial.duration.value, trial.duration.unit as any, trial.started_at);
10
- }
11
- static isTrial(trial: Trial, date: Date)
12
- {
13
- return date <= TimeUtil.trialEndsAt(trial);
14
- }
15
- static async loopHourly(trial: Trial | null, period: Period, estimate_hour: (period: Period, trial: boolean) => Promise<void>): Promise<void>
16
- {
17
- if (period.end <= period.start)
18
- return;
19
-
20
- let trial_ends_at: Date | null = null;
21
- if (trial)
22
- trial_ends_at = TimeUtil.trialEndsAt(trial);
23
-
24
- let start = period.start;
25
- let end = null;
26
-
27
- do
28
- {
29
- let next_start = TimeOperation.hoursLater(1, start);
30
- next_start.setMilliseconds(0);
31
- next_start.setSeconds(0);
32
- next_start.setMinutes(0);
33
- if (period.end < next_start)
34
- next_start = period.end;
35
- end = TimeOperation.secondsAgo(1, next_start);
36
- if (trial_ends_at)
37
- {
38
- if (trial_ends_at < period.start)
39
- await estimate_hour({ start, end }, false);
40
- else if (trial_ends_at <= period.end)
41
- {
42
- let trial_ends_at_e = TimeOperation.secondsAgo(1, trial_ends_at);
43
- let trial_ends_at_s = trial_ends_at;
44
- if (start < trial_ends_at_e)
45
- await estimate_hour({ start, end: trial_ends_at_e }, true);
46
- await estimate_hour({ start: trial_ends_at_s, end }, false);
47
- }
48
- else if (period.end < trial_ends_at)
49
- await estimate_hour({ start: period.start, end: trial_ends_at }, true);
50
- }
51
- else
52
- await estimate_hour({ start, end }, false);
53
- start = next_start;
54
- }
55
- while (end < period.end)
56
- }
1
+ import { TimeOperation, TimeUnitOperation } from "namirasoft-core";
2
+ import { Trial } from "./type/Trial";
3
+ import { Period } from "./type/Period";
4
+
5
+ export class TimeUtil
6
+ {
7
+ static trialEndsAt(trial: Trial)
8
+ {
9
+ return TimeUnitOperation.later(trial.duration.value, trial.duration.unit as any, trial.started_at);
10
+ }
11
+ static isTrial(trial: Trial, date: Date)
12
+ {
13
+ return date <= TimeUtil.trialEndsAt(trial);
14
+ }
15
+ static async loopHourly(trial: Trial | null, period: Period, estimate_hour: (period: Period, trial: boolean) => Promise<void>): Promise<void>
16
+ {
17
+ if (period.end <= period.start)
18
+ return;
19
+
20
+ let pre_estimate_hour = async (period: Period, trial: boolean) =>
21
+ {
22
+ if (period.end <= period.start)
23
+ return;
24
+ return await estimate_hour(period, trial);
25
+ }
26
+
27
+ let trial_ends_at: Date | null = null;
28
+ if (trial)
29
+ trial_ends_at = TimeUtil.trialEndsAt(trial);
30
+
31
+ let start = period.start;
32
+ let end = null;
33
+
34
+ do
35
+ {
36
+ let next_start = TimeOperation.hoursLater(1, start);
37
+ next_start.setMilliseconds(0);
38
+ next_start.setSeconds(0);
39
+ next_start.setMinutes(0);
40
+ if (period.end < next_start)
41
+ {
42
+ next_start = period.end;
43
+ end = period.end;
44
+ }
45
+ else
46
+ end = TimeOperation.secondsAgo(1, next_start);
47
+ if (trial_ends_at)
48
+ {
49
+ if (trial_ends_at < start)
50
+ await pre_estimate_hour({ start, end }, false);
51
+ else if (trial_ends_at <= end)
52
+ {
53
+ let trial_ends_at_e = TimeOperation.secondsAgo(1, trial_ends_at);
54
+ let trial_ends_at_s = trial_ends_at;
55
+ await pre_estimate_hour({ start, end: trial_ends_at_e }, true);
56
+ await pre_estimate_hour({ start: trial_ends_at_s, end }, false);
57
+ }
58
+ else if (end < trial_ends_at)
59
+ await pre_estimate_hour({ start: period.start, end }, true);
60
+ }
61
+ else
62
+ await pre_estimate_hour({ start, end }, false);
63
+ start = next_start;
64
+ }
65
+ while (end < period.end)
66
+ }
57
67
  }