Subversion Repositories HomeAutomation

Rev

Rev 969 | Rev 984 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 969 Rev 971
Line -... Line 1...
-
 
1
 
-
 
2
 
-
 
3
function extend(descendant, parent)
-
 
4
{
-
 
5
    var sConstructor = parent.toString();
-
 
6
    var aMatch = sConstructor.match(/\s*function (.*)\(/);
-
 
7
   
-
 
8
    if (aMatch != null)
-
 
9
    {
-
 
10
        descendant.prototype[aMatch[1]] = parent;
-
 
11
    }
-
 
12
   
-
 
13
    for (var m in parent.prototype)
-
 
14
    {
-
 
15
        descendant.prototype[m] = parent.prototype[m];
-
 
16
    }
-
 
17
}
-
 
18
 
1
/*
19
/*
2
String.pad(length: Integer, [substring: String = " "], [type: Integer = 0]): String
20
String.pad(length: Integer, [substring: String = " "], [type: Integer = 0]): String
3
        Returns the string with a substring padded on the left, right or both sides.
21
        Returns the string with a substring padded on the left, right or both sides.
4
    length
22
    length
5
        amount of characters that the string must have
23
        amount of characters that the string must have
Line 11... Line 29...
11
String.prototype.pad = function(l, s, t)
29
String.prototype.pad = function(l, s, t)
12
{
30
{
13
    return s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length)
31
    return  s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length)
14
        + 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2))
32
        + 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2))
15
        + this + s.substr(0, l - t) : this;
33
        + this + s.substr(0, l - t) : this;
16
}
-
 
17
 
-
 
18
function extend(descendant, parent)
-
 
19
{
-
 
20
    var sConstructor = parent.toString();
-
 
21
    var aMatch = sConstructor.match(/\s*function (.*)\(/);
-
 
22
   
-
 
23
    if (aMatch != null)
-
 
24
    {
-
 
25
        descendant.prototype[aMatch[1]] = parent;
-
 
26
    }
-
 
27
   
-
 
28
    for (var m in parent.prototype)
-
 
29
    {
-
 
30
        descendant.prototype[m] = parent.prototype[m];
-
 
31
    }
-
 
32
}
-
 
33
 
-
 
34
function time(d)
-
 
35
{
-
 
36
    if (!d)
-
 
37
        d = new Date();
-
 
38
       
-
 
39
    return d.getTime()/1000;
-
 
40
}
-
 
41
 
-
 
42
function formatDate(d)
-
 
43
{
-
 
44
    if (!d)
-
 
45
        d = new Date();
-
 
46
       
-
 
47
    return d.getFullYear() + "-" + (d.getMonth()+1).toString().pad(2, "0", 0) + "-" + d.getDate().toString().pad(2, "0", 0);
-
 
48
}
-
 
49
 
-
 
50
function formatTime(d)
-
 
51
{
-
 
52
    if (!d)
-
 
53
        d = new Date();
-
 
54
       
-
 
55
    return d.getHours().toString().pad(2, "0", 0) + "." + d.getMinutes().toString().pad(2, "0", 0) + "." + d.getSeconds().toString().pad(2, "0", 0);
-
 
56
}
-
 
57
 
-
 
58
function formatDateTime(d)
-
 
59
{
-
 
60
    if (!d)
-
 
61
        d = new Date();
-
 
62
       
-
 
63
    return formatDate(d) + " " + formatTime(d);
-
 
64
}
34
}
65
 
35
 
66
function ltrim(str, charlist)
36
String.prototype.ltrim = function(charlist)
67
{
37
{
68
    charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
38
    charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
69
    var re = new RegExp('^[' + charlist + ']+', 'g');
39
    var re = new RegExp('^[' + charlist + ']+', 'g');
70
    return str.replace(re, '');
40
    return this.replace(re, '');
71
}
41
}
72
 
42
 
73
function rtrim(str, charlist)
43
String.prototype.rtrim = function(charlist)
74
{
44
{
75
    charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
45
    charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
76
    var re = new RegExp('[' + charlist + ']+$', 'g');
46
    var re = new RegExp('[' + charlist + ']+$', 'g');
77
    return str.replace(re, '');
47
    return this.replace(re, '');
-
 
48
}
-
 
49
 
-
 
50
String.prototype.trim = function(charlist)
-
 
51
{
-
 
52
    var str = this.ltrim(charlist);
-
 
53
    return str.rtrim(charlist);
-
 
54
}
-
 
55
 
-
 
56
 
-
 
57
Date.prototype.getTimestamp = function()
-
 
58
{
-
 
59
    return this.getTime()/1000;
-
 
60
}
-
 
61
 
-
 
62
Date.prototype.getDateFormated = function()
-
 
63
{
-
 
64
    return this.getFullYear() + "-" + (this.getMonth()+1).toString().pad(2, "0", 0) + "-" + this.getDate().toString().pad(2, "0", 0);
-
 
65
}
-
 
66
 
-
 
67
Date.prototype.getTimeFormated = function()
-
 
68
{
-
 
69
    return this.getHours().toString().pad(2, "0", 0) + "." + this.getMinutes().toString().pad(2, "0", 0) + "." + this.getSeconds().toString().pad(2, "0", 0);
78
}
70
}
79
 
71
 
80
function trim(str, charlist)
72
Date.prototype.getDateTimeFormated = function()
81
{
73
{
82
    str = ltrim(str, charlist);
-
 
83
    return rtrim(str, charlist);
74
    return this.getDateFormated() + " " + this.getTimeFormated();
84
}
75
}