@dative-gpi/foundation-shared-services 1.0.128-mountain-alpha → 1.0.128-remove-deprecated-scenario

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.
@@ -4,5 +4,4 @@ export * from "./app";
4
4
  export * from "./useDateFormat";
5
5
  export * from "./useFiles";
6
6
  export * from "./useFoundationShared";
7
- export * from "./useRouting";
8
- export * from "./useTermFieldDate";
7
+ export * from "./useRouting";
@@ -43,14 +43,6 @@ export const useDateFormat = () => {
43
43
  return date.toLocaleString(languageCode.value, { ...OPTIONS.dayMonthLongOnly, timeZone: timeZone.value });
44
44
  }
45
45
 
46
- const epochToDayMonthShortOnly = (value: number | null | undefined): string => {
47
- if (value == null || !isFinite(value)) {
48
- return "";
49
- }
50
- const date = new Date(value);
51
- return date.toLocaleString(languageCode.value, { ...OPTIONS.dayMonthShortOnly, timeZone: timeZone.value });
52
- }
53
-
54
46
  const epochToShortDateFormat = (value: number | null | undefined): string => {
55
47
  if (value == null || !isFinite(value)) {
56
48
  return "";
@@ -82,14 +74,6 @@ export const useDateFormat = () => {
82
74
  return date.toLocaleString(languageCode.value, { ...OPTIONS.shortTime, timeZone: timeZone.value });
83
75
  };
84
76
 
85
- const epochToMonthShortTimeFormat = (value: number | null | undefined): string => {
86
- if (value == null || !isFinite(value)) {
87
- return "";
88
- }
89
- const date = new Date(value);
90
- return date.toLocaleString(languageCode.value, { ...OPTIONS.monthShortTime, timeZone: timeZone.value });
91
- };
92
-
93
77
  const epochToLocalDayStart = (value: number | null | undefined): number => {
94
78
  if (value == null || !isFinite(value)) {
95
79
  return 0;
@@ -225,8 +209,6 @@ export const useDateFormat = () => {
225
209
  epochToMonthYearOnlyFormat,
226
210
  epochToShortDateFormat,
227
211
  epochToShortTimeFormat,
228
- epochToDayMonthShortOnly,
229
- epochToMonthShortTimeFormat,
230
212
  epochToShortTimeOnlyFormat,
231
213
  epochToTimeOnlyFormat,
232
214
  epochToWeekNumber,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dative-gpi/foundation-shared-services",
3
3
  "sideEffects": false,
4
- "version": "1.0.128-mountain-alpha",
4
+ "version": "1.0.128-remove-deprecated-scenario",
5
5
  "description": "",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -10,7 +10,7 @@
10
10
  "author": "",
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
- "@dative-gpi/foundation-shared-domain": "1.0.128-mountain-alpha"
13
+ "@dative-gpi/foundation-shared-domain": "1.0.128-remove-deprecated-scenario"
14
14
  },
15
15
  "peerDependencies": {
16
16
  "@dative-gpi/bones-ui": "^1.0.0",
@@ -18,5 +18,5 @@
18
18
  "vue": "^3.4.38",
19
19
  "vue-router": "^4.3.0"
20
20
  },
21
- "gitHead": "37cef6036141cc79839c97f8ffc124c024e5486a"
21
+ "gitHead": "c130943e7cb96800dbd98069299ec689da3c9866"
22
22
  }
@@ -1,137 +0,0 @@
1
- import { useAppTimeZone } from './app/useAppTimeZone';
2
- import { useDateFormat } from './useDateFormat';
3
-
4
- export const useTermFieldDate = () => {
5
- const { todayToEpoch } = useDateFormat();
6
- const { getUserOffset } = useAppTimeZone();
7
-
8
- const EXPRESSION = /(?:(?:([-\+])(\d*))?(\w+))?(?:\/(\w))?/g;
9
- const NOW = 'now';
10
-
11
- const convert = (value: string, variables: { [key: string]: number | string } = {}): number => {
12
- //Try to convert the value to a date
13
- const date = new Date(value);
14
- if (!isNaN(date.getTime())) {
15
- return date.getTime() + getUserOffset(date.getTime());
16
- }
17
-
18
- const currentVariables = {
19
- ...variables,
20
- [NOW]: todayToEpoch()
21
- };
22
-
23
- return applyFormula(value, currentVariables);
24
- }
25
-
26
- const applyFormula = (expression: string, variables: { [key: string]: number | string }): number => {
27
- expression = expression.replace(/\s/g, '');
28
- const matches = expression.matchAll(EXPRESSION);
29
-
30
- if (!matches) {
31
- console.error('Invalid expression');
32
- return NaN;
33
- }
34
-
35
- let timestamp = 0;
36
-
37
- // Retrieving group in order are: operator (+ or -), number, unit, and special (variable)
38
- matches.forEach(match => {
39
- const operator = match[1];
40
- const number = match[2];
41
- const unit = match[3];
42
- const special = match[4];
43
-
44
- if (unit) {
45
- timestamp = applyUnit(timestamp, operator, number, unit, variables);
46
- }
47
-
48
- if (special) {
49
- timestamp = applySpecial(timestamp, special);
50
- }
51
- });
52
-
53
- return timestamp;
54
- }
55
-
56
- const applyUnit = (timestamp: number, operator: string, number: string, unit: string, variables: { [key: string]: number | string }): number => {
57
- let factor = operator === '-' ? -1 : 1;
58
- factor *= Number.isNaN(parseInt(number)) ? 1 : parseInt(number);
59
-
60
- switch (unit) {
61
- case 's':
62
- return timestamp + factor * 1000;
63
- case 'm':
64
- return timestamp + factor * 60 * 1000;
65
- case 'h':
66
- return timestamp + factor * 60 * 60 * 1000;
67
- case 'd':
68
- return new Date(timestamp).setDate(new Date(timestamp).getDate() + factor)
69
- case 'w':
70
- return new Date(timestamp).setDate(new Date(timestamp).getDate() + factor * 7);
71
- case 'M':
72
- return new Date(timestamp).setMonth(new Date(timestamp).getMonth() + factor);
73
- case 'y':
74
- return new Date(timestamp).setFullYear(new Date(timestamp).getFullYear() + factor);
75
- default:
76
- if(variables[unit]) {
77
- const variableValue = getVariableValue(unit, variables);
78
- return timestamp + factor * variableValue;
79
- }
80
- else {
81
- console.error(`Invalid unit expression, unit ${unit} is not defined in the variables`);
82
- return timestamp;
83
- }
84
- }
85
- }
86
-
87
- const getVariableValue = (unit: string, variables: { [key: string]: number | string }): number => {
88
- if(variables[unit]) {
89
- const variableValue = parseInt(variables[unit].toString());
90
- if (typeof variables[unit] === 'number') {
91
- return variableValue;
92
- } else if (!isNaN(variableValue)) {
93
- return variableValue;
94
- } else {
95
- const variableExpression = variables[unit].toString();
96
- const variableValue = applyFormula(variableExpression, variables);
97
- if (!isNaN(variableValue)) {
98
- return variableValue;
99
- } else {
100
- console.error(`Invalid unit expression, unit ${unit} is not defined in the variables`);
101
- return 0;
102
- }
103
- }
104
- }
105
- else {
106
- console.error(`Invalid unit expression, unit ${unit} is not defined in the variables`);
107
- return 0;
108
- }
109
- }
110
-
111
- const applySpecial = (timestamp: number, special: string): number => {
112
- switch (special) {
113
- case "h":
114
- return new Date(timestamp).setMinutes(0, 0, 0);
115
- case "d":
116
- return new Date(timestamp).setHours(0, 0, 0, 0);
117
- case "w":
118
- const date = new Date(timestamp);
119
- const day = date.getDay();
120
- const diff = date.getDate() - day + (day === 0 ? -6 : 1);
121
- return new Date(date.setDate(diff)).setHours(0, 0, 0, 0);
122
- case "M":
123
- const dateM = new Date(timestamp);
124
- return new Date(dateM.setMonth(dateM.getMonth(), 1)).setHours(0, 0, 0, 0);
125
- case "y":
126
- const dateY = new Date(timestamp);
127
- return new Date(dateY.setMonth(0, 1)).setHours(0, 0, 0, 0);
128
- default:
129
- break;
130
- }
131
- return timestamp;
132
- }
133
-
134
- return {
135
- convert
136
- }
137
- }