Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function duration(time) {
- var buffer = '';
- var chunks = new Array();
- var hours = Math.floor((time / 3600));
- time %= 3600;
- var minutes = Math.floor((time / 60));
- time %= 60;
- if(hours > 0) { chunks.push(hours + ' hour' + ((hours == 1)?'':'s'));}
- if(minutes > 0) { chunks.push(minutes + ' minute' + ((minutes == 1)?' ':'s'));}
- if(time > 0) { chunks.push(time + ' second' + ((time == 1)?'':'s'));}
- var len = chunks.length;
- for(var i = 0; i < len; i++) {
- switch(true) {
- case i == len-1:
- buffer += chunks[i];
- break;
- case i == len-2:
- buffer += chunks[i] + ' and ';
- break;
- default:
- buffer += chunks[i] + ', ';
- break;
- }
- }
- return buffer;
- }
Advertisement
Add Comment
Please, Sign In to add comment