Subversion Repositories HomeAutomation

Rev

Blame | Last modification | View Log | SVN | RSS feed

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