Skip to content

Instantly share code, notes, and snippets.

@Verurteilt
Last active December 17, 2015 02:48
Show Gist options
  • Save Verurteilt/5537944 to your computer and use it in GitHub Desktop.
Save Verurteilt/5537944 to your computer and use it in GitHub Desktop.
function checar_tiempo (startdate, tiempo_de_creacion) {
if(startdate.getSeconds() > tiempo_de_creacion.getSeconds() && startdate.getMinutes() === tiempo_de_creacion.getMinutes() && startdate.getDay() === tiempo_de_creacion.getDay() && startdate.getMonth() === tiempo_de_creacion.getMonth() && startdate.getFullYear() === tiempo_de_creacion.getFullYear() && startdate.getHours() === tiempo_de_creacion.getHours()){
tiempo = "A few ";
quees = "seconds";
}else if(startdate.getMinutes() > tiempo_de_creacion.getMinutes() && startdate.getDay() === tiempo_de_creacion.getDay() && startdate.getMonth() === tiempo_de_creacion.getMonth() && startdate.getFullYear() === tiempo_de_creacion.getFullYear() && startdate.getHours() === tiempo_de_creacion.getHours()){
tiempo = startdate.getMinutes() - tiempo_de_creacion.getMinutes() ;
quees = " minutes";
}else if(startdate.getDay() === tiempo_de_creacion.getDay() && startdate.getMonth() === tiempo_de_creacion.getMonth() && startdate.getFullYear() === tiempo_de_creacion.getFullYear() && startdate.getHours() > tiempo_de_creacion.getHours()){
tiempo = startdate.getHours() - tiempo_de_creacion.getHours();
quees = " hours";
}else if(startdate.getDay() <= tiempo_de_creacion.getDay() ||startdate.getDay() > tiempo_de_creacion.getDay() && startdate.getMonth() === tiempo_de_creacion.getMonth()){
if(startdate.getDay() <= tiempo_de_creacion.getDay()){
tiempo = -(startdate.getDay() - tiempo_de_creacion.getDay());
}else{
tiempo = startdate.getDay() - tiempo_de_creacion.getDay();
}
quees = " day(s)";
}else if(startdate.getMonth() >= tiempo_de_creacion.getMonth() && startdate.getFullYear() === tiempo_de_creacion.getFullYear() ) {
tiempo = startdate.getMonth() - tiempo_de_creacion.getMonth();
quees = " months";
}else{
tiempo = startdate.getFullYear() - tiempo_de_creacion.getFullYear();
quees =" years"
}
return tiempo, quees;
}
var tiempo_de_creacion = new Date(twit.created_at)
var startdate = new Date();
checar_tiempo(startdate,tiempo_de_creacion);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment