@ejfdelgado/ejflab-common 1.0.0
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/LICENSE +201 -0
- package/README.md +2 -0
- package/package.json +29 -0
- package/src/CollisionsEngine.js +252 -0
- package/src/CsvFormatter.js +54 -0
- package/src/CsvFormatter.test.js +119 -0
- package/src/CsvFormatterFilters.js +79 -0
- package/src/CsvParser.js +51 -0
- package/src/CsvParser.test.js +41 -0
- package/src/CsvWithFilters.js +114 -0
- package/src/FaceEncoder.js +64 -0
- package/src/FlowChartDiagram.js +503 -0
- package/src/IdGen.js +211 -0
- package/src/ModuloDatoSeguro.js +142 -0
- package/src/ModuloDatoSeguro.test.js +29 -0
- package/src/ModuloDatoSeguro.test.mjs +45 -0
- package/src/ModuloDatoSeguroBack.mjs +55 -0
- package/src/ModuloDatoSeguroFront.js +73 -0
- package/src/ModuloSonido.js +83 -0
- package/src/ModuloVideos.js +51 -0
- package/src/MyColor.js +136 -0
- package/src/MyColor.test.js +37 -0
- package/src/MyConstants.js +147 -0
- package/src/MyCookies.js +34 -0
- package/src/MyDates.js +412 -0
- package/src/MyDates.test.js +26 -0
- package/src/MyDatesBack.mjs +21 -0
- package/src/MyDatesFront.js +41 -0
- package/src/MyJsPdf.js +52 -0
- package/src/MyRoutes.js +29 -0
- package/src/MyTemplate.js +272 -0
- package/src/MyTemplate.test.js +90 -0
- package/src/MyTensorflow.js +248 -0
- package/src/MyTensorflow.test.js +19 -0
- package/src/MyTensorflowBack.mjs +33 -0
- package/src/MyThrottle.js +80 -0
- package/src/MyTuples.js +445 -0
- package/src/MyTuples.test.js +330 -0
- package/src/MyUtilities.js +137 -0
- package/src/SimpleObj.js +153 -0
- package/src/SimpleObj.test.js +58 -0
- package/src/TriangulacionGeometric.js +335 -0
- package/src/changePath.js +38 -0
- package/src/data/case0.csv +3 -0
- package/src/data/case0.json +24 -0
- package/src/data/case1.csv +2 -0
- package/src/data/case1.json +24 -0
- package/src/data/case2.csv +3 -0
- package/src/data/case2.json +24 -0
- package/src/data/case3.csv +3 -0
- package/src/data/case3.json +24 -0
- package/src/data/format0.json +0 -0
- package/src/data/format0.txt +1 -0
- package/src/data/tensordata.csv +10 -0
- package/src/data/tensordata.json +37 -0
- package/src/data/tensordata.test.csv +10 -0
- package/src/data/tensormodel.json +113 -0
- package/src/fft.js +224 -0
- package/src/flowchart/FlowChartExec.js +763 -0
- package/src/flowchart/steps/CommandBasic.js +32 -0
- package/src/flowchart/steps/CommandInc.js +19 -0
- package/src/flowchart/steps/CommandMilvus.js +47 -0
- package/src/flowchart/steps/CommandMinio.js +28 -0
- package/src/flowchart/steps/CommandMongo.js +59 -0
- package/src/flowchart/steps/CommandPrint.js +12 -0
- package/src/flowchart/steps/CommandSet.js +14 -0
- package/src/flowchart/steps/CommandTimeline.js +21 -0
- package/src/flowchart/steps/CommandTimelineNext.js +28 -0
- package/src/flowchart/steps/StepBasic.js +184 -0
- package/src/flowchart/steps/StepCheckProcessor.js +26 -0
- package/src/flowchart/steps/StepCheckSrc.js +42 -0
- package/src/flowchart/steps/StepIsTrue.js +12 -0
- package/src/flowchart/steps/StepOneTime.js +21 -0
- package/src/flowchart/steps/StepProcess.js +163 -0
- package/src/flowchart/steps/StepReadSrc.js +66 -0
- package/src/flowchart/steps/StepSleep.js +22 -0
- package/src/flowchart/steps/StepTimeLineEnds.js +21 -0
- package/src/flowchart/steps/StepTimeLineHasMore.js +16 -0
- package/src/gif/index.d.ts +20 -0
- package/src/gif/index.mjs +85 -0
- package/src/gif/utils/checkTypes.d.ts +2 -0
- package/src/gif/utils/checkTypes.mjs +11 -0
- package/src/js-colormaps.js +19484 -0
- package/src/sortify.js +75 -0
- package/src/sqlmodelparser/SqlModelParser.js +22 -0
- package/src/test/csv/test_1000_20230429204538700.csv +1001 -0
- package/src/test/csv/test_5_20230429204525930.csv +6 -0
- package/src/test/svg/test.html +5 -0
package/src/MyDates.js
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
const offset = new Date().getTimezoneOffset() / 60;
|
|
2
|
+
|
|
3
|
+
class MyDates {
|
|
4
|
+
static getSelectedLanguage() {
|
|
5
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
6
|
+
const lan = urlParams.get('l');
|
|
7
|
+
return lan;
|
|
8
|
+
}
|
|
9
|
+
static configureLocale(i18n, masks, lan = "es") {
|
|
10
|
+
if (lan == "es") {
|
|
11
|
+
i18n.dayNames = [
|
|
12
|
+
"Dom",
|
|
13
|
+
"Lun",
|
|
14
|
+
"Mar",
|
|
15
|
+
"Mié",
|
|
16
|
+
"Jue",
|
|
17
|
+
"Vie",
|
|
18
|
+
"Sab",
|
|
19
|
+
"Domingo",
|
|
20
|
+
"Lunes",
|
|
21
|
+
"Martes",
|
|
22
|
+
"Miércoles",
|
|
23
|
+
"Jueves",
|
|
24
|
+
"Viernes",
|
|
25
|
+
"Sábado",
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
i18n.monthNames = [
|
|
29
|
+
"Ene",
|
|
30
|
+
"Feb",
|
|
31
|
+
"Mar",
|
|
32
|
+
"Abr",
|
|
33
|
+
"May",
|
|
34
|
+
"Jun",
|
|
35
|
+
"Jul",
|
|
36
|
+
"Ago",
|
|
37
|
+
"Sep",
|
|
38
|
+
"Oct",
|
|
39
|
+
"Nov",
|
|
40
|
+
"Dic",
|
|
41
|
+
"Enero",
|
|
42
|
+
"Febrero",
|
|
43
|
+
"Marzo",
|
|
44
|
+
"Abril",
|
|
45
|
+
"Mayo",
|
|
46
|
+
"Junio",
|
|
47
|
+
"Julio",
|
|
48
|
+
"Agosto",
|
|
49
|
+
"Septiembre",
|
|
50
|
+
"Octubre",
|
|
51
|
+
"Noviembre",
|
|
52
|
+
"Diciembre",
|
|
53
|
+
];
|
|
54
|
+
} else if (lan == "en") {
|
|
55
|
+
i18n.dayNames = [
|
|
56
|
+
"Sun",
|
|
57
|
+
"Mon",
|
|
58
|
+
"Thu",
|
|
59
|
+
"Wed",
|
|
60
|
+
"Thr",
|
|
61
|
+
"Fri",
|
|
62
|
+
"Sat",
|
|
63
|
+
"Sunday",
|
|
64
|
+
"Monday",
|
|
65
|
+
"Thuesday",
|
|
66
|
+
"Wednesday",
|
|
67
|
+
"Thursday",
|
|
68
|
+
"Friday",
|
|
69
|
+
"Saturday",
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
i18n.monthNames = [
|
|
73
|
+
"Jan",
|
|
74
|
+
"Feb",
|
|
75
|
+
"Mar",
|
|
76
|
+
"Apr",
|
|
77
|
+
"May",
|
|
78
|
+
"Jun",
|
|
79
|
+
"Jul",
|
|
80
|
+
"Aug",
|
|
81
|
+
"Sep",
|
|
82
|
+
"Oct",
|
|
83
|
+
"Nov",
|
|
84
|
+
"Dec",
|
|
85
|
+
"January",
|
|
86
|
+
"February",
|
|
87
|
+
"March",
|
|
88
|
+
"April",
|
|
89
|
+
"May",
|
|
90
|
+
"June",
|
|
91
|
+
"July",
|
|
92
|
+
"August",
|
|
93
|
+
"September",
|
|
94
|
+
"October",
|
|
95
|
+
"November",
|
|
96
|
+
"December",
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
i18n.timeNames = ["a", "p", "am", "pm", "A", "P", "AM", "PM"];
|
|
101
|
+
|
|
102
|
+
masks.opcion1 = 'dddd, mmmm d, yyyy';
|
|
103
|
+
masks.opcion2 = 'dddd, mmmm d';
|
|
104
|
+
|
|
105
|
+
masks.simple1 = 'ddd d mmm, yyyy';
|
|
106
|
+
masks.simple2 = 'ddd d mmm';
|
|
107
|
+
|
|
108
|
+
masks.opcion3 = 'h:MM TT';
|
|
109
|
+
|
|
110
|
+
// yyyy-MM-ddTHH:mm:ss
|
|
111
|
+
// https://www.npmjs.com/package/dateformat
|
|
112
|
+
masks.opcionPayu = 'yyyy-mm-dd"T"HH:MM:ss';
|
|
113
|
+
|
|
114
|
+
masks.completo1 = 'ddd d mmm, yyyy h:MM:ss TT';
|
|
115
|
+
masks.completo2 = 'ddd d mmm h:MM:ss TT';
|
|
116
|
+
}
|
|
117
|
+
static getDates(epoch) {
|
|
118
|
+
let hoy;
|
|
119
|
+
if (typeof epoch == "number") {
|
|
120
|
+
hoy = new Date(epoch);
|
|
121
|
+
} else {
|
|
122
|
+
hoy = new Date();
|
|
123
|
+
}
|
|
124
|
+
const manana = new Date(hoy.getTime());
|
|
125
|
+
manana.setDate(manana.getDate() + 1);
|
|
126
|
+
const mananaInicio = new Date(manana.getUTCFullYear(), manana.getUTCMonth(), manana.getUTCDate());
|
|
127
|
+
const ayer = new Date(hoy.getTime());
|
|
128
|
+
ayer.setDate(ayer.getDate() - 1);
|
|
129
|
+
const actual = MyDates.getDayAsContinuosNumber(hoy);
|
|
130
|
+
const siguiente = MyDates.getDayAsContinuosNumber(manana);
|
|
131
|
+
const anterior = MyDates.getDayAsContinuosNumber(ayer);
|
|
132
|
+
return {
|
|
133
|
+
actual,
|
|
134
|
+
siguiente,
|
|
135
|
+
anterior,
|
|
136
|
+
deadline: (mananaInicio.getTime() - hoy.getTime()),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
static formatDateBasic(dateformat, now, ...args) {
|
|
140
|
+
if (now instanceof Date) {
|
|
141
|
+
if (new Date().getFullYear() == now.getFullYear()) {
|
|
142
|
+
return dateformat(now, "opcion2");
|
|
143
|
+
} else {
|
|
144
|
+
return dateformat(now, "opcion1");
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
return "Día / Mes / Año";
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
static formatDateSimpleBasic(dateformat, now, ...args) {
|
|
151
|
+
if (now instanceof Date) {
|
|
152
|
+
if (new Date().getFullYear() == now.getFullYear()) {
|
|
153
|
+
return dateformat(now, "simple2");
|
|
154
|
+
} else {
|
|
155
|
+
return dateformat(now, "simple1");
|
|
156
|
+
}
|
|
157
|
+
} else {
|
|
158
|
+
return "Día / Mes / Año";
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
static formatDateCompletoBasic(dateformat, now, ...args) {
|
|
162
|
+
if (now instanceof Date) {
|
|
163
|
+
if (new Date().getFullYear() == now.getFullYear()) {
|
|
164
|
+
return dateformat(now, "completo2");
|
|
165
|
+
} else {
|
|
166
|
+
return dateformat(now, "completo1");
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
return "Día / Mes / Año Hora:Minutos:Segundos";
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
static formatTimeBasic(dateformat, now, ...args) {
|
|
173
|
+
if (now instanceof Date) {
|
|
174
|
+
return dateformat(now, "opcion3");
|
|
175
|
+
} else {
|
|
176
|
+
return "Hora / Minuto";
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
static formatPayu(dateformat, now) {
|
|
180
|
+
if (now instanceof Date) {
|
|
181
|
+
return dateformat(now, "opcionPayu");
|
|
182
|
+
} else {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
static createDuration(dias = 0, horas = 0, minutos = 0) {
|
|
187
|
+
const actual = new Date(1970, 0, dias + 1, horas - offset, minutos).getTime();
|
|
188
|
+
return actual;
|
|
189
|
+
}
|
|
190
|
+
static getDaysFromDuration(epoch) {
|
|
191
|
+
return new Date(epoch).getUTCDate() - 1;
|
|
192
|
+
}
|
|
193
|
+
static getHoursFromDuration(epoch) {
|
|
194
|
+
return new Date(epoch).getUTCHours();
|
|
195
|
+
}
|
|
196
|
+
static getMinutesFromDuration(epoch) {
|
|
197
|
+
return new Date(epoch).getUTCMinutes();
|
|
198
|
+
}
|
|
199
|
+
static AAAAMMDD2unixUTC(aaaammdd) {
|
|
200
|
+
let temporal = aaaammdd;
|
|
201
|
+
const fecha = new Date(0);
|
|
202
|
+
const dia = temporal % 100;
|
|
203
|
+
temporal = Math.floor((temporal - dia) / 100);
|
|
204
|
+
const mes = temporal % 100;
|
|
205
|
+
const anio = Math.floor((temporal - mes) / 100);
|
|
206
|
+
//console.log(`${anio} / ${mes} / ${dia}`);
|
|
207
|
+
fecha.setUTCDate(dia);
|
|
208
|
+
fecha.setUTCMonth(mes - 1);
|
|
209
|
+
fecha.setUTCFullYear(anio);
|
|
210
|
+
return fecha.getTime();
|
|
211
|
+
}
|
|
212
|
+
static AAAAMMDD2unix(aaaammdd) {
|
|
213
|
+
let temporal = aaaammdd;
|
|
214
|
+
const fecha = new Date(0);
|
|
215
|
+
const dia = temporal % 100;
|
|
216
|
+
temporal = Math.floor((temporal - dia) / 100);
|
|
217
|
+
const mes = temporal % 100;
|
|
218
|
+
const anio = Math.floor((temporal - mes) / 100);
|
|
219
|
+
//console.log(`${anio} / ${mes} / ${dia}`);
|
|
220
|
+
fecha.setDate(dia);
|
|
221
|
+
fecha.setMonth(mes - 1);
|
|
222
|
+
fecha.setFullYear(anio);
|
|
223
|
+
return fecha.getTime();
|
|
224
|
+
}
|
|
225
|
+
static AAAAMMDDhhmmss2unixUTC(aaaammdd) {
|
|
226
|
+
let temporal = aaaammdd;
|
|
227
|
+
const fecha = new Date(0);
|
|
228
|
+
const segundos = temporal % 100;
|
|
229
|
+
temporal = Math.floor((temporal - segundos) / 100);
|
|
230
|
+
const minutos = temporal % 100;
|
|
231
|
+
temporal = Math.floor((temporal - minutos) / 100);
|
|
232
|
+
const horas = temporal % 100;
|
|
233
|
+
temporal = Math.floor((temporal - horas) / 100);
|
|
234
|
+
const dia = temporal % 100;
|
|
235
|
+
temporal = Math.floor((temporal - dia) / 100);
|
|
236
|
+
const mes = temporal % 100;
|
|
237
|
+
const anio = Math.floor((temporal - mes) / 100);
|
|
238
|
+
//console.log(`${anio} / ${mes} / ${dia} - ${horas}:${minutos}:${segundos}`);
|
|
239
|
+
fecha.setUTCSeconds(segundos);
|
|
240
|
+
fecha.setUTCMinutes(minutos);
|
|
241
|
+
fecha.setUTCHours(horas);
|
|
242
|
+
fecha.setUTCDate(dia);
|
|
243
|
+
fecha.setUTCMonth(mes - 1);
|
|
244
|
+
fecha.setUTCFullYear(anio);
|
|
245
|
+
return fecha.getTime();
|
|
246
|
+
}
|
|
247
|
+
static AAAAMMDDhhmmss2unix(aaaammdd) {
|
|
248
|
+
let temporal = aaaammdd;
|
|
249
|
+
const fecha = new Date(0);
|
|
250
|
+
const segundos = temporal % 100;
|
|
251
|
+
temporal = Math.floor((temporal - segundos) / 100);
|
|
252
|
+
const minutos = temporal % 100;
|
|
253
|
+
temporal = Math.floor((temporal - minutos) / 100);
|
|
254
|
+
const horas = temporal % 100;
|
|
255
|
+
temporal = Math.floor((temporal - horas) / 100);
|
|
256
|
+
const dia = temporal % 100;
|
|
257
|
+
temporal = Math.floor((temporal - dia) / 100);
|
|
258
|
+
const mes = temporal % 100;
|
|
259
|
+
const anio = Math.floor((temporal - mes) / 100);
|
|
260
|
+
//console.log(`${anio} / ${mes} / ${dia} - ${horas}:${minutos}:${segundos}`);
|
|
261
|
+
fecha.setSeconds(segundos);
|
|
262
|
+
fecha.setMinutes(minutos);
|
|
263
|
+
fecha.setHours(horas);
|
|
264
|
+
fecha.setDate(dia);
|
|
265
|
+
fecha.setMonth(mes - 1);
|
|
266
|
+
fecha.setFullYear(anio);
|
|
267
|
+
return fecha.getTime();
|
|
268
|
+
}
|
|
269
|
+
static getDayAsContinuosNumber(fecha) {
|
|
270
|
+
const anio = fecha.getUTCFullYear();
|
|
271
|
+
const mes = fecha.getUTCMonth() + 1;
|
|
272
|
+
const dia = fecha.getUTCDate();
|
|
273
|
+
return dia + 100 * mes + anio * 10000;
|
|
274
|
+
}
|
|
275
|
+
// Esta función es muy peligrosa porque supera MAX SAFE INTEGER constant is
|
|
276
|
+
//9007199254740991
|
|
277
|
+
//20231204093015
|
|
278
|
+
static getDayAsContinuosNumberHmmSSmmm(fecha) {
|
|
279
|
+
const anio = fecha.getUTCFullYear();
|
|
280
|
+
const mes = fecha.getUTCMonth() + 1;
|
|
281
|
+
const dia = fecha.getUTCDate();
|
|
282
|
+
const horas = fecha.getUTCHours();//00
|
|
283
|
+
const minutos = fecha.getUTCMinutes();//00
|
|
284
|
+
const segundos = fecha.getUTCSeconds();//00
|
|
285
|
+
const milisegundos = fecha.getUTCMilliseconds();//000
|
|
286
|
+
return milisegundos + 1000 * segundos + minutos * 100000 + horas * 10000000 + dia * 1000000000 + 100000000000 * mes + anio * 10000000000000;
|
|
287
|
+
}
|
|
288
|
+
static getDayAsContinuosNumberHmmSS(fecha) {
|
|
289
|
+
const anio = fecha.getUTCFullYear();
|
|
290
|
+
const mes = fecha.getUTCMonth() + 1;
|
|
291
|
+
const dia = fecha.getUTCDate();
|
|
292
|
+
const horas = fecha.getUTCHours();//00
|
|
293
|
+
const minutos = fecha.getUTCMinutes();//00
|
|
294
|
+
const segundos = fecha.getUTCSeconds();//00
|
|
295
|
+
return segundos + minutos * 100 + horas * 10000 + dia * 1000000 + 100000000 * mes + anio * 10000000000;
|
|
296
|
+
}
|
|
297
|
+
static isToday(someDate) {
|
|
298
|
+
const fecha = new Date(someDate);
|
|
299
|
+
const ahora = new Date();
|
|
300
|
+
const anio0 = ahora.getFullYear();
|
|
301
|
+
const mes0 = ahora.getMonth();
|
|
302
|
+
const dia0 = ahora.getDate();
|
|
303
|
+
|
|
304
|
+
const isToday = (fecha.getFullYear() == anio0 && fecha.getMonth() == mes0 && fecha.getDate() == dia0);
|
|
305
|
+
return isToday;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
static lPad2(n) {
|
|
309
|
+
return ('0' + n).slice(-2);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
static lPad3(n) {
|
|
313
|
+
return ('00' + n).slice(-3);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
static listGenerator(min, max, pad = false) {
|
|
317
|
+
const response = [];
|
|
318
|
+
if (!pad) {
|
|
319
|
+
for (let i = min; i <= max; i++) {
|
|
320
|
+
response.push({ label: "" + i, value: "" + i })
|
|
321
|
+
}
|
|
322
|
+
} else {
|
|
323
|
+
for (let i = min; i <= max; i++) {
|
|
324
|
+
response.push({ label: MyDates.lPad2(i), value: "" + i })
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return response;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
static toAAAAMMDD(siguiente, predeterminado = "") {
|
|
331
|
+
if (typeof siguiente == "string") {
|
|
332
|
+
siguiente = parseInt(siguiente);
|
|
333
|
+
}
|
|
334
|
+
if (typeof siguiente == "number") {
|
|
335
|
+
if (isNaN(siguiente)) {
|
|
336
|
+
return predeterminado;
|
|
337
|
+
}
|
|
338
|
+
siguiente = new Date(siguiente);
|
|
339
|
+
}
|
|
340
|
+
if (!(siguiente instanceof Date)) {
|
|
341
|
+
return predeterminado;
|
|
342
|
+
}
|
|
343
|
+
const anio1 = siguiente.getFullYear();
|
|
344
|
+
const mes1 = siguiente.getMonth() + 1;
|
|
345
|
+
const dia1 = siguiente.getDate();
|
|
346
|
+
return anio1 + MyDates.lPad2(mes1) + MyDates.lPad2(dia1);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
static toHHMMssmm(siguiente) {
|
|
350
|
+
const esNegativo = (siguiente < 0);
|
|
351
|
+
if (esNegativo) {
|
|
352
|
+
siguiente *= -1;
|
|
353
|
+
}
|
|
354
|
+
const segundosTemp = Math.floor(siguiente / 1000);
|
|
355
|
+
const milis = siguiente - 1000 * segundosTemp;
|
|
356
|
+
const segundos = segundosTemp % 60;
|
|
357
|
+
let minutosTemp = (segundosTemp - segundos) / 60;
|
|
358
|
+
const minutos = minutosTemp % 60;
|
|
359
|
+
const hora = (minutosTemp - minutos) / 60;
|
|
360
|
+
if (hora > 0) {
|
|
361
|
+
return `${esNegativo ? '-' : ''}${MyDates.lPad2(hora)}:${MyDates.lPad2(minutos)}:${MyDates.lPad2(segundos)}.${MyDates.lPad3(milis)}`;
|
|
362
|
+
} else {
|
|
363
|
+
if (minutos > 0) {
|
|
364
|
+
return `${esNegativo ? '-' : ''}${MyDates.lPad2(minutos)}:${MyDates.lPad2(segundos)}.${MyDates.lPad3(milis)}`;
|
|
365
|
+
} else {
|
|
366
|
+
if (segundos > 0) {
|
|
367
|
+
return `${esNegativo ? '-' : ''}${MyDates.lPad2(segundos)}.${MyDates.lPad3(milis)}`;
|
|
368
|
+
} else {
|
|
369
|
+
return `${esNegativo ? '-' : ''}00.${MyDates.lPad3(milis)}`;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
static toAAAAMMDDHHmmss(siguiente, predeterminado = "") {
|
|
376
|
+
if (typeof siguiente == "string") {
|
|
377
|
+
siguiente = parseInt(siguiente);
|
|
378
|
+
}
|
|
379
|
+
if (typeof siguiente == "number") {
|
|
380
|
+
if (isNaN(siguiente)) {
|
|
381
|
+
return predeterminado;
|
|
382
|
+
}
|
|
383
|
+
siguiente = new Date(siguiente);
|
|
384
|
+
}
|
|
385
|
+
if (!(siguiente instanceof Date)) {
|
|
386
|
+
return predeterminado;
|
|
387
|
+
}
|
|
388
|
+
const anio1 = siguiente.getFullYear();
|
|
389
|
+
const mes1 = siguiente.getMonth() + 1;
|
|
390
|
+
const dia1 = siguiente.getDate();
|
|
391
|
+
const hora = siguiente.getHours();
|
|
392
|
+
const minutos = siguiente.getMinutes();
|
|
393
|
+
const segundos = siguiente.getSeconds();
|
|
394
|
+
return `${anio1}/${MyDates.lPad2(mes1)}/${MyDates.lPad2(dia1)} ${MyDates.lPad2(hora)}:${MyDates.lPad2(minutos)}:${MyDates.lPad2(segundos)}`;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
static secondsToHms(d) {
|
|
398
|
+
d = Number(d);
|
|
399
|
+
var h = Math.floor(d / 3600);
|
|
400
|
+
var m = Math.floor(d % 3600 / 60);
|
|
401
|
+
var s = Math.floor(d % 3600 % 60);
|
|
402
|
+
|
|
403
|
+
var hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours, ") : "";
|
|
404
|
+
var mDisplay = m > 0 ? m + (m == 1 ? " minute, " : " minutes, ") : "";
|
|
405
|
+
var sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
|
|
406
|
+
return hDisplay + mDisplay + sDisplay;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
module.exports = {
|
|
411
|
+
MyDates
|
|
412
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const { MyDates } = require('./MyDates.js');
|
|
2
|
+
|
|
3
|
+
const pool = [
|
|
4
|
+
{ input: 5156, expected: "05.156" },
|
|
5
|
+
{ input: 61156, expected: "01:01.156" },
|
|
6
|
+
{ input: 121156, expected: "02:01.156" },
|
|
7
|
+
{ input: -5156, expected: "-05.156" },
|
|
8
|
+
{ input: -61156, expected: "-01:01.156" },
|
|
9
|
+
{ input: -121156, expected: "-02:01.156" },
|
|
10
|
+
{ input: 3600010, expected: "01:00:00.010" },
|
|
11
|
+
{ input: 3600000, expected: "01:00:00.000" },
|
|
12
|
+
];
|
|
13
|
+
console.log("Testing...");
|
|
14
|
+
for (let i = 0; i < pool.length; i++) {
|
|
15
|
+
const { input, expected } = pool[i];
|
|
16
|
+
const actual = MyDates.toHHMMssmm(input);
|
|
17
|
+
if (actual != expected) {
|
|
18
|
+
throw new Error(`Para ${input} se esperaba ${expected} pero se tuvo ${actual}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const prueba = MyDates.AAAAMMDDhhmmss2unix(20180101000000);
|
|
23
|
+
console.log(`prueba = ${MyDates.getDayAsContinuosNumberHmmSS(new Date(prueba))}`);
|
|
24
|
+
|
|
25
|
+
const response = MyDates.secondsToHms(1000);
|
|
26
|
+
console.log(response);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import dateFormat, { masks, i18n } from "dateformat";
|
|
2
|
+
import { MyDates } from './MyDates.js';
|
|
3
|
+
|
|
4
|
+
MyDates.configureLocale(i18n, masks);
|
|
5
|
+
export default class MyDatesBack extends MyDates {
|
|
6
|
+
static formatDate(now, ...args) {
|
|
7
|
+
return MyDates.formatDateBasic(dateFormat, now, args);
|
|
8
|
+
}
|
|
9
|
+
static formatDateSimple(now, ...args) {
|
|
10
|
+
return MyDates.formatDateSimpleBasic(dateFormat, now, args);
|
|
11
|
+
}
|
|
12
|
+
static formatTime(now, ...args) {
|
|
13
|
+
return MyDates.formatTimeBasic(dateFormat, now, args);
|
|
14
|
+
}
|
|
15
|
+
static formatDateCompleto(now, ...args) {
|
|
16
|
+
return MyDates.formatDateCompletoBasic(dateFormat, now, args);
|
|
17
|
+
}
|
|
18
|
+
static formatPayu(now) {
|
|
19
|
+
return MyDates.formatPayu(dateFormat, now);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const dateformat = require('dateformat');
|
|
2
|
+
const { MyDates } = require('./MyDates.js');
|
|
3
|
+
|
|
4
|
+
class MyDatesFront extends MyDates {
|
|
5
|
+
static timeDifference = 0;
|
|
6
|
+
static {
|
|
7
|
+
// Se captura la fecha del html
|
|
8
|
+
const serverTime = document
|
|
9
|
+
.getElementById('meta_time')
|
|
10
|
+
?.getAttribute('content');
|
|
11
|
+
if (typeof serverTime == 'string' && serverTime.length > 0) {
|
|
12
|
+
this.timeDifference = new Date().getTime() - parseInt(serverTime);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
static formatDate(now, ...args) {
|
|
16
|
+
return MyDates.formatDateBasic(dateformat.default, now, args);
|
|
17
|
+
}
|
|
18
|
+
static formatDateCompleto(now, ...args) {
|
|
19
|
+
return MyDates.formatDateCompletoBasic(dateformat.default, now, args);
|
|
20
|
+
}
|
|
21
|
+
static formatDateSimple(now, ...args) {
|
|
22
|
+
return MyDates.formatDateSimpleBasic(dateformat.default, now, args);
|
|
23
|
+
}
|
|
24
|
+
static formatTime(now, ...args) {
|
|
25
|
+
return MyDates.formatTimeBasic(dateformat.default, now, args);
|
|
26
|
+
}
|
|
27
|
+
static getServerTime() {
|
|
28
|
+
return new Date().getTime() - this.timeDifference;
|
|
29
|
+
}
|
|
30
|
+
static autoConfigure(lan = null) {
|
|
31
|
+
if (!lan) {
|
|
32
|
+
lan = MyDates.getSelectedLanguage();
|
|
33
|
+
}
|
|
34
|
+
MyDates.configureLocale(dateformat.i18n, dateformat.masks, lan);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
MyDatesFront.autoConfigure();
|
|
38
|
+
|
|
39
|
+
module.exports = {
|
|
40
|
+
MyDatesFront
|
|
41
|
+
};
|
package/src/MyJsPdf.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const { jsPDF } = require("jspdf"); // will automatically load the node version
|
|
2
|
+
const jsdom = require("jsdom");
|
|
3
|
+
const { JSDOM } = jsdom;
|
|
4
|
+
|
|
5
|
+
// "jspdf": "^2.5.1",
|
|
6
|
+
// "jsdom": "^22.0.0",
|
|
7
|
+
// "html2canvas": "^1.4.1",
|
|
8
|
+
// "dompurify": "^3.0.3",
|
|
9
|
+
// "core-js": "^3.30.2",
|
|
10
|
+
// "canvg": "^4.0.1",
|
|
11
|
+
// "btoa": "^1.2.1",
|
|
12
|
+
// "atob": "^2.1.2",
|
|
13
|
+
|
|
14
|
+
class MyJsPdf {
|
|
15
|
+
static async render() {
|
|
16
|
+
|
|
17
|
+
const html = '<html><head><style> html { color: red; } </style></head><body>hola</body></html>';
|
|
18
|
+
const domhtml = new JSDOM(html, { contentType: "text/html" });
|
|
19
|
+
|
|
20
|
+
global.window = domhtml.window;
|
|
21
|
+
global.document = window.document;
|
|
22
|
+
global.navigator = window.navigator;
|
|
23
|
+
window.getComputedStyle = (...args) => {
|
|
24
|
+
return { content: "none" };
|
|
25
|
+
/*
|
|
26
|
+
if ([":before", ":after"].indexOf(args[1]) >= 0) {
|
|
27
|
+
return { content: "none" };
|
|
28
|
+
} else {
|
|
29
|
+
return window.getComputedStyle(...args);
|
|
30
|
+
}
|
|
31
|
+
*/
|
|
32
|
+
};
|
|
33
|
+
window.scrollTo = () => { };
|
|
34
|
+
global.Node = window.Node;
|
|
35
|
+
|
|
36
|
+
var doc = new jsPDF();
|
|
37
|
+
await new Promise((resolve) => {
|
|
38
|
+
doc.html(document.body, {
|
|
39
|
+
callback: function (d) {
|
|
40
|
+
d.save("a4.pdf");
|
|
41
|
+
resolve();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//MyJsPdf.render();
|
|
49
|
+
|
|
50
|
+
module.exports = {
|
|
51
|
+
MyJsPdf,
|
|
52
|
+
};
|
package/src/MyRoutes.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
class MyRoutes {
|
|
3
|
+
// pageType is for example /calendar
|
|
4
|
+
static splitPageData(path) {
|
|
5
|
+
const partes = /(\/[^/]+)(\/[^/\?#]+|\/)?/ig.exec(path);
|
|
6
|
+
if (partes == null) {
|
|
7
|
+
return {
|
|
8
|
+
pageId: null,
|
|
9
|
+
pageType: null,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
let pageId = null;
|
|
13
|
+
if (typeof partes[2] == "string") {
|
|
14
|
+
pageId = (partes[2].replace("/", ""));
|
|
15
|
+
}
|
|
16
|
+
// Must ignore some special paths
|
|
17
|
+
if (["p"].indexOf(pageId) >= 0) {
|
|
18
|
+
pageId = null;
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
pageId,
|
|
22
|
+
pageType: partes[1],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = {
|
|
28
|
+
MyRoutes
|
|
29
|
+
};
|