-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16.js
25 lines (13 loc) · 755 Bytes
/
16.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
function CalcularAnios (fecha = undefined) {
if (fecha === undefined) return console.warn("No ingresaste la fecha");
if (!(fecha instanceof Date)) return console.error(`El valor ingresado no es valido`);
let hoyMenosFecha = new Date().getTime() - fecha.getTime()
aniosEnMS = 1000 * 60 * 60 * 24 * 365,
aniosEnMS = Math.floor(hoyMenosFecha / aniosEnMS);
return (Math.sign(aniosEnMS) === -1)
? console.info(`Faltan ${Math.abs(aniosEnMS)} años para el ${fecha.getFullYear()}.`)
: (Math.sign(aniosEnMS) === 1)
? console.info(`Han pasado ${aniosEnMS} años, desde ${fecha.getFullYear()}.`)
: console.info(`Estamos en el año actual ${fecha.getFullYear()}.`)
}
console.log(CalcularAnios(new Date(1984,4,23)))