]> err.no Git - scalable-opengroupware.org/blob - UI/WebServerResources/JavascriptAPIExtensions.js
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1009 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / WebServerResources / JavascriptAPIExtensions.js
1 String.prototype.trim = function() {
2   return this.replace(/(^\s+|\s+$)/g, '');
3 }
4
5 String.prototype.capitalize = function() {
6   return this.replace(/\w+/g,
7                       function(a) {
8                         return ( a.charAt(0).toUpperCase()
9                                  + a.substr(1).toLowerCase() );
10                       });
11 }
12
13 String.prototype.decodeEntities = function() {
14   return this.replace(/&#(\d+);/g,
15                       function(wholematch, parenmatch1) {
16                         return String.fromCharCode(+parenmatch1);
17                       });
18 }
19
20 String.prototype.asDate = function () {
21   var newDate;
22   var date = this.split("/");
23   if (date.length == 3)
24     newDate = new Date(date[2], date[1] - 1, date[0]);
25   else {
26     date = this.split("-");
27     newDate = new Date(date[0], date[1] - 1, date[2]);
28   }
29
30   return newDate;  
31 }
32
33 Date.prototype.sogoDayName = function() {
34   var dayName = "";
35
36   var day = this.getDay();
37   if (day == 0) {
38     dayName = labels['a2_Sunday'];
39   } else if (day == 1) {
40     dayName = labels['a2_Monday'];
41   } else if (day == 2) {
42     dayName = labels['a2_Tuesday'];
43   } else if (day == 3) {
44     dayName = labels['a2_Wednesday'];
45   } else if (day == 4) {
46     dayName = labels['a2_Thursday'];
47   } else if (day == 5) {
48     dayName = labels['a2_Friday'];
49   } else if (day == 6) {
50     dayName = labels['a2_Saturday'];
51   }
52
53   return dayName;
54 }
55
56 Date.prototype.daysUpTo = function(otherDate) {
57   var days = new Array();
58   var day1 = this.getTime();
59   var day2 = otherDate.getTime();
60
61   var nbrDays = Math.floor((day2 - day1) / 86400000) + 1;
62   for (var i = 0; i < nbrDays; i++) {
63     var newDate = new Date();
64     newDate.setTime(day1 + (i * 86400000));
65     days.push(newDate);
66   }
67
68   return days;
69 }
70
71 Date.prototype.stringWithSeparator = function(separator) {
72   var month = '' + (this.getMonth() + 1);
73   var day = '' + this.getDate();
74   if (month.length == 1)
75     month = '0' + month;
76   if (day.length == 1)
77     day = '0' + day;
78
79   if (separator == '-')
80     str = (this.getYear() + 1900) + '-' + month + '-' + day;
81   else
82     str = day + '/' + month + '/' + (this.getYear() + 1900);
83
84   return str;
85 }
86
87 Date.prototype.sogoFreeBusyStringWithSeparator = function(separator) {
88   return this.sogoDayName() + ", " + this.stringWithSeparator(separator);
89 }