fable 3.1.28 → 3.1.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fable",
3
- "version": "3.1.28",
3
+ "version": "3.1.29",
4
4
  "description": "A service dependency injection, configuration and logging library.",
5
5
  "main": "source/Fable.js",
6
6
  "scripts": {
@@ -225,6 +225,81 @@ class DateManipulation extends libFableServiceProviderBase
225
225
  let tmpEndDate = this.dayJS(pDateEnd);
226
226
  return tmpEndDate.diff(tmpStartDate, 'year');
227
227
  }
228
+
229
+ dateAddMilliseconds(pDate, pAmount)
230
+ {
231
+ return this.dateMath(pDate, pAmount, 'millisecond', 'add');
232
+ }
233
+
234
+ dateAddSeconds(pDate, pAmount)
235
+ {
236
+ return this.dateMath(pDate, pAmount, 'second', 'add');
237
+ }
238
+
239
+ dateAddMinutes(pDate, pAmount)
240
+ {
241
+ return this.dateMath(pDate, pAmount, 'minute', 'add');
242
+ }
243
+
244
+ dateAddHours(pDate, pAmount)
245
+ {
246
+ return this.dateMath(pDate, pAmount, 'hour', 'add');
247
+ }
248
+
249
+ dateAddDays(pDate, pAmount)
250
+ {
251
+ return this.dateMath(pDate, pAmount, 'day', 'add');
252
+ }
253
+
254
+ dateAddWeeks(pDate, pAmount)
255
+ {
256
+ return this.dateMath(pDate, pAmount, 'week', 'add');
257
+ }
258
+
259
+ dateAddMonths(pDate, pAmount)
260
+ {
261
+ return this.dateMath(pDate, pAmount, 'month', 'add');
262
+ }
263
+
264
+ dateAddYears(pDate, pAmount)
265
+ {
266
+ return this.dateMath(pDate, pAmount, 'year', 'add');
267
+ }
268
+
269
+ dateMath(pDate, pAmount, pUnit, pOperation)
270
+ {
271
+ try
272
+ {
273
+ let tmpDate = this.dayJS.utc(pDate);
274
+
275
+ if (pOperation === 'add')
276
+ {
277
+ tmpDate = tmpDate.add(pAmount, pUnit);
278
+ }
279
+ else if (pOperation === 'subtract')
280
+ {
281
+ tmpDate = tmpDate.subtract(pAmount, pUnit);
282
+ }
283
+ return this.dayJS.utc(tmpDate).toISOString();
284
+ }
285
+ catch (pError)
286
+ {
287
+ return undefined;
288
+ }
289
+ }
290
+
291
+ dateFromParts(pYear, pMonth, pDay, pHour = 0, pMinute = 0, pSecond = 0, pMillisecond = 0)
292
+ {
293
+ try
294
+ {
295
+ let tmpDate = this.dayJS.utc().year(pYear).month(pMonth - 1).date(pDay).hour(pHour).minute(pMinute).second(pSecond).millisecond(pMillisecond);
296
+ return tmpDate.toISOString();
297
+ }
298
+ catch (pError)
299
+ {
300
+ return undefined;
301
+ }
302
+ }
228
303
  }
229
304
 
230
305
  module.exports = DateManipulation;
@@ -348,7 +348,49 @@
348
348
  "Address": "fable.Dates.dateYearDifference"
349
349
  },
350
350
 
