@syncfusion/ej2-calculate 35.1.37
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/.eslintrc.json +263 -0
- package/README.md +132 -0
- package/base.d.ts +4 -0
- package/base.js +4 -0
- package/common.d.ts +4 -0
- package/common.js +4 -0
- package/dist/ej2-calculate.umd.min.js +11 -0
- package/dist/ej2-calculate.umd.min.js.map +1 -0
- package/dist/es6/ej2-calculate.es2015.js +24801 -0
- package/dist/es6/ej2-calculate.es2015.js.map +1 -0
- package/dist/es6/ej2-calculate.es5.js +27229 -0
- package/dist/es6/ej2-calculate.es5.js.map +1 -0
- package/dist/global/ej2-calculate.min.js +11 -0
- package/dist/global/ej2-calculate.min.js.map +1 -0
- package/dist/global/index.d.ts +14 -0
- package/formulas.d.ts +4 -0
- package/formulas.js +4 -0
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/license +10 -0
- package/package.json +30 -0
- package/src/base/calculate-model.d.ts +4 -0
- package/src/base/calculate-model.js +0 -0
- package/src/base/calculate.d.ts +1105 -0
- package/src/base/calculate.js +4720 -0
- package/src/base/index.d.ts +8 -0
- package/src/base/index.js +7 -0
- package/src/base/parser.d.ts +208 -0
- package/src/base/parser.js +1512 -0
- package/src/common/address.d.ts +59 -0
- package/src/common/address.js +96 -0
- package/src/common/cell-ref.d.ts +32 -0
- package/src/common/cell-ref.js +112 -0
- package/src/common/common.d.ts +44 -0
- package/src/common/common.js +134 -0
- package/src/common/enum.d.ts +94 -0
- package/src/common/enum.js +97 -0
- package/src/common/index.d.ts +9 -0
- package/src/common/index.js +8 -0
- package/src/common/interface.d.ts +122 -0
- package/src/common/interface.js +0 -0
- package/src/common/l10n.d.ts +24 -0
- package/src/common/l10n.js +54 -0
- package/src/common/number-date.d.ts +26 -0
- package/src/common/number-date.js +38 -0
- package/src/common/sheet-info.d.ts +10 -0
- package/src/common/sheet-info.js +17 -0
- package/src/common/sort.d.ts +17 -0
- package/src/common/sort.js +44 -0
- package/src/formulas/array.d.ts +47 -0
- package/src/formulas/array.js +718 -0
- package/src/formulas/basic.d.ts +47 -0
- package/src/formulas/basic.js +181 -0
- package/src/formulas/complex-numbers.d.ts +207 -0
- package/src/formulas/complex-numbers.js +549 -0
- package/src/formulas/database.d.ts +152 -0
- package/src/formulas/database.js +579 -0
- package/src/formulas/date-time-extra.d.ts +97 -0
- package/src/formulas/date-time-extra.js +415 -0
- package/src/formulas/date-time-intl.d.ts +57 -0
- package/src/formulas/date-time-intl.js +309 -0
- package/src/formulas/date-time.d.ts +164 -0
- package/src/formulas/date-time.js +1021 -0
- package/src/formulas/engineering-base.d.ts +150 -0
- package/src/formulas/engineering-base.js +404 -0
- package/src/formulas/engineering-bessel.d.ts +65 -0
- package/src/formulas/engineering-bessel.js +167 -0
- package/src/formulas/engineering-convert.d.ts +35 -0
- package/src/formulas/engineering-convert.js +120 -0
- package/src/formulas/engineering-misc.d.ts +64 -0
- package/src/formulas/engineering-misc.js +168 -0
- package/src/formulas/financial-amortization-ecma.d.ts +87 -0
- package/src/formulas/financial-amortization-ecma.js +288 -0
- package/src/formulas/financial-annuity.d.ts +104 -0
- package/src/formulas/financial-annuity.js +419 -0
- package/src/formulas/financial-bond-helpers.d.ts +106 -0
- package/src/formulas/financial-bond-helpers.js +190 -0
- package/src/formulas/financial-cashflow.d.ts +47 -0
- package/src/formulas/financial-cashflow.js +203 -0
- package/src/formulas/financial-coupons.d.ts +227 -0
- package/src/formulas/financial-coupons.js +810 -0
- package/src/formulas/financial-depreciation.d.ts +64 -0
- package/src/formulas/financial-depreciation.js +247 -0
- package/src/formulas/financial-rates.d.ts +54 -0
- package/src/formulas/financial-rates.js +140 -0
- package/src/formulas/financial-securities.d.ts +126 -0
- package/src/formulas/financial-securities.js +488 -0
- package/src/formulas/formula-math-helpers.d.ts +212 -0
- package/src/formulas/formula-math-helpers.js +599 -0
- package/src/formulas/formula-module-base.d.ts +54 -0
- package/src/formulas/formula-module-base.js +125 -0
- package/src/formulas/formula-owner.d.ts +17 -0
- package/src/formulas/formula-owner.js +0 -0
- package/src/formulas/index.d.ts +68 -0
- package/src/formulas/index.js +67 -0
- package/src/formulas/information-advanced.d.ts +44 -0
- package/src/formulas/information-advanced.js +157 -0
- package/src/formulas/information-ecma.d.ts +33 -0
- package/src/formulas/information-ecma.js +88 -0
- package/src/formulas/information-extra.d.ts +146 -0
- package/src/formulas/information-extra.js +351 -0
- package/src/formulas/information.d.ts +34 -0
- package/src/formulas/information.js +78 -0
- package/src/formulas/logical-extra.d.ts +75 -0
- package/src/formulas/logical-extra.js +217 -0
- package/src/formulas/logical.d.ts +83 -0
- package/src/formulas/logical.js +296 -0
- package/src/formulas/lookup-array.d.ts +98 -0
- package/src/formulas/lookup-array.js +364 -0
- package/src/formulas/lookup-ref-extra.d.ts +64 -0
- package/src/formulas/lookup-ref-extra.js +180 -0
- package/src/formulas/lookup-ref.d.ts +84 -0
- package/src/formulas/lookup-ref.js +263 -0
- package/src/formulas/lookup.d.ts +114 -0
- package/src/formulas/lookup.js +881 -0
- package/src/formulas/math-aggregate.d.ts +74 -0
- package/src/formulas/math-aggregate.js +376 -0
- package/src/formulas/math-ceiling-ecma.d.ts +42 -0
- package/src/formulas/math-ceiling-ecma.js +123 -0
- package/src/formulas/math-combinatorics.d.ts +75 -0
- package/src/formulas/math-combinatorics.js +290 -0
- package/src/formulas/math-misc.d.ts +164 -0
- package/src/formulas/math-misc.js +889 -0
- package/src/formulas/math-number.d.ts +76 -0
- package/src/formulas/math-number.js +261 -0
- package/src/formulas/math-rounding.d.ts +115 -0
- package/src/formulas/math-rounding.js +728 -0
- package/src/formulas/math-trig-hyperbolic.d.ts +55 -0
- package/src/formulas/math-trig-hyperbolic.js +113 -0
- package/src/formulas/math-trig.d.ts +165 -0
- package/src/formulas/math-trig.js +334 -0
- package/src/formulas/matrix-base.d.ts +13 -0
- package/src/formulas/matrix-base.js +169 -0
- package/src/formulas/matrix.d.ts +64 -0
- package/src/formulas/matrix.js +161 -0
- package/src/formulas/regression-ecma.d.ts +66 -0
- package/src/formulas/regression-ecma.js +234 -0
- package/src/formulas/statistical-advanced.d.ts +125 -0
- package/src/formulas/statistical-advanced.js +756 -0
- package/src/formulas/statistical-correlation.d.ts +75 -0
- package/src/formulas/statistical-correlation.js +198 -0
- package/src/formulas/statistical-dispersion.d.ts +108 -0
- package/src/formulas/statistical-dispersion.js +337 -0
- package/src/formulas/statistical-distribution-extended.d.ts +176 -0
- package/src/formulas/statistical-distribution-extended.js +668 -0
- package/src/formulas/statistical-distribution.d.ts +104 -0
- package/src/formulas/statistical-distribution.js +368 -0
- package/src/formulas/statistical-ecma.d.ts +95 -0
- package/src/formulas/statistical-ecma.js +392 -0
- package/src/formulas/statistical-extended.d.ts +136 -0
- package/src/formulas/statistical-extended.js +340 -0
- package/src/formulas/statistical-ifs.d.ts +46 -0
- package/src/formulas/statistical-ifs.js +180 -0
- package/src/formulas/statistical-moments.d.ts +84 -0
- package/src/formulas/statistical-moments.js +269 -0
- package/src/formulas/statistical-percentile.d.ts +56 -0
- package/src/formulas/statistical-percentile.js +195 -0
- package/src/formulas/statistical-sample-base.d.ts +14 -0
- package/src/formulas/statistical-sample-base.js +124 -0
- package/src/formulas/statistical.d.ts +135 -0
- package/src/formulas/statistical.js +542 -0
- package/src/formulas/text-advanced.d.ts +64 -0
- package/src/formulas/text-advanced.js +222 -0
- package/src/formulas/text-ecma.d.ts +54 -0
- package/src/formulas/text-ecma.js +106 -0
- package/src/formulas/text-extra.d.ts +216 -0
- package/src/formulas/text-extra.js +657 -0
- package/src/formulas/text.d.ts +125 -0
- package/src/formulas/text.js +628 -0
- package/src/global.js +1 -0
- package/src/index.d.ts +14 -0
- package/src/index.js +14 -0
- package/tslint.json +111 -0
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
extendStatics(d, b);
|
|
10
|
+
function __() { this.constructor = d; }
|
|
11
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
12
|
+
};
|
|
13
|
+
})();
|
|
14
|
+
import { FormulasErrorsStrings, CommonErrors } from '../common/index';
|
|
15
|
+
import { isNullOrUndefined } from '@syncfusion/ej2-base';
|
|
16
|
+
import { FormulaModuleBase } from './formula-module-base';
|
|
17
|
+
/**
|
|
18
|
+
* Additional date/time utilities: workdays, network days, week numbers, and calendar offsets.
|
|
19
|
+
*
|
|
20
|
+
* Registered functions: YEAR, WEEKNUM, TIMEVALUE, DAYS360, YEARFRAC, NETWORKDAYS, WORKDAY.
|
|
21
|
+
*
|
|
22
|
+
* @hidden
|
|
23
|
+
*/
|
|
24
|
+
var DateTimeExtraFormulas = /** @class */ (function (_super) {
|
|
25
|
+
__extends(DateTimeExtraFormulas, _super);
|
|
26
|
+
/**
|
|
27
|
+
* @hidden
|
|
28
|
+
* @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
|
|
29
|
+
*/
|
|
30
|
+
function DateTimeExtraFormulas(owner) {
|
|
31
|
+
var _this = _super.call(this, owner) || this;
|
|
32
|
+
/** Formula definitions registered with {@link BasicFormulas}. */
|
|
33
|
+
_this.formulas = [
|
|
34
|
+
{ formulaName: 'YEAR', category: 'Date & Time', description: 'Converts a serial number to a year.' },
|
|
35
|
+
{ formulaName: 'WEEKNUM', category: 'Date & Time', description: 'Converts a serial number to a number representing where the week falls numerically within a year.' },
|
|
36
|
+
{ formulaName: 'TIMEVALUE', category: 'Date & Time', description: 'Converts a time in the form of text to a serial number.' },
|
|
37
|
+
{ formulaName: 'DAYS360', category: 'Date & Time', description: 'Calculates the number of days between two dates based on a 360-day year.' },
|
|
38
|
+
{ formulaName: 'YEARFRAC', category: 'Date & Time', description: 'Returns the year fraction representing the number of whole days between start_date and end_date.' },
|
|
39
|
+
{ formulaName: 'NETWORKDAYS', category: 'Date & Time', description: 'Returns the number of whole workdays between two dates.' },
|
|
40
|
+
{ formulaName: 'WORKDAY', category: 'Date & Time', description: 'Returns the serial number of the date before or after a specified number of workdays.' }
|
|
41
|
+
];
|
|
42
|
+
return _this;
|
|
43
|
+
}
|
|
44
|
+
DateTimeExtraFormulas.prototype.toSerial = function (arg) {
|
|
45
|
+
var errCollection = this.parent.getErrorStrings();
|
|
46
|
+
var value = this.parent.getValueFromArg(arg);
|
|
47
|
+
if (errCollection.indexOf(value) > -1) {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
if (!this.parent.isCellReference(arg)) {
|
|
51
|
+
value = this.parent.removeTics(value);
|
|
52
|
+
}
|
|
53
|
+
if (value === '') {
|
|
54
|
+
return errCollection[CommonErrors.Value];
|
|
55
|
+
}
|
|
56
|
+
if (this.parent.isNumber(value)) {
|
|
57
|
+
return this.parent.parseFloat(value);
|
|
58
|
+
}
|
|
59
|
+
var parsed = this.parent.isDate(new Date(value));
|
|
60
|
+
if (parsed) {
|
|
61
|
+
return this.parent.toOADate(parsed);
|
|
62
|
+
}
|
|
63
|
+
return errCollection[CommonErrors.Value];
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Converts a serial number to a year.
|
|
67
|
+
*
|
|
68
|
+
* Excel: `YEAR(...)`.
|
|
69
|
+
*
|
|
70
|
+
* @hidden
|
|
71
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
72
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* engine.computeFormula('=YEAR(1)');
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
DateTimeExtraFormulas.prototype.ComputeYEAR = function () {
|
|
80
|
+
var args = [];
|
|
81
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
82
|
+
args[_i] = arguments[_i];
|
|
83
|
+
}
|
|
84
|
+
var errCollection = this.parent.getErrorStrings();
|
|
85
|
+
if (isNullOrUndefined(args) || args.length !== 1) {
|
|
86
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
87
|
+
}
|
|
88
|
+
var serial = this.toSerial(args[0]);
|
|
89
|
+
if (typeof serial === 'string') {
|
|
90
|
+
return serial;
|
|
91
|
+
}
|
|
92
|
+
if (serial < 0) {
|
|
93
|
+
return errCollection[CommonErrors.Num];
|
|
94
|
+
}
|
|
95
|
+
return this.parent.fromOADate(serial).getFullYear().toString();
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Converts a serial number to a number representing where the week falls numerically within a year.
|
|
99
|
+
*
|
|
100
|
+
* Excel: `WEEKNUM(...)`.
|
|
101
|
+
*
|
|
102
|
+
* @hidden
|
|
103
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
104
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
105
|
+
*/
|
|
106
|
+
DateTimeExtraFormulas.prototype.ComputeWEEKNUM = function () {
|
|
107
|
+
var args = [];
|
|
108
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
109
|
+
args[_i] = arguments[_i];
|
|
110
|
+
}
|
|
111
|
+
var errCollection = this.parent.getErrorStrings();
|
|
112
|
+
if (isNullOrUndefined(args) || args.length < 1 || args.length > 2) {
|
|
113
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
114
|
+
}
|
|
115
|
+
var serial = this.toSerial(args[0]);
|
|
116
|
+
if (typeof serial === 'string') {
|
|
117
|
+
return serial;
|
|
118
|
+
}
|
|
119
|
+
var returnType = 1;
|
|
120
|
+
if (args.length === 2 && args[1] !== '') {
|
|
121
|
+
var rt = this.resolveNumberArg(args[1]);
|
|
122
|
+
if (typeof rt === 'string') {
|
|
123
|
+
return rt;
|
|
124
|
+
}
|
|
125
|
+
returnType = Math.floor(rt);
|
|
126
|
+
}
|
|
127
|
+
var date = this.parent.fromOADate(serial);
|
|
128
|
+
var yearStart = new Date(date.getFullYear(), 0, 1);
|
|
129
|
+
var dayOffset = 0;
|
|
130
|
+
if (returnType === 2 || returnType === 11) {
|
|
131
|
+
dayOffset = 1; // week begins Monday
|
|
132
|
+
}
|
|
133
|
+
var startDow = (yearStart.getDay() + 7 - dayOffset) % 7;
|
|
134
|
+
var dayOfYear = Math.floor((date.getTime() - yearStart.getTime()) / 86400000);
|
|
135
|
+
var week = Math.floor((dayOfYear + startDow) / 7) + 1;
|
|
136
|
+
if (week < 1) {
|
|
137
|
+
return errCollection[CommonErrors.Num];
|
|
138
|
+
}
|
|
139
|
+
return week.toString();
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Converts a time in the form of text to a serial number.
|
|
143
|
+
*
|
|
144
|
+
* Excel: `TIMEVALUE(...)`.
|
|
145
|
+
*
|
|
146
|
+
* @hidden
|
|
147
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
148
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
149
|
+
*/
|
|
150
|
+
DateTimeExtraFormulas.prototype.ComputeTIMEVALUE = function () {
|
|
151
|
+
var args = [];
|
|
152
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
153
|
+
args[_i] = arguments[_i];
|
|
154
|
+
}
|
|
155
|
+
var errCollection = this.parent.getErrorStrings();
|
|
156
|
+
if (isNullOrUndefined(args) || args.length !== 1) {
|
|
157
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
158
|
+
}
|
|
159
|
+
var text = this.resolveTextArg(args[0]);
|
|
160
|
+
if (errCollection.indexOf(text) > -1) {
|
|
161
|
+
return text;
|
|
162
|
+
}
|
|
163
|
+
// eslint-disable-next-line security/detect-unsafe-regex
|
|
164
|
+
var match = text.trim().match(/^(\d{1,2}):(\d{2})(?::(\d{2}))?\s*(AM|PM)?$/i);
|
|
165
|
+
if (!match) {
|
|
166
|
+
var asDate = this.parent.isDate(new Date(text));
|
|
167
|
+
if (asDate) {
|
|
168
|
+
var serial = this.parent.toOADate(asDate, true);
|
|
169
|
+
return (serial - Math.floor(serial)).toString();
|
|
170
|
+
}
|
|
171
|
+
return errCollection[CommonErrors.Value];
|
|
172
|
+
}
|
|
173
|
+
var hours = parseInt(match[1], 10);
|
|
174
|
+
var minutes = parseInt(match[2], 10);
|
|
175
|
+
var seconds = match[3] ? parseInt(match[3], 10) : 0;
|
|
176
|
+
var ampm = match[4] ? match[4].toUpperCase() : '';
|
|
177
|
+
if (ampm === 'PM' && hours < 12) {
|
|
178
|
+
hours += 12;
|
|
179
|
+
}
|
|
180
|
+
if (ampm === 'AM' && hours === 12) {
|
|
181
|
+
hours = 0;
|
|
182
|
+
}
|
|
183
|
+
if (hours > 23 || minutes > 59 || seconds > 59) {
|
|
184
|
+
return errCollection[CommonErrors.Value];
|
|
185
|
+
}
|
|
186
|
+
return ((hours * 3600 + minutes * 60 + seconds) / 86400).toString();
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Calculates the number of days between two dates based on a 360-day year.
|
|
190
|
+
*
|
|
191
|
+
* Excel: `DAYS360(...)`.
|
|
192
|
+
*
|
|
193
|
+
* @hidden
|
|
194
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
195
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
196
|
+
*/
|
|
197
|
+
DateTimeExtraFormulas.prototype.ComputeDAYS360 = function () {
|
|
198
|
+
var args = [];
|
|
199
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
200
|
+
args[_i] = arguments[_i];
|
|
201
|
+
}
|
|
202
|
+
if (isNullOrUndefined(args) || args.length < 2 || args.length > 3) {
|
|
203
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
204
|
+
}
|
|
205
|
+
var start = this.toSerial(args[0]);
|
|
206
|
+
var end = this.toSerial(args[1]);
|
|
207
|
+
if (typeof start === 'string') {
|
|
208
|
+
return start;
|
|
209
|
+
}
|
|
210
|
+
if (typeof end === 'string') {
|
|
211
|
+
return end;
|
|
212
|
+
}
|
|
213
|
+
var method = false;
|
|
214
|
+
if (args.length === 3 && args[2] !== '') {
|
|
215
|
+
var flag = this.parent.getValueFromArg(args[2]).toUpperCase();
|
|
216
|
+
method = flag === this.parent.trueValue || this.parent.parseFloat(flag) !== 0;
|
|
217
|
+
}
|
|
218
|
+
var d1 = this.parent.fromOADate(start);
|
|
219
|
+
var d2 = this.parent.fromOADate(end);
|
|
220
|
+
var y1 = d1.getFullYear();
|
|
221
|
+
var m1 = d1.getMonth() + 1;
|
|
222
|
+
var day1 = d1.getDate();
|
|
223
|
+
var y2 = d2.getFullYear();
|
|
224
|
+
var m2 = d2.getMonth() + 1;
|
|
225
|
+
var day2 = d2.getDate();
|
|
226
|
+
if (!method) {
|
|
227
|
+
if (day1 === 31) {
|
|
228
|
+
day1 = 30;
|
|
229
|
+
}
|
|
230
|
+
if (day2 === 31 && day1 === 30) {
|
|
231
|
+
day2 = 30;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
if (day1 === 31) {
|
|
236
|
+
day1 = 30;
|
|
237
|
+
}
|
|
238
|
+
if (day2 === 31) {
|
|
239
|
+
day2 = 30;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return ((y2 - y1) * 360 + (m2 - m1) * 30 + (day2 - day1)).toString();
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* Returns the year fraction representing the number of whole days between start_date and end_date.
|
|
246
|
+
*
|
|
247
|
+
* Excel: `YEARFRAC(...)`.
|
|
248
|
+
*
|
|
249
|
+
* @hidden
|
|
250
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
251
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
252
|
+
*/
|
|
253
|
+
DateTimeExtraFormulas.prototype.ComputeYEARFRAC = function () {
|
|
254
|
+
var args = [];
|
|
255
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
256
|
+
args[_i] = arguments[_i];
|
|
257
|
+
}
|
|
258
|
+
if (isNullOrUndefined(args) || args.length < 2 || args.length > 3) {
|
|
259
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
260
|
+
}
|
|
261
|
+
var start = this.toSerial(args[0]);
|
|
262
|
+
var end = this.toSerial(args[1]);
|
|
263
|
+
if (typeof start === 'string') {
|
|
264
|
+
return start;
|
|
265
|
+
}
|
|
266
|
+
if (typeof end === 'string') {
|
|
267
|
+
return end;
|
|
268
|
+
}
|
|
269
|
+
var basis = 0;
|
|
270
|
+
if (args.length === 3 && args[2] !== '') {
|
|
271
|
+
var b = this.resolveNumberArg(args[2]);
|
|
272
|
+
if (typeof b === 'string') {
|
|
273
|
+
return b;
|
|
274
|
+
}
|
|
275
|
+
basis = Math.floor(b);
|
|
276
|
+
}
|
|
277
|
+
var days = Math.abs(end - start);
|
|
278
|
+
switch (basis) {
|
|
279
|
+
case 0:
|
|
280
|
+
return (Math.abs(this.parent.parseFloat(this.ComputeDAYS360(args[0], args[1], 'FALSE'))) / 360).toString();
|
|
281
|
+
case 1: {
|
|
282
|
+
var avgYear = 365.25;
|
|
283
|
+
return (days / avgYear).toString();
|
|
284
|
+
}
|
|
285
|
+
case 2:
|
|
286
|
+
return (days / 360).toString();
|
|
287
|
+
case 3:
|
|
288
|
+
return (days / 365).toString();
|
|
289
|
+
case 4:
|
|
290
|
+
return (Math.abs(this.parent.parseFloat(this.ComputeDAYS360(args[0], args[1], 'TRUE'))) / 360).toString();
|
|
291
|
+
default:
|
|
292
|
+
return this.parent.getErrorStrings()[CommonErrors.Num];
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
DateTimeExtraFormulas.prototype.isWeekend = function (date) {
|
|
296
|
+
var dow = date.getDay();
|
|
297
|
+
return dow === 0 || dow === 6;
|
|
298
|
+
};
|
|
299
|
+
DateTimeExtraFormulas.prototype.holidaySet = function (arg) {
|
|
300
|
+
var set = new Set();
|
|
301
|
+
if (!arg || arg === '') {
|
|
302
|
+
return set;
|
|
303
|
+
}
|
|
304
|
+
var errCollection = this.parent.getErrorStrings();
|
|
305
|
+
if (this.parent.isCellReference(arg) && arg.indexOf(':') > -1) {
|
|
306
|
+
var cells = this.parent.getCellCollection(arg);
|
|
307
|
+
var list = Array.isArray(cells) ? cells : [cells];
|
|
308
|
+
for (var i = 0; i < list.length; i++) {
|
|
309
|
+
var serial = this.toSerial(list[i]);
|
|
310
|
+
if (typeof serial === 'string') {
|
|
311
|
+
if (errCollection.indexOf(serial) > -1) {
|
|
312
|
+
return serial;
|
|
313
|
+
}
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
set.add(Math.floor(serial));
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
var serial = this.toSerial(arg);
|
|
321
|
+
if (typeof serial === 'string') {
|
|
322
|
+
return serial;
|
|
323
|
+
}
|
|
324
|
+
set.add(Math.floor(serial));
|
|
325
|
+
}
|
|
326
|
+
return set;
|
|
327
|
+
};
|
|
328
|
+
/**
|
|
329
|
+
* Returns the number of whole workdays between two dates.
|
|
330
|
+
*
|
|
331
|
+
* Excel: `NETWORKDAYS(...)`.
|
|
332
|
+
*
|
|
333
|
+
* @hidden
|
|
334
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
335
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
336
|
+
*/
|
|
337
|
+
DateTimeExtraFormulas.prototype.ComputeNETWORKDAYS = function () {
|
|
338
|
+
var args = [];
|
|
339
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
340
|
+
args[_i] = arguments[_i];
|
|
341
|
+
}
|
|
342
|
+
if (isNullOrUndefined(args) || args.length < 2 || args.length > 3) {
|
|
343
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
344
|
+
}
|
|
345
|
+
var start = this.toSerial(args[0]);
|
|
346
|
+
var end = this.toSerial(args[1]);
|
|
347
|
+
if (typeof start === 'string') {
|
|
348
|
+
return start;
|
|
349
|
+
}
|
|
350
|
+
if (typeof end === 'string') {
|
|
351
|
+
return end;
|
|
352
|
+
}
|
|
353
|
+
var holidays = this.holidaySet(args[2]);
|
|
354
|
+
if (!(holidays instanceof Set)) {
|
|
355
|
+
return holidays;
|
|
356
|
+
}
|
|
357
|
+
var step = start <= end ? 1 : -1;
|
|
358
|
+
var count = 0;
|
|
359
|
+
for (var s = Math.floor(start); step > 0 ? s <= Math.floor(end) : s >= Math.floor(end); s += step) {
|
|
360
|
+
var d = this.parent.fromOADate(s);
|
|
361
|
+
if (!this.isWeekend(d) && !holidays.has(s)) {
|
|
362
|
+
count += step;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return count.toString();
|
|
366
|
+
};
|
|
367
|
+
/**
|
|
368
|
+
* Returns the serial number of the date before or after a specified number of workdays.
|
|
369
|
+
*
|
|
370
|
+
* Excel: `WORKDAY(...)`.
|
|
371
|
+
*
|
|
372
|
+
* @hidden
|
|
373
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
374
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
375
|
+
*/
|
|
376
|
+
DateTimeExtraFormulas.prototype.ComputeWORKDAY = function () {
|
|
377
|
+
var args = [];
|
|
378
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
379
|
+
args[_i] = arguments[_i];
|
|
380
|
+
}
|
|
381
|
+
var errCollection = this.parent.getErrorStrings();
|
|
382
|
+
if (isNullOrUndefined(args) || args.length < 2 || args.length > 3) {
|
|
383
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
384
|
+
}
|
|
385
|
+
var start = this.toSerial(args[0]);
|
|
386
|
+
var daysArg = this.resolveNumberArg(args[1]);
|
|
387
|
+
if (typeof start === 'string') {
|
|
388
|
+
return start;
|
|
389
|
+
}
|
|
390
|
+
if (typeof daysArg === 'string') {
|
|
391
|
+
return daysArg;
|
|
392
|
+
}
|
|
393
|
+
var days = Math.trunc(daysArg);
|
|
394
|
+
var holidays = this.holidaySet(args[2]);
|
|
395
|
+
if (!(holidays instanceof Set)) {
|
|
396
|
+
return holidays;
|
|
397
|
+
}
|
|
398
|
+
var current = Math.floor(start);
|
|
399
|
+
var step = days >= 0 ? 1 : -1;
|
|
400
|
+
var remaining = Math.abs(days);
|
|
401
|
+
while (remaining > 0) {
|
|
402
|
+
current += step;
|
|
403
|
+
var d = this.parent.fromOADate(current);
|
|
404
|
+
if (!this.isWeekend(d) && !holidays.has(current)) {
|
|
405
|
+
remaining--;
|
|
406
|
+
}
|
|
407
|
+
if (current < 0) {
|
|
408
|
+
return errCollection[CommonErrors.Num];
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return current.toString();
|
|
412
|
+
};
|
|
413
|
+
return DateTimeExtraFormulas;
|
|
414
|
+
}(FormulaModuleBase));
|
|
415
|
+
export { DateTimeExtraFormulas };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { IBasicFormula } from '../common/index';
|
|
2
|
+
import { FormulaOwner } from './formula-owner';
|
|
3
|
+
import { FormulaModuleBase } from './formula-module-base';
|
|
4
|
+
/**
|
|
5
|
+
* Locale-aware and ECMA date functions including DATEDIF and custom-weekend WORKDAY/NETWORKDAYS variants.
|
|
6
|
+
*
|
|
7
|
+
* Registered functions: DATEDIF, NETWORKDAYS.INTL, WORKDAY.INTL.
|
|
8
|
+
*
|
|
9
|
+
* @hidden
|
|
10
|
+
*/
|
|
11
|
+
export declare class DateTimeIntlFormulas extends FormulaModuleBase {
|
|
12
|
+
/** Formula definitions registered with {@link BasicFormulas}. */
|
|
13
|
+
formulas: IBasicFormula[];
|
|
14
|
+
/**
|
|
15
|
+
* @hidden
|
|
16
|
+
* @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
|
|
17
|
+
*/
|
|
18
|
+
constructor(owner: FormulaOwner);
|
|
19
|
+
private toSerial;
|
|
20
|
+
private holidaySet;
|
|
21
|
+
private weekendMask;
|
|
22
|
+
private isWeekendMask;
|
|
23
|
+
/**
|
|
24
|
+
* Calculates the number of days, months, or years between two dates.
|
|
25
|
+
*
|
|
26
|
+
* Excel: `DATEDIF(...)`.
|
|
27
|
+
*
|
|
28
|
+
* @hidden
|
|
29
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
30
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* engine.computeFormula('=DATEDIF(DATE(2020,1,1),DATE(2024,1,1),"Y")');
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
ComputeDATEDIF(...args: string[]): string | number;
|
|
38
|
+
private isLeapYear;
|
|
39
|
+
/**
|
|
40
|
+
* Returns workdays between dates for a custom weekend.
|
|
41
|
+
*
|
|
42
|
+
* Excel: `NETWORKDAYS.INTL(...)`.
|
|
43
|
+
*
|
|
44
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
45
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
46
|
+
*/
|
|
47
|
+
['ComputeNETWORKDAYS.INTL'](...args: string[]): string | number;
|
|
48
|
+
/**
|
|
49
|
+
* Returns the date before or after a number of workdays with a custom weekend.
|
|
50
|
+
*
|
|
51
|
+
* Excel: `WORKDAY.INTL(...)`.
|
|
52
|
+
*
|
|
53
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
54
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
55
|
+
*/
|
|
56
|
+
['ComputeWORKDAY.INTL'](...args: string[]): string | number;
|
|
57
|
+
}
|