-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiempo.js
74 lines (60 loc) · 1.87 KB
/
tiempo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const msg_ini = "Log Start : "
const msg_fin = "Log Stop : "
let fecha
// .......................
// tamaño en bytes
// .......................
exports.estimarTiempo = (x) => {
// y = mx + b con b=fecha.ini.fecha
let tiempo = new Date(fecha.m * x + fecha.ini.fecha.getTime())
return tiempo.toLocaleString()
}
// .......................
// fechas inicio-fin log
// .......................
/**
* @param {string} entrada
* cadena de caracteres que representa el contedio del archivo
* @return {object} inicio: { posicion, fecha }, fin: { posicion, fecha }, rel_segpos
*/
exports.fechasLog = (entrada) => {
fecha = {}
const ind_ini = entrada.indexOf(msg_ini)
const ind_fin = entrada.lastIndexOf(msg_fin)
const fecha_ini_tmp = entrada
.substr(ind_ini + msg_ini.length, 17)
.trim()
.replace(/\s\s/, ".")
.split(".")
const fecha_fin_tmp = entrada
.substr(ind_fin + msg_fin.length, 17)
.trim()
.replace(/\s\s/, ".")
.split(".")
let fecha_ini = new Date(
fecha_ini_tmp[0], // anio
fecha_ini_tmp[1]-1, // mes
fecha_ini_tmp[2], // dia
fecha_ini_tmp[3], // hora
fecha_ini_tmp[4],0,0) // minuto, segundo, miliseg
let fecha_fin = new Date(
fecha_fin_tmp[0], // anio
fecha_fin_tmp[1]-1, // mes
fecha_fin_tmp[2], // dia
fecha_fin_tmp[3], // hora
fecha_fin_tmp[4],0,0) // minuto, segundo, miliseg
fecha = {
ini: { pos:ind_ini, fecha:fecha_ini },
fin: { pos:ind_fin, fecha:fecha_fin },
m: (fecha_fin - fecha_ini) / (ind_fin - ind_ini)
}
console.log("t(ini) caputurado: " + fecha_ini);
console.log("t(fin) caputurado: " + fecha_fin);
}
// .......................
//
// .......................
exports.estampaTiempo = (cb) => {
//cb(new Date(tiempo - (180 * 60 * 1000)))
cb(new Date(Date.now()))
}