351
- "createValueObjectByHashes": {
351
+ "datemathadd": {
352
+ "Name": "Date Math Add",
353
+ "Address": "fable.Dates.dateMath"
354
+ },
355
+ "dateaddmilliseconds": {
356
+ "Name": "Date Add Milliseconds",
357
+ "Address": "fable.Dates.dateAddMilliseconds"
358
+ },
359
+ "dateaddseconds": {
360
+ "Name": "Date Add Seconds",
361
+ "Address": "fable.Dates.dateAddSeconds"
362
+ },
363
+ "dateaddminutes": {
364
+ "Name": "Date Add Minutes",
365
+ "Address": "fable.Dates.dateAddMinutes"
366
+ },
367
+ "dateaddhours": {
368
+ "Name": "Date Add Hours",
369
+ "Address": "fable.Dates.dateAddHours"
370
+ },
371
+ "dateadddays": {
372
+ "Name": "Date Add Days",
373
+ "Address": "fable.Dates.dateAddDays"
374
+ },
375
+ "dateaddweeks": {
376
+ "Name": "Date Add Weeks",
377
+ "Address": "fable.Dates.dateAddWeeks"
378
+ },
379
+ "dateaddmonths": {
380
+ "Name": "Date Add Months",
381
+ "Address": "fable.Dates.dateAddMonths"
382
+ },
383
+ "dateaddyears": {
384
+ "Name": "Date Add Years",
385
+ "Address": "fable.Dates.dateAddYears"
386
+ },
387
+
388
+ "datefromparts": {
389
+ "Name": "Date From Parts",
390
+ "Address": "fable.Dates.dateFromParts"
391
+ },
392
+
393
+ "createvalueobjectbyhashes": {
352
394
  "Name": "Create Value Object by Hashes",
353
395
  "Address": "fable.Utility.createValueObjectByHashes"
354
396
  }
@@ -40,6 +40,10 @@ suite
40
40
  let tmpDatePacific = tmpDate.tz("America/Los_Angeles");
41
41
  testFable.log.trace(`Date Pacific formats to: ${tmpDatePacific.format()}`);
42
42
 
43
+ Expect(tmpDates.dateFromParts(2023, 8, 10, 5, 0, 0, 0)).to.equal("2023-08-10T05:00:00.000Z");
44
+ Expect(tmpDates.dateFromParts(2023, 8, 10)).to.equal("2023-08-10T00:00:00.000Z");
45
+ Expect(tmpDates.dateFromParts(2023, 12, 31, 23, 59, 59, 999)).to.equal("2023-12-31T23:59:59.999Z");
46
+
43
47
  return fDone();
44
48
  }
45
49
  );
@@ -87,6 +91,32 @@ suite
87
91
  return fDone();
88
92
  }
89
93
  );
94
+ test
95
+ (
96
+ 'Add or remove time from dates.',
97
+ function(fDone)
98
+ {
99
+ let testFable = new libFable();
100
+ let tmpDates = testFable.instantiateServiceProvider('Dates');
101
+
102
+ const tmpFirstDate = "2023-08-10T05:00:00.000Z";
103
+ const tmpSecondDate = "2023-08-11T05:00:00.000Z"; // 1 day later, precisely
104
+ const tmpThirdDate = "2023-03-11T11:01:01.030Z";
105
+ const tmpFourthDate = "2025-12-25T00:00:00.000Z";
106
+
107
+ Expect(tmpDates.dateAddDays(tmpFirstDate, 1)).to.equal(tmpSecondDate);
108
+ Expect(tmpDates.dateAddHours(tmpFirstDate, 24)).to.equal(tmpSecondDate);
109
+ Expect(tmpDates.dateAddHours(tmpFirstDate, "24")).to.equal(tmpSecondDate);
110
+ Expect(tmpDates.dateAddMinutes(tmpFirstDate, 1440)).to.equal(tmpSecondDate);
111
+ Expect(tmpDates.dateAddSeconds(tmpFirstDate, 86400)).to.equal(tmpSecondDate);
112
+ Expect(tmpDates.dateAddMilliseconds(tmpFirstDate, 86400000)).to.equal(tmpSecondDate);
113
+
114
+ Expect(tmpDates.dateAddDays(tmpSecondDate, -1)).to.equal(tmpFirstDate);
115
+ Expect(tmpDates.dateAddDays(tmpSecondDate, "-1")).to.equal(tmpFirstDate);
116
+
117
+ return fDone();
118
+ }
119
+ );
90
120
  }
91
121
  );
92
122
  }
@@ -319,6 +319,9 @@ suite
319
319
  let tmpHistogram = _Parser.solve(`aggregationhistogrambyobject(getvalue("AppData.Teams"), "States", "Score")`);
320
320
  Expect(tmpHistogram['New York']).to.equal("250");
321
321
 
322
+ Expect(_Parser.solve("DateFromPartsExample = DATEFROMPARTS(2025, 4, 1)")).to.equal("2025-04-01T00:00:00.000Z");
323
+ Expect(_Parser.solve("DateFromPartsExample = DATEADDDAYS(DATEFROMPARTS(2025, 4, 1, 13, 03, 51, 761),87)")).to.equal("2025-06-27T13:03:51.761Z");
324
+
322
325
  return fDone();
323
326
  }
324
327
  );