Created
January 25, 2017 19:07
-
-
Save jesuslerma/a1031488d2da0e1d8173ba51b1757c18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// aqui defino las variables que me pasaste | |
function calcData () { | |
poblationInit = 122823652 // 122´823, 652 | |
newHabitantMx = 25.6 | |
newBirthMx = 14.5 | |
deathMexican = 44.15 | |
dayInit = '01/01/2017' | |
today = new Date() | |
todayMom = moment(today) // aqui uso la variable today para traer la hora/fecha actual | |
yesterdayMom = moment(today).subtract(1, 'days') // obtengo la fecha de ayer | |
initMom = moment(dayInit,"DD/MM/YYYY") // aqui obtengo la fecha inicial que es el primero de enero del 2017 | |
secondsDiff = todayMom.diff(initMom, 'seconds') // obtengo la diferencia de la fecha actual al dia de hoy en segundos | |
secondsDiffToday = todayMom.diff(yesterdayMom, 'seconds') // obtengo la diferenua de la fecha actual al dia de hoy en segundos | |
// aqui hago los calculos que muestro en la tabla | |
yearBirths = secondsDiff / newBirthMx | |
yearDeaths = secondsDiff / deathMexican | |
todayBirths = secondsDiffToday / newBirthMx | |
todayDeaths = secondsDiffToday / deathMexican | |
// para mostrar los resultados | |
console.log(yearBirths) | |
console.log(yearDeaths) | |
console.log(todayBirths) | |
console.log(todayDeaths) | |
} | |
// Estos calculos se realizan cada segundo | |
calcData() | |
setInterval(() => calcData(), 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment