@trackunit/iris-app-runtime-core 0.3.27 → 0.3.28

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/index.cjs CHANGED
@@ -102,7 +102,7 @@ const getCustomFieldValueFromRawValue = (customFieldDefinition, newValue) => {
102
102
  }
103
103
  else if (customFieldDefinition.type === irisAppRuntimeCoreApi.CustomFieldType.DATE) {
104
104
  return {
105
- dateValue: getStringValue(newValue),
105
+ dateValue: getDateValue(newValue),
106
106
  type: irisAppRuntimeCoreApi.CustomFieldType.DATE,
107
107
  };
108
108
  }
@@ -169,12 +169,12 @@ const getCustomFieldValueFromRawValue = (customFieldDefinition, newValue) => {
169
169
  }
170
170
  throw new Error("Unsupported custom field type");
171
171
  };
172
+ /**
173
+ * Convert the received value to a string
174
+ */
172
175
  const getStringValue = (value) => {
173
176
  const stringValue = value;
174
- if (!isNaN(new Date(stringValue).getDate())) {
175
- return new Date(stringValue).toISOString();
176
- }
177
- else if (stringValue === null || stringValue === undefined) {
177
+ if (stringValue === null || stringValue === undefined) {
178
178
  return null;
179
179
  }
180
180
  else if (stringValue.trim().length === 0) {
@@ -184,6 +184,17 @@ const getStringValue = (value) => {
184
184
  return stringValue.trim();
185
185
  }
186
186
  };
187
+ /**
188
+ * Format the received value to a date string
189
+ * yyyy-mm-dd
190
+ */
191
+ const getDateValue = (value) => {
192
+ const date = new Date(value);
193
+ const day = date.toLocaleString("default", { day: "2-digit" });
194
+ const month = date.toLocaleString("default", { month: "2-digit" });
195
+ const year = date.toLocaleString("default", { year: "numeric" });
196
+ return `${year}-${month}-${day}`;
197
+ };
187
198
  const CustomFieldRuntime = {
188
199
  getCustomFieldsFor: (entity) => __awaiter(void 0, void 0, void 0, function* () {
189
200
  const api = yield getHostConnector();
@@ -328,7 +339,9 @@ exports.ToastRuntime = ToastRuntime;
328
339
  exports.TokenRuntime = TokenRuntime;
329
340
  exports.UserSubscriptionRuntime = UserSubscriptionRuntime;
330
341
  exports.getCustomFieldValueFromRawValue = getCustomFieldValueFromRawValue;
342
+ exports.getDateValue = getDateValue;
331
343
  exports.getHostConnector = getHostConnector;
344
+ exports.getStringValue = getStringValue;
332
345
  exports.setupHostConnector = setupHostConnector;
333
346
  Object.keys(irisAppRuntimeCoreApi).forEach(function (k) {
334
347
  if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
package/index.js CHANGED
@@ -99,7 +99,7 @@ const getCustomFieldValueFromRawValue = (customFieldDefinition, newValue) => {
99
99
  }
100
100
  else if (customFieldDefinition.type === CustomFieldType.DATE) {
101
101
  return {
102
- dateValue: getStringValue(newValue),
102
+ dateValue: getDateValue(newValue),
103
103
  type: CustomFieldType.DATE,
104
104
  };
105
105
  }
@@ -166,12 +166,12 @@ const getCustomFieldValueFromRawValue = (customFieldDefinition, newValue) => {
166
166
  }
167
167
  throw new Error("Unsupported custom field type");
168
168
  };
169
+ /**
170
+ * Convert the received value to a string
171
+ */
169
172
  const getStringValue = (value) => {
170
173
  const stringValue = value;
171
- if (!isNaN(new Date(stringValue).getDate())) {
172
- return new Date(stringValue).toISOString();
173
- }
174
- else if (stringValue === null || stringValue === undefined) {
174
+ if (stringValue === null || stringValue === undefined) {
175
175
  return null;
176
176
  }
177
177
  else if (stringValue.trim().length === 0) {
@@ -181,6 +181,17 @@ const getStringValue = (value) => {
181
181
  return stringValue.trim();
182
182
  }
183
183
  };
184
+ /**
185
+ * Format the received value to a date string
186
+ * yyyy-mm-dd
187
+ */
188
+ const getDateValue = (value) => {
189
+ const date = new Date(value);
190
+ const day = date.toLocaleString("default", { day: "2-digit" });
191
+ const month = date.toLocaleString("default", { month: "2-digit" });
192
+ const year = date.toLocaleString("default", { year: "numeric" });
193
+ return `${year}-${month}-${day}`;
194
+ };
184
195
  const CustomFieldRuntime = {
185
196
  getCustomFieldsFor: (entity) => __awaiter(void 0, void 0, void 0, function* () {
186
197
  const api = yield getHostConnector();
@@ -310,4 +321,4 @@ const UserSubscriptionRuntime = {
310
321
  }),
311
322
  };
312
323
 
313
- export { AssetRuntime, AssetSortingRuntime, CurrentUserRuntime, CustomFieldRuntime, DeveloperSettingsRuntime, EnvironmentRuntime, GlobalSelectionRuntime, NavigationRuntime, ParamsRuntime, RestRuntime, SiteRuntime, ToastRuntime, TokenRuntime, UserSubscriptionRuntime, getCustomFieldValueFromRawValue, getHostConnector, setupHostConnector };
324
+ export { AssetRuntime, AssetSortingRuntime, CurrentUserRuntime, CustomFieldRuntime, DeveloperSettingsRuntime, EnvironmentRuntime, GlobalSelectionRuntime, NavigationRuntime, ParamsRuntime, RestRuntime, SiteRuntime, ToastRuntime, TokenRuntime, UserSubscriptionRuntime, getCustomFieldValueFromRawValue, getDateValue, getHostConnector, getStringValue, setupHostConnector };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/iris-app-runtime-core",
3
- "version": "0.3.27",
3
+ "version": "0.3.28",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "module": "./index.js",
@@ -10,6 +10,15 @@ export interface DropdownSelection {
10
10
  * @returns { CustomFieldValue } an updated CustomFieldValue
11
11
  */
12
12
  export declare const getCustomFieldValueFromRawValue: (customFieldDefinition: CustomFieldDefinition, newValue: boolean | string | string[] | DropdownSelection[] | DropdownSelection | number) => CustomFieldValue;
13
+ /**
14
+ * Convert the received value to a string
15
+ */
16
+ export declare const getStringValue: (value: boolean | string | string[] | DropdownSelection[] | DropdownSelection | number) => string | null;
17
+ /**
18
+ * Format the received value to a date string
19
+ * yyyy-mm-dd
20
+ */
21
+ export declare const getDateValue: (value: string) => string;
13
22
  export interface ICustomFieldRuntime {
14
23
  getCustomFieldsFor: (entity: EntityIdentity) => Promise<ValueAndDefinition[]>;
15
24
  setCustomFieldsFor: (entity: EntityIdentity, values: ValueAndDefinitionKey[]) => Promise<void | CustomFieldError>;