fable 3.0.83 → 3.0.84

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.0.83",
3
+ "version": "3.0.84",
4
4
  "description": "An entity behavior management and API bundling library.",
5
5
  "main": "source/Fable.js",
6
6
  "scripts": {
@@ -58,6 +58,7 @@
58
58
  "cachetrax": "^1.0.4",
59
59
  "cookie": "^0.5.0",
60
60
  "data-arithmatic": "^1.0.7",
61
+ "dayjs": "^1.11.10",
61
62
  "fable-log": "^3.0.12",
62
63
  "fable-serviceproviderbase": "^3.0.10",
63
64
  "fable-settings": "^3.0.8",
package/source/Fable.js CHANGED
@@ -46,6 +46,7 @@ class Fable
46
46
  this.serviceManager.addServiceType('Template', require('./services/Fable-Service-Template.js'));
47
47
  this.serviceManager.addServiceType('MetaTemplate', require('./services/Fable-Service-MetaTemplate.js'));
48
48
  this.serviceManager.addServiceType('Anticipate', require('./services/Fable-Service-Anticipate.js'));
49
+ this.serviceManager.addAndInstantiateServiceType('Dates', require('./services/Fable-Service-DateManipulation.js'));
49
50
  this.serviceManager.addAndInstantiateServiceType('DataFormat', require('./services/Fable-Service-DataFormat.js'));
50
51
  this.serviceManager.addAndInstantiateServiceType('DataGeneration', require('./services/Fable-Service-DataGeneration.js'));
51
52
  this.serviceManager.addAndInstantiateServiceType('Utility', require('./services/Fable-Service-Utility.js'));
@@ -0,0 +1,46 @@
1
+ const libFableServiceProviderBase = require('fable-serviceproviderbase');
2
+ /**
3
+ * Date management a la Moment using days.js
4
+ *
5
+ * @class DateManipulation
6
+ */
7
+ class DateManipulation extends libFableServiceProviderBase
8
+ {
9
+ constructor(pFable, pOptions, pServiceHash)
10
+ {
11
+ super(pFable, pOptions, pServiceHash)
12
+
13
+ this.serviceType = 'Dates';
14
+
15
+ this.dayJS = require('dayjs');
16
+
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
+
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
+ }
45
+
46
+ module.exports = DateManipulation;
@@ -84,7 +84,7 @@ class FableOperation extends libFableServiceBase
84
84
  this.writeOperationErrors(pLogText, pLogObject);
85
85
  this.fable.log.fatal(pLogText, pLogObject);
86
86
  }
87
-
87
+
88
88
  /************************************************************************
89
89
  * BEGINNING OF --> Telemetry Helpers
90
90
  */
@@ -94,21 +94,21 @@ class FableOperation extends libFableServiceBase
94
94
  this.timeStamps[tmpTimeStampHash] = +new Date();
95
95
  return this.timeStamps[tmpTimeStampHash];
96
96
  }
97
-
97
+
98
98
  getTimeDelta(pTimeStampHash)
99
99
  {
100
100
  let tmpTimeStampHash = (typeof(pTimeStampHash) == 'string') ? pTimeStampHash : 'Default';
101
101
  if (this.timeStamps.hasOwnProperty(tmpTimeStampHash))
102
102
  {
103
103
  let tmpEndTime = +new Date();
104
- return tmpEndTime-this.timeStamps[tmpTimeStampHash];
104
+ return tmpEndTime-this.timeStamps[tmpTimeStampHash];
105
105
  }
106
106
  else
107
107
  {
108
108
  return -1;
109
109
  }
110
110
  }
111
-
111
+
112
112
  logTimeDelta(pTimeStampHash, pMessage)
113
113
  {
114
114
  let tmpTimeStampHash = (typeof(pTimeStampHash) == 'string') ? pTimeStampHash : 'Default';
@@ -117,12 +117,12 @@ class FableOperation extends libFableServiceBase
117
117
  this.info(tmpMessage +' ('+tmpOperationTime+'ms)');
118
118
  return tmpOperationTime;
119
119
  }
120
-
120
+
121
121
  createProgressTracker(pTotalOperations, pProgressTrackerHash)
122
122
  {
123
123
  let tmpProgressTrackerHash = (typeof(pProgressTrackerHash) == 'string') ? pProgressTrackerHash : 'DefaultProgressTracker';
124
124
  let tmpTotalOperations = (typeof(pTotalOperations) == 'number') ? pTotalOperations : 100;
125
-
125
+
126
126
  let tmpProgressTracker = (
127
127
  {
128
128
  Hash: tmpProgressTrackerHash,
@@ -135,92 +135,92 @@ class FableOperation extends libFableServiceBase
135
135
  TotalCount: tmpTotalOperations,
136
136
  CurrentCount:-1
137
137
  });
138
-
138
+
139
139
  this.progressTrackers[tmpProgressTrackerHash] = tmpProgressTracker;
140
-
140
+
141
141
  return tmpProgressTracker;
142
142
  }
