Merge pull request #62 from nmaier/eta

Format times like hh:mm:ss
This commit is contained in:
hamza zia 2013-08-02 17:01:32 -07:00
commit 2e04def70d

View File

@ -20,14 +20,21 @@ angular
}; };
}]) }])
.filter('time', function() { .filter('time', function() {
function pad(f) {
return ("0" + f).substr(-2);
}
return function(time) { return function(time) {
time = parseFloat(time); time = parseInt(time, 10);
if (isNaN(time) || !isFinite(time)) return " infinite"; if (!time || !isFinite(time)) return "∞";
if (!time) return " infinite"; var secs = time % 60;
if (time < 60) return time.toFixed(2) + " s"; if (time < 60) return secs + "s";
else if (time < 60*60) return (time/60).toFixed(2) + " min"; var mins = Math.floor((time % 3600) / 60)
else if (time < 60*60*24) return (time/(60*60)).toFixed(2) + " hours"; if (time < 3600) return pad(mins) + ":" + pad(secs);
else return (time/(60*60*24)).toFixed(2) + " days!"; var hrs = Math.floor((time % 86400) / 3600);
if (time < 86400) return pad(hrs) + ":" + pad(mins) + ":" + pad(secs);
var days = Math.floor(time / 86400);
return days + "::" + pad(hrs) + ":" + pad(mins) + ":" + pad(secs);
}; };
}); });