This repository was archived by the owner on Sep 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting2.js
54 lines (49 loc) · 1.44 KB
/
testing2.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
fs = require('fs');
const moment = require('./obtener_tiempo.js');
aux = moment((Date.now()+2591807000))
let date = new Date()
let day = date.getDate()
let month = date.getMonth() + 1
let mothmeta = date.getMonth() + 2
let year = date.getFullYear()
if(month < 10){
console.log(`${day}-0${month}-${year}`)
}else{
console.log(`${day}-${month}-${year}`)
}
fechainicio = new Date(`${year}-0${month}-${day}`).getTime();
fechafin = new Date(`${year}-0${mothmeta}-${day}`).getTime();
var diff = (fechafin - fechainicio);
console.log(Math.floor(diff/(1000 * 60 * 60 *24)),'==========')
aux3 = 'carlos';
aux2= {
"name": aux3,
"hora": fechafin
}
aux2 = JSON.stringify(aux2)
console.log('Testt')
fs.appendFile('./permitir_accesodias', aux2, function (err) { console.log('Casi');
if (err) {
// append failed
} else {
console.log(aux2)
aux2=JSON.parse(aux2)
console.log(aux2.hora, '.-.-.-.-.-..-.-')
}
})
var lineReader = require('readline').createInterface({
input: require('fs').createReadStream('permitir_accesodias')
});
acceso = true;
lineReader.on('line', async function (line) {
if(JSON.parse(line).name === 'carlos'){
var hoy = new Date(); var fecha1 = moment(hoy);
a=0
fechafin = JSON.parse(line).hora
if(fechafin >= fechainicio){
console.log('Autorizado')
}
console.log(diff)
console.log(a, 'Dias que lleva')
}
});