Subversion Repositories HomeAutomation

Rev

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

Rev 1679 Rev 1759
Line 1... Line 1...
1
 
1
 
-
 
2
/*
-
 
3
String.pad(length: Integer, [substring: String = " "], [type: Integer = 0]): String
-
 
4
      Returns the string with a substring padded on the left, right or both sides.
-
 
5
    length
-
 
6
        amount of characters that the string must have
-
 
7
    substring
-
 
8
        string that will be concatenated
-
 
9
    type
-
 
10
        specifies the side where the concatenation will happen, where: 0 = left, 1 = right and 2 = both sides
-
 
11
*/
-
 
12
String.prototype.pad = function(l, s, t)
-
 
13
{
-
 
14
  return  s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length)
-
 
15
    + 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2))
-
 
16
    + this + s.substr(0, l - t) : this;
-
 
17
}
2
 
18
 
-
 
19
String.prototype.ltrim = function(charlist)
-
 
20
{
-
 
21
  charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
-
 
22
  var re = new RegExp('^[' + charlist + ']+', 'g');
-
 
23
  return this.replace(re, '');
-
 
24
}
-
 
25
 
-
 
26
String.prototype.rtrim = function(charlist)
-
 
27
{
-
 
28
  charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
-
 
29
  var re = new RegExp('[' + charlist + ']+$', 'g');
-
 
30
  return this.replace(re, '');
-
 
31
}
-
 
32
 
-
 
33
String.prototype.trim = function(charlist)
-
 
34
{
-
 
35
  var str = this.ltrim(charlist);
-
 
36
  return str.rtrim(charlist);
-
 
37
}
-
 
38
 
-
 
39
String.prototype.html_entity_decode = function()
-
 
40
{
-
 
41
  var str = this.replace(/Å/g, "Ä");
-
 
42
  str = str.replace(/Ä/g, "Ä");
-
 
43
 
-
 
44
  str = str.replace(/Ä/g, "Å");
-
 
45
  str = str.replace(/Å/g, "Å");
-
 
46
 
-
 
47
  str = str.replace(/Ö/g, "Ö");
-
 
48
  str = str.replace(/Ö/g, "Ö");
-
 
49
 
-
 
50
  str = str.replace(/ä/g, "ä");
-
 
51
  str = str.replace(/ä/g, "ä");
-
 
52
 
-
 
53
  str = str.replace(/å/g, "å");
-
 
54
  str = str.replace(/å/g, "å");
-
 
55
 
-
 
56
  str = str.replace(/ö/g, "ö");
-
 
57
  str = str.replace(/ö/g, "ö");
-
 
58
 
-
 
59
  //FIXME: Add more characters
-
 
60
 
-
 
61
  return str;
-
 
62
}
-
 
63
 
-
 
64
Date.prototype.getTimestamp = function()
-
 
65
{
-
 
66
  return this.getTime()/1000;
-
 
67
}
-
 
68
 
-
 
69
Date.prototype.getDateFormated = function()
-
 
70
{
-
 
71
  return this.getFullYear() + "-" + (this.getMonth()+1).toString().pad(2, "0", 0) + "-" + this.getDate().toString().pad(2, "0", 0);
-
 
72
}
-
 
73
 
-
 
74
Date.prototype.getTimeFormated = function()
-
 
75
{
-
 
76
  return this.getHours().toString().pad(2, "0", 0) + ":" + this.getMinutes().toString().pad(2, "0", 0) + ":" + this.getSeconds().toString().pad(2, "0", 0);
-
 
77
}
-
 
78
 
-
 
79
Date.prototype.getTimeShortFormated = function()
-
 
80
{
-
 
81
  return this.getHours().toString().pad(2, "0", 0) + ":" + this.getMinutes().toString().pad(2, "0", 0);
-
 
82
}
-
 
83
 
-
 
84
Date.prototype.getDateTimeFormated = function()
-
 
85
{
-
 
86
  return this.getDateFormated() + " " + this.getTimeFormated();
-
 
87
}
3
 
88
 
4
function get_time()
89
function get_time()
5
{
90
{
6
    return Math.round(new Date().getTime() / 1000);
91
    return Math.round(new Date().getTime() / 1000);
7
}
92
}