Created
December 22, 2014 16:48
-
-
Save Kolesias123/77be7b1bddb423d962b6 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
function calculate(time, num) | |
{ | |
var inte = ["segundo", "minuto", "hora", "día", "semana", "mes", "año"]; | |
var dur = [60, 60, 24, 7, 4.35, 12]; | |
time = parseInt(time); | |
var now = parseInt( Math.round((new Date()).getTime() / 1000) ); | |
var j = 0; | |
var dif = 0; | |
var str = ""; | |
var sh = time + 10; | |
//if(now == time || now < sh) | |
// return "Justo ahora"; | |
if(now > time) | |
{ | |
dif = now - time; | |
str = "Hace"; | |
} | |
else | |
{ | |
dif = time - now; | |
str = "Dentro de"; | |
} | |
for(j = 0; dif >= dur[j] && j < dur.length - 1; j++) | |
dif /= dur[j]; | |
dif = Math.round(dif); | |
if(dif != 1) | |
{ | |
inte[5] += "e"; | |
inte[j] += "s"; | |
} | |
if(num == true) | |
return dif + ' ' + inte[j]; | |
else | |
return str + " " + dif + " " + inte[j]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment