2 * Generic Javascript Utility Functions
4 * Copyright (c) 2011, Tom Swindell.
6 * This program is licensed under the terms and conditions of the
7 * Apache License, version 2.0. The full text of the Apache License is at
8 * http://www.apache.org/licenses/LICENSE-2.0
12 Date.prototype.getFormat = function()
14 return (this.getDate() < 10 ? '0' : '') + this.getDate() + '/' +
15 (this.getMonth() < 10 ? '0' : '') + this.getMonth() + '/' +
18 (this.getHours() < 10 ? '0' : '') + this.getHours() + ':' +
19 (this.getMinutes() < 10 ? '0' : '') + this.getMinutes() + ':' +
20 (this.getSeconds() < 10 ? '0' : '') + this.getSeconds();
23 function friendlyInterval(duration)
25 duration = Number(duration);
26 if(isNaN(duration)) duration = 0;
28 var hours = Math.floor(duration / 3600);
29 var minutes = Math.floor((duration % 3600) / 60);
30 var seconds = duration % 60;
32 return (hours < 10 ? '0' : '') + hours + ':' + (minutes < 10 ? '0' : '') + minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
35 function friendlyDuration(start, end)
37 var duration = Math.floor(((new Date(end)) - (new Date(start))) / 1000);
38 return friendlyInterval(duration);