@trudb/tru-common-lib 0.0.184 → 0.0.185
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/esm2020/lib/classes/tru-formula-eval.mjs +26 -26
- package/esm2020/public-api.mjs +3 -1
- package/fesm2015/trudb-tru-common-lib.mjs +26 -26
- package/fesm2015/trudb-tru-common-lib.mjs.map +1 -1
- package/fesm2020/trudb-tru-common-lib.mjs +26 -26
- package/fesm2020/trudb-tru-common-lib.mjs.map +1 -1
- package/lib/classes/tru-formula-eval.d.ts +1 -1
- package/package.json +1 -1
- package/public-api.d.ts +2 -0
|
@@ -115,7 +115,7 @@ class TruTableConfigBase {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
class
|
|
118
|
+
class TruFormulaEval {
|
|
119
119
|
static isString(s) {
|
|
120
120
|
return typeof s === 'string';
|
|
121
121
|
}
|
|
@@ -154,33 +154,33 @@ class FormulaEval {
|
|
|
154
154
|
* Exposed for testing.
|
|
155
155
|
*/
|
|
156
156
|
static _calculate(f, left, right) {
|
|
157
|
-
if (
|
|
157
|
+
if (TruFormulaEval.isString(left))
|
|
158
158
|
left = parseFloat(left);
|
|
159
|
-
if (
|
|
160
|
-
if (
|
|
159
|
+
if (TruFormulaEval.isString(left))
|
|
160
|
+
if (TruFormulaEval.isString(right))
|
|
161
161
|
right = parseFloat(right);
|
|
162
162
|
return f(left, right);
|
|
163
163
|
}
|
|
164
164
|
static _calculateDate(left, right, add) {
|
|
165
165
|
if (add) {
|
|
166
|
-
if (
|
|
166
|
+
if (TruFormulaEval.isDate(left) && !TruFormulaEval.isDate(right)) {
|
|
167
167
|
return moment(left).add(right, 'day').toDate();
|
|
168
168
|
}
|
|
169
|
-
if (!
|
|
169
|
+
if (!TruFormulaEval.isDate(left) && TruFormulaEval.isDate(right)) {
|
|
170
170
|
return moment(right).add(left, 'day').toDate();
|
|
171
171
|
}
|
|
172
|
-
if (
|
|
172
|
+
if (TruFormulaEval.isDate(left) && TruFormulaEval.isDate(right)) {
|
|
173
173
|
moment(left).add(right).toDate();
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
else {
|
|
177
|
-
if (
|
|
177
|
+
if (TruFormulaEval.isDate(left) && !TruFormulaEval.isDate(right)) {
|
|
178
178
|
return moment(left).subtract(right, 'day').toDate();
|
|
179
179
|
}
|
|
180
|
-
if (!
|
|
180
|
+
if (!TruFormulaEval.isDate(left) && TruFormulaEval.isDate(right)) {
|
|
181
181
|
return moment(right).subtract(left, 'day').toDate();
|
|
182
182
|
}
|
|
183
|
-
if (
|
|
183
|
+
if (TruFormulaEval.isDate(left) && TruFormulaEval.isDate(right)) {
|
|
184
184
|
//var m = moment(left).diff(right, 'days'); //Integer value, but Excel uses decimal for date time
|
|
185
185
|
var m = moment(left).diff(moment(right)) / 86400000; //divide by miliseconds in a day, decimal answer 1.0 = 1 day, 0.5 = 12 hours
|
|
186
186
|
return m;
|
|
@@ -191,36 +191,36 @@ class FormulaEval {
|
|
|
191
191
|
static add(left, right) {
|
|
192
192
|
if (left === null || left === undefined || right === null || right === undefined)
|
|
193
193
|
return undefined;
|
|
194
|
-
if (
|
|
195
|
-
return
|
|
196
|
-
return
|
|
194
|
+
if (TruFormulaEval.isDate(left) || TruFormulaEval.isDate(right))
|
|
195
|
+
return TruFormulaEval._calculateDate(left, right, true);
|
|
196
|
+
return TruFormulaEval._calculate(function (l, r) { return l + r; }, left, right);
|
|
197
197
|
}
|
|
198
198
|
static subtract(left, right) {
|
|
199
199
|
if (left === null || left === undefined || right === null || right === undefined)
|
|
200
200
|
return undefined;
|
|
201
|
-
if (
|
|
202
|
-
return
|
|
203
|
-
return
|
|
201
|
+
if (TruFormulaEval.isDate(left) || TruFormulaEval.isDate(right))
|
|
202
|
+
return TruFormulaEval._calculateDate(left, right, true);
|
|
203
|
+
return TruFormulaEval._calculate(function (l, r) { return l - r; }, left, right);
|
|
204
204
|
}
|
|
205
205
|
static multiply(left, right) {
|
|
206
206
|
if (left === null || left === undefined || right === null || right === undefined)
|
|
207
207
|
return undefined;
|
|
208
|
-
return
|
|
208
|
+
return TruFormulaEval._calculate(function (l, r) { return l * r; }, left, right);
|
|
209
209
|
}
|
|
210
210
|
static divide(left, right) {
|
|
211
211
|
if (left === null || left === undefined || right === null || right === undefined)
|
|
212
212
|
return undefined;
|
|
213
|
-
return
|
|
213
|
+
return TruFormulaEval._calculate(function (l, r) { return l / r; }, left, right);
|
|
214
214
|
}
|
|
215
215
|
static power(left, right) {
|
|
216
216
|
if (left === null || left === undefined || right === null || right === undefined)
|
|
217
217
|
return undefined;
|
|
218
|
-
return
|
|
218
|
+
return TruFormulaEval._calculate(Math.pow, left, right);
|
|
219
219
|
}
|
|
220
220
|
static concatenate(left, right) {
|
|
221
221
|
if (_.isBoolean(left))
|
|
222
222
|
left = left ? 'TRUE' : 'FALSE';
|
|
223
|
-
else if (!
|
|
223
|
+
else if (!TruFormulaEval.isString(left))
|
|
224
224
|
//NOTE: only need to convert left to string since concat() will coerce parameters
|
|
225
225
|
left = left.toString();
|
|
226
226
|
if (_.isBoolean(right))
|
|
@@ -235,22 +235,22 @@ class FormulaEval {
|
|
|
235
235
|
}
|
|
236
236
|
static lessThan(left, right) {
|
|
237
237
|
if (typeof (left) !== typeof (right))
|
|
238
|
-
return !
|
|
238
|
+
return !TruFormulaEval.compareResultForMismatchedParams[typeof (left) + typeof (right)];
|
|
239
239
|
return left < right;
|
|
240
240
|
}
|
|
241
241
|
static greaterThan(left, right) {
|
|
242
242
|
if (typeof (left) !== typeof (right))
|
|
243
|
-
return
|
|
243
|
+
return TruFormulaEval.compareResultForMismatchedParams[typeof (left) + typeof (right)];
|
|
244
244
|
return left > right;
|
|
245
245
|
}
|
|
246
246
|
static lessThanOrEqual(left, right) {
|
|
247
247
|
if (typeof (left) !== typeof (right))
|
|
248
|
-
return !
|
|
248
|
+
return !TruFormulaEval.compareResultForMismatchedParams[typeof (left) + typeof (right)];
|
|
249
249
|
return left <= right;
|
|
250
250
|
}
|
|
251
251
|
static greaterThanOrEqual(left, right) {
|
|
252
252
|
if (typeof (left) !== typeof (right))
|
|
253
|
-
return
|
|
253
|
+
return TruFormulaEval.compareResultForMismatchedParams[typeof (left) + typeof (right)];
|
|
254
254
|
return left >= right;
|
|
255
255
|
}
|
|
256
256
|
static negate(operand) {
|
|
@@ -260,7 +260,7 @@ class FormulaEval {
|
|
|
260
260
|
return operand / 100.0;
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
|
-
|
|
263
|
+
TruFormulaEval.compareResultForMismatchedParams = {
|
|
264
264
|
booleanstring: true,
|
|
265
265
|
booleannumber: true,
|
|
266
266
|
stringnumber: true,
|
|
@@ -4520,5 +4520,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.2", ngImpor
|
|
|
4520
4520
|
* Generated bundle index. Do not edit.
|
|
4521
4521
|
*/
|
|
4522
4522
|
|
|
4523
|
-
export {
|
|
4523
|
+
export { TruAppEnvironment, TruBreezeContext, TruBreezeContextFactory, TruBreezeMetadataProvider, TruColumn, TruColumnModule, TruCommonModule, TruComponentLookup, TruConfirmDialog, TruConfirmDialogConfig, TruConfirmDialogModule, TruDataContext, TruDataGrid, TruDataGridModule, TruDataGridTypes, TruDesktop, TruDesktopModule, TruEntityAccessor, TruEntityBase, TruExportDialog, TruExportDialogConfig, TruExportDialogModule, TruForm, TruFormModule, TruFormulaEval, TruGroupBox, TruGroupBoxModule, TruPredicate, TruPredicateMap, TruPropertyConfigBase, TruPropertyConfigCloudFile, TruPropertyConfigDecimal, TruPropertyConfigForeignKey, TruPropertyConfigInteger, TruPropertyConfigPassword, TruPropertyConfigPercentage, TruPropertyConfigScientific, TruPropertyConfigText, TruPropertyConfigTextChoices, TruPropertyConfigUsaAddress, TruPropertyConfigZipCode, TruQueryPredicateManager, TruRow, TruRowModule, TruSearchComponentBase, TruSearchComponentConfigBase, TruSearchGroupEventHandler, TruSearchIconModule, TruSearchPanelPositionManager, TruSearchPanelPositionManagerModule, TruSearchViewEventHandler, TruSort, TruTableConfigBase, TruTextManager, TruToolbar, TruToolbarButton, TruToolbarButtonModule, TruToolbarContextFilter, TruToolbarContextFilterModule, TruToolbarDropdown, TruToolbarDropdownModule, TruToolbarMenu, TruToolbarMenuModule, TruToolbarModule, TruToolbarSeparator, TruToolbarSeparatorModule, TruToolbarText, TruToolbarTextModule, TruUiNotification, TruUser, TruWindowActionEventHandler, TruWindowAddViewEventArgs, TruWindowEventArgs, TruWindowEventHandler };
|
|
4524
4524
|
//# sourceMappingURL=trudb-tru-common-lib.mjs.map
|