fable 3.1.21 → 3.1.23
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/dist/fable.js +59 -39
- package/dist/fable.js.map +1 -1
- package/dist/fable.min.js +2 -2
- package/dist/fable.min.js.map +1 -1
- package/package.json +1 -1
- package/source/services/Fable-Service-DateManipulation.js +211 -111
- package/source/services/Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-FunctionMap.json +16 -0
- package/source/services/Fable-Service-Math.js +1 -1
- package/test/DateManipulation_tests.js +44 -0
- package/test/ExpressionParser_tests.js +12 -0
package/package.json
CHANGED
|
@@ -6,125 +6,225 @@ const libFableServiceProviderBase = require('fable-serviceproviderbase');
|
|
|
6
6
|
*/
|
|
7
7
|
class DateManipulation extends libFableServiceProviderBase
|
|
8
8
|
{
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
constructor(pFable, pOptions, pServiceHash)
|
|
10
|
+
{
|
|
11
|
+
super(pFable, pOptions, pServiceHash)
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
this.serviceType = 'Dates';
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
this.dayJS = require('dayjs');
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
17
|
+
// Include the `weekOfYear` plugin
|
|
18
|
+
this.plugin_weekOfYear = require('dayjs/plugin/weekOfYear');
|
|
19
|
+
this.dayJS.extend(this.plugin_weekOfYear);
|
|
20
|
+
// Include the `weekday` plugin
|
|
21
|
+
this.plugin_weekday = require('dayjs/plugin/weekday');
|
|
22
|
+
this.dayJS.extend(this.plugin_weekday);
|
|
23
|
+
// Include the `isoWeek` plugin
|
|
24
|
+
this.plugin_isoWeek = require('dayjs/plugin/isoWeek');
|
|
25
|
+
this.dayJS.extend(this.plugin_isoWeek);
|
|
26
|
+
// Include the `timezone` plugin
|
|
27
|
+
this.plugin_timezone = require('dayjs/plugin/timezone');
|
|
28
|
+
this.dayJS.extend(this.plugin_timezone);
|
|
29
|
+
// Include the `relativetime` plugin
|
|
30
|
+
this.plugin_relativetime = require('dayjs/plugin/relativeTime');
|
|
31
|
+
this.dayJS.extend(this.plugin_relativetime);
|
|
32
|
+
// Include the `utc` plugin
|
|
33
|
+
this.plugin_utc = require('dayjs/plugin/utc');
|
|
34
|
+
this.dayJS.extend(this.plugin_utc);
|
|
35
|
+
// Include the `advancedFormat` plugin
|
|
36
|
+
this.plugin_advancedFormat = require('dayjs/plugin/advancedFormat');
|
|
37
|
+
this.dayJS.extend(this.plugin_advancedFormat);
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
// A developer can include locales if they want
|
|
40
|
+
// You would do the following:
|
|
41
|
+
// const localeDE = require('dayjs/locale/de');
|
|
42
|
+
// _Fable.Dates.dayJS.locale('de');
|
|
43
|
+
}
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Calculates the difference in milliseconds between two dates.
|
|
47
|
+
*
|
|
48
|
+
* @param {string|Date|number} pDateStart - The start date. Can be a string, Date object, or timestamp.
|
|
49
|
+
* @param {string|Date|number} pDateEnd - The end date. Can be a string, Date object, or timestamp. Defaults to the current date if not provided.
|
|
50
|
+
* @param {boolean} pRequireEndDate - If true, the end date must be provided; otherwise, it defaults to the current date.
|
|
51
|
+
* @returns {number} The difference in milliseconds between the start and end dates. Returns NaN if the start date is invalid.
|
|
52
|
+
*/
|
|
53
|
+
dateMillisecondDifference(pDateStart, pDateEnd, pRequireEndDate = false)
|
|
54
|
+
{
|
|
55
|
+
if ((pDateStart === undefined) || (pDateStart === null) || (pDateStart === ''))
|
|
56
|
+
{
|
|
57
|
+
return NaN;
|
|
58
|
+
}
|
|
59
|
+
if ((pRequireEndDate || (pRequireEndDate == 1) || (pRequireEndDate == '1')) && ((pDateEnd === undefined) || (pDateEnd === null) || (pDateEnd === '')))
|
|
60
|
+
{
|
|
61
|
+
return NaN;
|
|
62
|
+
}
|
|
63
|
+
let tmpStartDate = this.dayJS(pDateStart);
|
|
64
|
+
let tmpEndDate = this.dayJS(pDateEnd);
|
|
65
|
+
return tmpEndDate.diff(tmpStartDate, 'millisecond');
|
|
66
|
+
}
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Calculates the difference in seconds between two dates.
|
|
70
|
+
*
|
|
71
|
+
* @param {string|Date|number} pDateStart - The start date. Can be a string, Date object, or timestamp.
|
|
72
|
+
* @param {string|Date|number} pDateEnd - The end date. Can be a string, Date object, or timestamp. Defaults to the current date if not provided.
|
|
73
|
+
* @param {boolean} pRequireEndDate - If true, the end date must be provided; otherwise, it defaults to the current date.
|
|
74
|
+
* @returns {number} The difference in seconds between the start and end dates. Returns NaN if the start date is invalid.
|
|
75
|
+
*/
|
|
76
|
+
dateSecondDifference(pDateStart, pDateEnd, pRequireEndDate = false)
|
|
77
|
+
{
|
|
78
|
+
if ((pDateStart === undefined) || (pDateStart === null) || (pDateStart === ''))
|
|
79
|
+
{
|
|
80
|
+
return NaN;
|
|
81
|
+
}
|
|
82
|
+
if ((pRequireEndDate || (pRequireEndDate == 1) || (pRequireEndDate == '1')) && ((pDateEnd === undefined) || (pDateEnd === null) || (pDateEnd === '')))
|
|
83
|
+
{
|
|
84
|
+
return NaN;
|
|
85
|
+
}
|
|
86
|
+
let tmpStartDate = this.dayJS(pDateStart);
|
|
87
|
+
let tmpEndDate = this.dayJS(pDateEnd);
|
|
88
|
+
return tmpEndDate.diff(tmpStartDate, 'second');
|
|
89
|
+
}
|
|
86
90
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Calculates the difference in minutes between two dates.
|
|
93
|
+
*
|
|
94
|
+
* @param {string|Date|number} pDateStart - The start date. Can be a string, Date object, or timestamp.
|
|
95
|
+
* @param {string|Date|number} pDateEnd - The end date. Can be a string, Date object, or timestamp. Defaults to the current date if not provided.
|
|
96
|
+
* @param {boolean} pRequireEndDate - If true, the end date must be provided; otherwise, it defaults to the current date.
|
|
97
|
+
* @returns {number} The difference in minutes between the start and end dates. Returns NaN if the start date is invalid.
|
|
98
|
+
*/
|
|
99
|
+
dateMinuteDifference(pDateStart, pDateEnd, pRequireEndDate = false)
|
|
100
|
+
{
|
|
101
|
+
if ((pDateStart === undefined) || (pDateStart === null) || (pDateStart === ''))
|
|
102
|
+
{
|
|
103
|
+
return NaN;
|
|
104
|
+
}
|
|
105
|
+
if ((pRequireEndDate || (pRequireEndDate == 1) || (pRequireEndDate == '1')) && ((pDateEnd === undefined) || (pDateEnd === null) || (pDateEnd === '')))
|
|
106
|
+
{
|
|
107
|
+
return NaN;
|
|
108
|
+
}
|
|
109
|
+
let tmpStartDate = this.dayJS(pDateStart);
|
|
110
|
+
let tmpEndDate = this.dayJS(pDateEnd);
|
|
111
|
+
return tmpEndDate.diff(tmpStartDate, 'minute');
|
|
112
|
+
}
|
|
107
113
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
114
|
+
/**
|
|
115
|
+
* Calculates the difference in hours between two dates.
|
|
116
|
+
*
|
|
117
|
+
* @param {string|Date|number} pDateStart - The start date. Can be a string, Date object, or timestamp.
|
|
118
|
+
* @param {string|Date|number} pDateEnd - The end date. Can be a string, Date object, or timestamp. Defaults to the current date if not provided.
|
|
119
|
+
* @param {boolean} pRequireEndDate - If true, the end date must be provided; otherwise, it defaults to the current date.
|
|
120
|
+
* @returns {number} The difference in hours between the start and end dates. Returns NaN if the start date is invalid.
|
|
121
|
+
*/
|
|
122
|
+
dateHourDifference(pDateStart, pDateEnd, pRequireEndDate = false)
|
|
123
|
+
{
|
|
124
|
+
if ((pDateStart === undefined) || (pDateStart === null) || (pDateStart === ''))
|
|
125
|
+
{
|
|
126
|
+
return NaN;
|
|
127
|
+
}
|
|
128
|
+
if ((pRequireEndDate || (pRequireEndDate == 1) || (pRequireEndDate == '1')) && ((pDateEnd === undefined) || (pDateEnd === null) || (pDateEnd === '')))
|
|
129
|
+
{
|
|
130
|
+
return NaN;
|
|
131
|
+
}
|
|
132
|
+
let tmpStartDate = this.dayJS(pDateStart);
|
|
133
|
+
let tmpEndDate = this.dayJS(pDateEnd);
|
|
134
|
+
return tmpEndDate.diff(tmpStartDate, 'hour');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Calculates the difference in days between two dates.
|
|
139
|
+
*
|
|
140
|
+
* @param {string|Date|number} pDateStart - The start date. Can be a string, Date object, or timestamp.
|
|
141
|
+
* @param {string|Date|number} pDateEnd - The end date. Can be a string, Date object, or timestamp. Defaults to the current date if not provided.
|
|
142
|
+
* @param {boolean} pRequireEndDate - If true, the end date must be provided; otherwise, it defaults to the current date.
|
|
143
|
+
* @returns {number} The difference in days between the start and end dates. Returns NaN if the start date is invalid.
|
|
144
|
+
*/
|
|
145
|
+
dateDayDifference(pDateStart, pDateEnd, pRequireEndDate = false)
|
|
146
|
+
{
|
|
147
|
+
if ((pDateStart === undefined) || (pDateStart === null) || (pDateStart === ''))
|
|
148
|
+
{
|
|
149
|
+
return NaN;
|
|
150
|
+
}
|
|
151
|
+
if ((pRequireEndDate || (pRequireEndDate == 1) || (pRequireEndDate == '1')) && ((pDateEnd === undefined) || (pDateEnd === null) || (pDateEnd === '')))
|
|
152
|
+
{
|
|
153
|
+
return NaN;
|
|
154
|
+
}
|
|
155
|
+
let tmpStartDate = this.dayJS(pDateStart);
|
|
156
|
+
let tmpEndDate = this.dayJS(pDateEnd);
|
|
157
|
+
return tmpEndDate.diff(tmpStartDate, 'day');
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Calculates the difference in weeks between two dates.
|
|
162
|
+
*
|
|
163
|
+
* @param {string|Date|number} pDateStart - The start date. Can be a string, Date object, or timestamp.
|
|
164
|
+
* @param {string|Date|number} pDateEnd - The end date. Can be a string, Date object, or timestamp. Defaults to the current date if not provided.
|
|
165
|
+
* @param {boolean} pRequireEndDate - If true, the end date must be provided; otherwise, it defaults to the current date.
|
|
166
|
+
* @returns {number} The difference in weeks between the two dates. Returns NaN if the start date is invalid.
|
|
167
|
+
*/
|
|
168
|
+
dateWeekDifference(pDateStart, pDateEnd, pRequireEndDate = false)
|
|
169
|
+
{
|
|
170
|
+
if ((pDateStart === undefined) || (pDateStart === null) || (pDateStart === ''))
|
|
171
|
+
{
|
|
172
|
+
return NaN;
|
|
173
|
+
}
|
|
174
|
+
if ((pRequireEndDate || (pRequireEndDate == 1) || (pRequireEndDate == '1')) && ((pDateEnd === undefined) || (pDateEnd === null) || (pDateEnd === '')))
|
|
175
|
+
{
|
|
176
|
+
return NaN;
|
|
177
|
+
}
|
|
178
|
+
let tmpStartDate = this.dayJS(pDateStart);
|
|
179
|
+
let tmpEndDate = this.dayJS(pDateEnd);
|
|
180
|
+
return tmpEndDate.diff(tmpStartDate, 'week');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Calculates the difference in months between two dates.
|
|
185
|
+
*
|
|
186
|
+
* @param {string|Date|number} pDateStart - The start date. Can be a string, Date object, or timestamp.
|
|
187
|
+
* @param {string|Date|number} pDateEnd - The end date. Can be a string, Date object, or timestamp. Defaults to the current date if not provided.
|
|
188
|
+
* @param {boolean} pRequireEndDate - If true, the end date must be provided; otherwise, it defaults to the current date.
|
|
189
|
+
* @returns {number} The difference in months between the two dates. Returns NaN if the start date is invalid.
|
|
190
|
+
*/
|
|
191
|
+
dateMonthDifference(pDateStart, pDateEnd, pRequireEndDate = false)
|
|
192
|
+
{
|
|
193
|
+
if ((pDateStart === undefined) || (pDateStart === null) || (pDateStart === ''))
|
|
194
|
+
{
|
|
195
|
+
return NaN;
|
|
196
|
+
}
|
|
197
|
+
if ((pRequireEndDate || (pRequireEndDate == 1) || (pRequireEndDate == '1')) && ((pDateEnd === undefined) || (pDateEnd === null) || (pDateEnd === '')))
|
|
198
|
+
{
|
|
199
|
+
return NaN;
|
|
200
|
+
}
|
|
201
|
+
let tmpStartDate = this.dayJS(pDateStart);
|
|
202
|
+
let tmpEndDate = this.dayJS(pDateEnd);
|
|
203
|
+
return tmpEndDate.diff(tmpStartDate, 'month');
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Calculates the difference in years between two dates.
|
|
208
|
+
*
|
|
209
|
+
* @param {string|Date|number} pDateStart - The start date. Can be a string, Date object, or timestamp.
|
|
210
|
+
* @param {string|Date|number} pDateEnd - The end date. Can be a string, Date object, or timestamp. Defaults to the current date if not provided.
|
|
211
|
+
* @param {boolean} pRequireEndDate - If true, the end date must be provided; otherwise, it defaults to the current date.
|
|
212
|
+
* @returns {number} The difference in years between the two dates. Returns NaN if the start date is invalid.
|
|
213
|
+
*/
|
|
214
|
+
dateYearDifference(pDateStart, pDateEnd, pRequireEndDate = false)
|
|
215
|
+
{
|
|
216
|
+
if ((pDateStart === undefined) || (pDateStart === null) || (pDateStart === ''))
|
|
217
|
+
{
|
|
218
|
+
return NaN;
|
|
219
|
+
}
|
|
220
|
+
if ((pRequireEndDate || (pRequireEndDate == 1) || (pRequireEndDate == '1')) && ((pDateEnd === undefined) || (pDateEnd === null) || (pDateEnd === '')))
|
|
221
|
+
{
|
|
222
|
+
return NaN;
|
|
223
|
+
}
|
|
224
|
+
let tmpStartDate = this.dayJS(pDateStart);
|
|
225
|
+
let tmpEndDate = this.dayJS(pDateEnd);
|
|
226
|
+
return tmpEndDate.diff(tmpStartDate, 'year');
|
|
227
|
+
}
|
|
128
228
|
}
|
|
129
229
|
|
|
130
230
|
module.exports = DateManipulation;
|
|
@@ -264,6 +264,22 @@
|
|
|
264
264
|
"Address": "fable.DataGeneration.randomFloatUpTo"
|
|
265
265
|
},
|
|
266
266
|
|
|
267
|
+
"datemilliseconddifference": {
|
|
268
|
+
"Name": "Date Difference in Milliseconds",
|
|
269
|
+
"Address": "fable.Dates.dateMillisecondDifference"
|
|
270
|
+
},
|
|
271
|
+
"dateseconddifference": {
|
|
272
|
+
"Name": "Date Difference in Seconds",
|
|
273
|
+
"Address": "fable.Dates.dateSecondDifference"
|
|
274
|
+
},
|
|
275
|
+
"dateminutedifference": {
|
|
276
|
+
"Name": "Date Difference in Minutes",
|
|
277
|
+
"Address": "fable.Dates.dateMinuteDifference"
|
|
278
|
+
},
|
|
279
|
+
"datehourdifference": {
|
|
280
|
+
"Name": "Date Difference in Hours",
|
|
281
|
+
"Address": "fable.Dates.dateHourDifference"
|
|
282
|
+
},
|
|
267
283
|
"datedaydifference": {
|
|
268
284
|
"Name": "Date Difference in Days",
|
|
269
285
|
"Address": "fable.Dates.dateDayDifference"
|
|
@@ -152,7 +152,7 @@ class FableServiceMath extends libFableServiceBase
|
|
|
152
152
|
toFixedPrecise(pValue, pDecimals, pRoundingMethod)
|
|
153
153
|
{
|
|
154
154
|
let tmpValue = isNaN(pValue) ? 0 : pValue;
|
|
155
|
-
let tmpDecimals = isNaN(pDecimals) ? 0 : pDecimals;
|
|
155
|
+
let tmpDecimals = isNaN(pDecimals) ? 0 : parseInt(pDecimals, 10);
|
|
156
156
|
let tmpRoundingMethod = (typeof (pRoundingMethod) === 'undefined') ? this.roundHalfUp : pRoundingMethod;
|
|
157
157
|
|
|
158
158
|
let tmpArbitraryValue = new this.bigNumber(tmpValue);
|
|
@@ -43,6 +43,50 @@ suite
|
|
|
43
43
|
return fDone();
|
|
44
44
|
}
|
|
45
45
|
);
|
|
46
|
+
test
|
|
47
|
+
(
|
|
48
|
+
'Get time differences between dates.',
|
|
49
|
+
function(fDone)
|
|
50
|
+
{
|
|
51
|
+
let testFable = new libFable();
|
|
52
|
+
let tmpDates = testFable.instantiateServiceProvider('Dates');
|
|
53
|
+
|
|
54
|
+
const tmpFirstDate = "2023-08-10T05:00:00.000Z";
|
|
55
|
+
const tmpSecondDate = "2023-08-11T05:00:00.000Z"; // 1 day later, precisely
|
|
56
|
+
const tmpThirdDate = "2023-03-11T11:01:01.030Z";
|
|
57
|
+
const tmpFourthDate = "2025-12-25T00:00:00.000Z";
|
|
58
|
+
|
|
59
|
+
Expect(tmpDates.dateMillisecondDifference(tmpFirstDate, tmpSecondDate)).to.equal(86400000);
|
|
60
|
+
Expect(tmpDates.dateSecondDifference(tmpFirstDate, tmpSecondDate)).to.equal(86400);
|
|
61
|
+
Expect(tmpDates.dateMinuteDifference(tmpFirstDate, tmpSecondDate)).to.equal(1440);
|
|
62
|
+
Expect(tmpDates.dateHourDifference(tmpFirstDate, tmpSecondDate)).to.equal(24);
|
|
63
|
+
Expect(tmpDates.dateDayDifference(tmpFirstDate, tmpSecondDate)).to.equal(1);
|
|
64
|
+
Expect(tmpDates.dateWeekDifference(tmpFirstDate, tmpSecondDate)).to.equal(0);
|
|
65
|
+
Expect(tmpDates.dateMonthDifference(tmpFirstDate, tmpSecondDate)).to.equal(0);
|
|
66
|
+
Expect(tmpDates.dateYearDifference(tmpFirstDate, tmpSecondDate)).to.equal(0);
|
|
67
|
+
|
|
68
|
+
Expect(tmpDates.dateMillisecondDifference(tmpFirstDate, tmpThirdDate)).to.equal(-13111138970);
|
|
69
|
+
Expect(tmpDates.dateSecondDifference(tmpFirstDate, tmpThirdDate)).to.equal(-13111138);
|
|
70
|
+
Expect(tmpDates.dateHourDifference(tmpFirstDate, tmpThirdDate)).to.equal(-3641);
|
|
71
|
+
Expect(tmpDates.dateDayDifference(tmpFirstDate, tmpThirdDate)).to.equal(-151);
|
|
72
|
+
Expect(tmpDates.dateWeekDifference(tmpFirstDate, tmpThirdDate)).to.equal(-21);
|
|
73
|
+
Expect(tmpDates.dateMonthDifference(tmpFirstDate, tmpThirdDate)).to.equal(-4);
|
|
74
|
+
Expect(tmpDates.dateYearDifference(tmpFirstDate, tmpThirdDate)).to.equal(0);
|
|
75
|
+
|
|
76
|
+
Expect(tmpDates.dateMillisecondDifference(tmpFirstDate, tmpFourthDate)).to.equal(74977200000);
|
|
77
|
+
Expect(tmpDates.dateSecondDifference(tmpFirstDate, tmpFourthDate)).to.equal(74977200);
|
|
78
|
+
Expect(tmpDates.dateHourDifference(tmpFirstDate, tmpFourthDate)).to.equal(20827);
|
|
79
|
+
Expect(tmpDates.dateDayDifference(tmpFirstDate, tmpFourthDate)).to.equal(867);
|
|
80
|
+
Expect(tmpDates.dateWeekDifference(tmpFirstDate, tmpFourthDate)).to.equal(123);
|
|
81
|
+
Expect(tmpDates.dateMonthDifference(tmpFirstDate, tmpFourthDate)).to.equal(28);
|
|
82
|
+
Expect(tmpDates.dateYearDifference(tmpFirstDate, tmpFourthDate)).to.equal(2);
|
|
83
|
+
|
|
84
|
+
// Test required end date behavior, specifically for solvers
|
|
85
|
+
Expect(tmpDates.dateYearDifference(tmpFirstDate, null, "1")).to.be.NaN;
|
|
86
|
+
Expect(tmpDates.dateYearDifference(tmpFirstDate, null)).to.not.be.NaN;
|
|
87
|
+
return fDone();
|
|
88
|
+
}
|
|
89
|
+
);
|
|
46
90
|
}
|
|
47
91
|
);
|
|
48
92
|
}
|
|
@@ -193,6 +193,18 @@ suite
|
|
|
193
193
|
Expect(_Parser.solve('7 +13')).to.equal("20");
|
|
194
194
|
Expect(_Parser.solve('7+14')).to.equal("21");
|
|
195
195
|
|
|
196
|
+
Expect(_Parser.solve('Result = datemilliseconddifference("2023-08-10T05:00:00.000Z", "2023-08-11T05:00:00.000Z")')).to.equal("86400000");
|
|
197
|
+
Expect(_Parser.solve('Result = datemilliseconddifference(StartDate, EndDate)', {StartDate: "2023-08-10T05:00:00.000Z", EndDate: "2023-08-11T05:00:00.000Z"})).to.equal("86400000");
|
|
198
|
+
Expect(_Parser.solve('Result = datemilliseconddifference(StartDate, EndDate)', {StartDate: "2023-08-10T05:11:00.000Z", EndDate: "2023-08-11T05:00:00.000Z"})).to.equal("85740000");
|
|
199
|
+
Expect(_Parser.solve('Result = datemilliseconddifference(StartDate, EndDate, 1)', {StartDate: "2023-08-10T05:11:00.000Z"})).to.equal('NaN');
|
|
200
|
+
Expect(_Parser.solve('Result = dateseconddifference(StartDate, EndDate)', {StartDate: "2023-08-10T05:00:00.000Z", EndDate: "2023-08-11T05:00:00.000Z"})).to.equal("86400");
|
|
201
|
+
Expect(_Parser.solve('Result = datehourdifference(StartDate, EndDate)', {StartDate: "2023-08-10T05:00:00.000Z", EndDate: "2023-08-11T05:00:00.000Z"})).to.equal("24");
|
|
202
|
+
Expect(_Parser.solve('Result = dateminutedifference(StartDate, EndDate)', {StartDate: "2023-08-10T05:00:00.000Z", EndDate: "2023-08-11T05:00:00.000Z"})).to.equal("1440");
|
|
203
|
+
Expect(_Parser.solve('Result = datehourdifference(StartDate, EndDate)', {StartDate: "2023-08-10T05:00:00.000Z", EndDate: "2023-08-11T05:00:00.000Z"})).to.equal("24");
|
|
204
|
+
Expect(_Parser.solve('Result = datedaydifference(StartDate, EndDate)', {StartDate: "2023-08-10T05:00:00.000Z", EndDate: "2023-08-11T05:00:00.000Z"})).to.equal("1");
|
|
205
|
+
Expect(_Parser.solve('Result = dateweekdifference(StartDate, EndDate)', {StartDate: "2023-08-10T05:00:00.000Z", EndDate: "2023-05-22T05:00:00.000Z"})).to.equal("-11");
|
|
206
|
+
Expect(_Parser.solve('Result = datemonthdifference(StartDate, EndDate)', {StartDate: "2023-08-10T05:00:00.000Z", EndDate: "2021-01-11T05:00:00.000Z"})).to.equal("-30");
|
|
207
|
+
Expect(_Parser.solve('Result = dateyeardifference(StartDate, EndDate)', {StartDate: "1986-08-10T05:00:00.000Z", EndDate: "2023-08-11T05:00:00.000Z"})).to.equal("37");
|
|
196
208
|
|
|
197
209
|
Expect(_Parser.solve('5 + 2 * 10')).to.equal("25");
|
|
198
210
|
Expect(_Parser.solve('3.5 + 5 + 10 * 10 / 5')).to.equal("28.5");
|