143
-
143
+
144
144
  solveProgressTrackerStatus(pProgressTrackerHash)
145
145
  {
146
146
  let tmpProgressTrackerHash = (typeof(pProgressTrackerHash) == 'string') ? pProgressTrackerHash : 'DefaultProgressTracker';
147
-
147
+
148
148
  if (!this.progressTrackers.hasOwnProperty(tmpProgressTrackerHash))
149
149
  {
150
150
  this.createProgressTracker(100, tmpProgressTrackerHash);
151
151
  }
152
-
152
+
153
153
  let tmpProgressTracker = this.progressTrackers[tmpProgressTrackerHash];
154
-
154
+
155
155
  tmpProgressTracker.CurrentTime = this.getTimeDelta(tmpProgressTracker.Hash);
156
-
156
+
157
157
  if ((tmpProgressTracker.CurrentCount > 0) && (tmpProgressTracker.TotalCount > 0))
158
158
  {
159
159
  tmpProgressTracker.PercentComplete = (tmpProgressTracker.CurrentCount / tmpProgressTracker.TotalCount) * 100.0;
160
160
  }
161
-
161
+
162
162
  if ((tmpProgressTracker.CurrentCount > 0) && (tmpProgressTracker.CurrentTime > 0))
163
163
  {
164
164
  tmpProgressTracker.AverageOperationTime = tmpProgressTracker.CurrentTime / tmpProgressTracker.CurrentCount;
165
165
  }
166
-
166
+
167
167
  if ((tmpProgressTracker.CurrentCount < tmpProgressTracker.TotalCount) && (tmpProgressTracker.AverageOperationTime > 0))
168
168
  {
169
169
  tmpProgressTracker.EstimatedCompletionTime = (tmpProgressTracker.TotalCount - tmpProgressTracker.CurrentCount) * tmpProgressTracker.AverageOperationTime;
170
170
  }
171
171
  }
172
-
172
+
173
173
  updateProgressTrackerStatus(pProgressTrackerHash, pCurrentOperations)
174
174
  {
175
175
  let tmpProgressTrackerHash = (typeof(pProgressTrackerHash) == 'string') ? pProgressTrackerHash : 'DefaultProgressTracker';
176
176
  let tmpCurrentOperations = parseInt(pCurrentOperations);
177
-
177
+
178
178
  if (isNaN(tmpCurrentOperations))
179
179
  {
180
180
  return false;
181
181
  }
182
-
182
+
183
183
  if (!this.progressTrackers.hasOwnProperty(tmpProgressTrackerHash))
184
184
  {
185
185
  this.createProgressTracker(100, tmpProgressTrackerHash);
186
186
  }
187
-
187
+
188
188
  this.progressTrackers[tmpProgressTrackerHash].CurrentCount = tmpCurrentOperations;
189
189
  this.progressTrackers[tmpProgressTrackerHash].CurrentTime = this.getTimeDelta(tmpProgressTrackerHash);
190
-
190
+
191
191
  this.solveProgressTrackerStatus(tmpProgressTrackerHash);
192
-
192
+
193
193
  return this.progressTrackers[tmpProgressTrackerHash];
194
194
  }
195
-
195
+
196
196
  incrementProgressTrackerStatus(pProgressTrackerHash, pIncrementSize)
197
197
  {
198
198
  let tmpProgressTrackerHash = (typeof(pProgressTrackerHash) == 'string') ? pProgressTrackerHash : 'DefaultProgressTracker';
199
199
  let tmpIncrementSize = parseInt(pIncrementSize);
200
-
200
+
201
201
  if (isNaN(tmpIncrementSize))
202
202
  {
203
203
  return false;
204
204
  }
205
-
205
+
206
206
  if (!this.progressTrackers.hasOwnProperty(tmpProgressTrackerHash))
207
207
  {
208
208
  this.createProgressTracker(100, tmpProgressTrackerHash);
209
209
  }
210
-
210
+
211
211
  this.progressTrackers[tmpProgressTrackerHash].CurrentCount = this.progressTrackers[tmpProgressTrackerHash].CurrentCount + tmpIncrementSize;
212
212
  this.progressTrackers[tmpProgressTrackerHash].CurrentTime = this.getTimeDelta(tmpProgressTrackerHash);
213
-
213
+
214
214
  this.solveProgressTrackerStatus(tmpProgressTrackerHash);
215
-
215
+
216
216
  return this.progressTrackers[tmpProgressTrackerHash];
217
217
  }
