Initial Import
[profile/ivi/hfdialer.git] / qml / javascripts / framework.js
1 /*
2  * Generic Javascript Utility Functions
3  *
4  * Copyright (c) 2011, Tom Swindell.
5  *
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
9  *
10  */
11
12 Date.prototype.getFormat = function()
13 {
14     return (this.getDate() < 10 ? '0' : '') + this.getDate() + '/' +
15            (this.getMonth() < 10 ? '0' : '') + this.getMonth() + '/' +
16            this.getFullYear() +
17            ' | ' +
18            (this.getHours() < 10 ? '0' : '') + this.getHours() + ':' +
19            (this.getMinutes() < 10 ? '0' : '') + this.getMinutes() + ':' +
20            (this.getSeconds() < 10 ? '0' : '') + this.getSeconds();
21 }
22
23 function friendlyInterval(duration)
24 {
25     duration = Number(duration);
26     if(isNaN(duration)) duration = 0;
27
28     var hours    = Math.floor(duration / 3600);
29     var minutes  = Math.floor((duration % 3600) / 60);
30     var seconds  = duration % 60;
31
32     return (hours < 10 ? '0' : '') + hours + ':' + (minutes < 10 ? '0' : '') + minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
33 }
34
35 function friendlyDuration(start, end)
36 {
37     var duration = Math.floor(((new Date(end)) - (new Date(start))) / 1000);
38     return friendlyInterval(duration);
39 }
40