@dative-gpi/foundation-shared-services 1.0.190-feat-time-normalization-2 → 1.0.190-feat-time-normalization-4

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.
@@ -5,4 +5,5 @@ export * from "./useDateFormat";
5
5
  export * from "./useFiles";
6
6
  export * from "./useFoundationShared";
7
7
  export * from "./useRouting";
8
- export * from "./useDateExpression";
8
+ export * from "./useDateExpression";
9
+ export * from "./useTimeDuration";
@@ -0,0 +1,48 @@
1
+ import { TimeComparisonType } from "@dative-gpi/foundation-shared-domain/enums";
2
+ import { useDateExpression } from "@dative-gpi/foundation-shared-services/composables";
3
+
4
+ const { convert } = useDateExpression();
5
+
6
+ export const useTimeDuration = () => {
7
+ const getPeriodDuration = (periodStart: string | undefined, periodEnd: string | undefined): number => {
8
+ if (!periodStart || !periodEnd) {
9
+ return 0;
10
+ }
11
+
12
+ const startTimestamp = convert(periodStart);
13
+ const endTimestamp = convert(periodEnd);
14
+
15
+ if (isNaN(startTimestamp) || isNaN(endTimestamp)) {
16
+ return 0;
17
+ }
18
+
19
+ const durationMs = endTimestamp - startTimestamp;
20
+ if (durationMs <= 0) {
21
+ return 0;
22
+ }
23
+
24
+ return durationMs;
25
+ };
26
+
27
+ const getTimeframeDuration = (timeframe: TimeComparisonType, periodStart: string | null = null, periodEnd: string | null = null): number => {
28
+ switch (timeframe) {
29
+ case TimeComparisonType.SinceReference:
30
+ return getPeriodDuration(periodStart ?? undefined, periodEnd ?? undefined);
31
+ case TimeComparisonType.Daily:
32
+ return 1000 * 60 * 60 * 24;
33
+ case TimeComparisonType.Weekly:
34
+ return 1000 * 60 * 60 * 24 * 7;
35
+ case TimeComparisonType.Monthly:
36
+ return 1000 * 60 * 60 * 24 * 30;
37
+ case TimeComparisonType.Yearly:
38
+ return 1000 * 60 * 60 * 24 * 365;
39
+ default:
40
+ return 0;
41
+ }
42
+ };
43
+
44
+ return {
45
+ getPeriodDuration,
46
+ getTimeframeDuration,
47
+ };
48
+ }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "url": "https://github.com/Dative-GPI/foundation-shared-ui.git"
5
5
  },
6
6
  "sideEffects": false,
7
- "version": "1.0.190-feat-time-normalization-2",
7
+ "version": "1.0.190-feat-time-normalization-4",
8
8
  "description": "",
9
9
  "publishConfig": {
10
10
  "access": "public"
@@ -13,7 +13,7 @@
13
13
  "author": "",
14
14
  "license": "ISC",
15
15
  "dependencies": {
16
- "@dative-gpi/foundation-shared-domain": "1.0.190-feat-time-normalization-2",
16
+ "@dative-gpi/foundation-shared-domain": "1.0.190-feat-time-normalization-4",
17
17
  "@vueuse/core": "^14.0.0"
18
18
  },
19
19
  "peerDependencies": {
@@ -22,5 +22,5 @@
22
22
  "vue": "^3.4.38",
23
23
  "vue-router": "^4.3.0"
24
24
  },
25
- "gitHead": "63de5aadeba94007714cb8d44a6a4561e69678a3"
25
+ "gitHead": "94b8ab509d32ca487dfd9430f4fde84b62f5046e"
26
26
  }