218
-
218
+
219
219
  setProgressTrackerEndTime(pProgressTrackerHash, pCurrentOperations)
220
220
  {
221
221
  let tmpProgressTrackerHash = (typeof(pProgressTrackerHash) == 'string') ? pProgressTrackerHash : 'DefaultProgressTracker';
222
222
  let tmpCurrentOperations = parseInt(pCurrentOperations);
223
-
223
+
224
224
  if (!this.progressTrackers.hasOwnProperty(tmpProgressTrackerHash))
225
225
  {
226
226
  return false;
@@ -229,18 +229,18 @@ class FableOperation extends libFableServiceBase
229
229
  {
230
230
  this.updateProgressTrackerStatus(tmpProgressTrackerHash, tmpCurrentOperations);
231
231
  }
232
-
232
+
233
233
  this.progressTrackers[tmpProgressTrackerHash].EndTime = this.getTimeDelta(tmpProgressTrackerHash);
234
-
234
+
235
235
  this.solveProgressTrackerStatus(tmpProgressTrackerHash);
236
-
236
+
237
237
  return this.progressTrackers[tmpProgressTrackerHash];
238
238
  }
239
-
239
+
240
240
  printProgressTrackerStatus(pProgressTrackerHash)
241
241
  {
242
242
  let tmpProgressTrackerHash = (typeof(pProgressTrackerHash) == 'string') ? pProgressTrackerHash : 'DefaultProgressTracker';
243
-
243
+
244
244
  if (!this.progressTrackers.hasOwnProperty(tmpProgressTrackerHash))
245
245
  {
246
246
  this.info(`>> Progress Tracker ${tmpProgressTrackerHash} does not exist! No stats to display.`);
@@ -248,7 +248,7 @@ class FableOperation extends libFableServiceBase
248
248
  else
249
249
  {
250
250
  const tmpProgressTracker = this.progressTrackers[tmpProgressTrackerHash];
251
-
251
+
252
252
  if (tmpProgressTracker.CurrentCount < 1)
253
253
  {
254
254
  this.info(`>> Progress Tracker ${tmpProgressTracker.Hash} has no completed operations. ${tmpProgressTracker.CurrentTime}ms have elapsed since it was started.`);
@@ -263,12 +263,12 @@ class FableOperation extends libFableServiceBase
263
263
  }
264
264
  }
265
265
  }
266
-
266
+
267
267
  // logMemoryResourcesUsed()
268
268
  // {
269
- //
269
+ //
270
270
  // const tmpResourcesUsed = process.memoryUsage().heapUsed / 1024 / 1024;
271
- // this.info(`Memory usage at ${Math.round(tmpResourcesUsed * 100) / 100} MB`);
271
+ // this.info(`Memory usage at ${Math.round(tmpResourcesUsed * 100) / 100} MB`);
272
272
  // }
273
273
  /*
274
274
  * END OF --> Logging and Telemetry Helpers
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Unit tests for Fable
3
+ *
4
+ * @license MIT
5
+ *
6
+ * @author Steven Velozo <steven@velozo.com>
7
+ */
8
+
9
+ var libFable = require('../source/Fable.js');
10
+
11
+ const libFS = require('fs');
12
+
13
+ var Chai = require("chai");
14
+ var Expect = Chai.expect;
15
+
16
+ suite
17
+ (
18
+ 'Date Manipulation',
19
+ function()
20
+ {
21
+ suite
22
+ (
23
+ 'Manipulate Dates',
24
+ function()
25
+ {
26
+ test
27
+ (
28
+ 'Get a Date and Format it',
29
+ function(fDone)
30
+ {
31
+ let testFable = new libFable();
32
+ let tmpDates = testFable.serviceManager.instantiateServiceProvider('Dates');
33
+
34
+ testFable.log.info(`Guessing your timezone: ${tmpDates.dayJS.tz.guess()}`);
35
+
36
+ // tmpDates.dayJS.tz('Etc/UTC');
37
+
38
+ let tmpDate = tmpDates.dayJS.utc("2023-08-10T05:00:00.000Z");
39
+ testFable.log.trace(`Date formats to: ${tmpDate.format()}`);
40
+ let tmpDateCentral = tmpDate.tz("America/Chicago");
41
+ testFable.log.trace(`Date Central formats to: ${tmpDateCentral.format()}`);
42
+ let tmpDatePacific = tmpDate.tz("America/Los_Angeles");
43
+ testFable.log.trace(`Date Pacific formats to: ${tmpDatePacific.format()}`);
44
+
45
+ return fDone();
46
+ }
47
+ );
48
+ }
49
+ );
50
+ }
51
+ );