summaryrefslogtreecommitdiff
path: root/frontend/delta/js/Clipperz/Date.js
Unidiff
Diffstat (limited to 'frontend/delta/js/Clipperz/Date.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/delta/js/Clipperz/Date.js297
1 files changed, 297 insertions, 0 deletions
diff --git a/frontend/delta/js/Clipperz/Date.js b/frontend/delta/js/Clipperz/Date.js
new file mode 100644
index 0000000..163790e
--- a/dev/null
+++ b/frontend/delta/js/Clipperz/Date.js
@@ -0,0 +1,297 @@
1/*
2
3Copyright 2008-2013 Clipperz Srl
4
5This file is part of Clipperz, the online password manager.
6For further information about its features and functionalities please
7refer to http://www.clipperz.com.
8
9* Clipperz is free software: you can redistribute it and/or modify it
10 under the terms of the GNU Affero General Public License as published
11 by the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14* Clipperz is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 See the GNU Affero General Public License for more details.
18
19* You should have received a copy of the GNU Affero General Public
20 License along with Clipperz. If not, see http://www.gnu.org/licenses/.
21
22*/
23
24if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
25if (typeof(Clipperz.Date) == 'undefined') { Clipperz.Date = {}; }
26
27Clipperz.Date.VERSION = "0.1";
28Clipperz.Date.NAME = "Clipperz.Date";
29
30MochiKit.Base.update(Clipperz.Date, {
31
32 //-------------------------------------------------------------------------
33
34 '__repr__': function () {
35 return "[" + this.NAME + " " + this.VERSION + "]";
36 },
37
38 //-------------------------------------------------------------------------
39
40 'toString': function () {
41 return this.__repr__();
42 },
43
44 //-------------------------------------------------------------------------
45
46 'daysInMonth': [31,28,31,30,31,30,31,31,30,31,30,31],
47
48 //-------------------------------------------------------------------------
49
50 'englishOrdinalDaySuffixForDate': function(aDate) {
51 var result;
52
53 switch (aDate.getDate()) {
54 case 1:
55 case 21:
56 case 31:
57 result = "st";
58 break;
59 case 2:
60 case 22:
61 result = "nd";
62 break;
63 case 3:
64 case 23:
65 result = "rd";
66 break;
67 default:
68 result = "th";
69 break;
70 }
71
72 return result;
73 },
74
75 //-------------------------------------------------------------------------
76
77 'isLeapYear': function(aDate) {
78 var year;
79 var result;
80
81 year = aDate.getFullYear();
82 result = ((year & 0x03) == 0 && (year % 100 || (year % 400 == 0 && year)));
83
84 return result;
85 },
86
87 //-------------------------------------------------------------------------
88
89 'getDaysInMonth': function(aDate) {
90 var result;
91
92 if (aDate.getMonth() == 1) {
93 Clipperz.Date.isLeapYear(aDate)
94 result += Clipperz.Date.isLeapYear(aDate) ? 29 : 28;
95 } else {
96 result = Clipperz.Date.daysInMonth[aDate.getMonth()];
97 }
98
99 return result;
100 },
101
102 //-------------------------------------------------------------------------
103
104 'getTimezone': function(aDate) {
105 var result;
106
107 result = aDate.toString();
108 result = result.replace(/([A-Z]{3}) [0-9]{4}/, '$1');
109 result = result.replace(/^.*?\(([A-Z])[a-z]+ ([A-Z])[a-z]+ ([A-Z])[a-z]+\)$/, "$1$2$3");
110
111 return result;
112 },
113
114 'getGMTOffset': function(aDate) {
115 return (aDate.getTimezoneOffset() > 0 ? "-" : "+")+ MochiKit.Format.numberFormatter('00')(Math.floor(this.getTimezoneOffset() / 60))
116 + MochiKit.Format.numberFormatter('00')(this.getTimezoneOffset() % 60);
117 },
118
119 //-------------------------------------------------------------------------
120
121 'dayOfYear': function(aDate) {
122 var result;
123 var i,c;
124
125 result = 0;
126 c = aDate.getMonth();
127 for (i=0; i<c; i++) {
128 if (i == 1) {
129 result += Clipperz.Date.isLeapYear(aDate) ? 29 : 28;
130 } else {
131 result += Clipperz.Date.daysInMonth[i];
132 }
133 }
134 return num + this.getDate() - 1;
135 },
136
137 //-------------------------------------------------------------------------
138
139 'getPHPLikeFormatCode': function(aCharacter) {
140 var result;
141
142 switch (aCharacter) {
143 case "d":
144 result = " + MochiKit.Format.numberFormatter('00')(aDate.getDate())";
145 break;
146 case "D":
147 result = " + aLocale['shortDays'][aDate.getDay()]";
148 break;
149 case "j":
150 result = " + aDate.getDate()";
151 break;
152 case "l":
153 result = " + aLocale['days'][aDate.getDay()]";
154 break;
155 case "S":
156 result = " + Clipperz.Date.englishOrdinalDaySuffixForDate(aDate)";
157 break;
158 case "w":
159 result = " + aDate.getDay()";
160 break;
161 case "z":
162 result = " + aDate.getDayOfYear()";
163 break;
164 case "W":
165 result = " + aDate.getWeekOfYear()";
166 break;
167 case "F":
168 result = " + aLocale['months'][aDate.getMonth()]";
169 break;
170 case "m":
171 result = " + MochiKit.Format.numberFormatter('00')(aDate.getMonth() + 1)";
172 break;
173 case "M":
174 result = " + aLocale['shortMonths'][aDate.getMonth()]";
175 break;
176 case "n":
177 result = " + (aDate.getMonth() + 1)";
178 break;
179 case "t":
180 result = " + Clipperz.Date.getDaysInMonth(aDate)";
181 break;
182 case "L":
183 result = " + (Clipperz.Date.isLeapYear(aDate) ? 1 : 0)";
184 break;
185 case "Y":
186 result = " + aDate.getFullYear()";
187 break;
188 case "y":
189 result = " + ('' + aDate.getFullYear()).substring(2, 4)";
190 break;
191 case "a":
192 result = " + (aDate.getHours() < 12 ? aLocale['amDesignation'] : aLocale['pmDesignation'])";
193 break;
194 case "A":
195 result = " + (aDate.getHours() < 12 ? aLocale['amDesignation'].toUpperCase() : aLocale['pmDesignation'].toUpperCase())";
196 break;
197 case "g":
198 result = " + ((aDate.getHours() %12) ? aDate.getHours() % 12 : 12)";
199 break;
200 case "G":
201 result = " + aDate.getHours()";
202 break;
203 case "h":
204 result = " + MochiKit.Format.numberFormatter('00')((aDate.getHours() %12) ? aDate.getHours() % 12 : 12)";
205 break;
206 case "H":
207 result = " + MochiKit.Format.numberFormatter('00')(aDate.getHours())";
208 break;
209 case "i":
210 result = " + MochiKit.Format.numberFormatter('00')(aDate.getMinutes())";
211 break;
212 case "s":
213 result = " + MochiKit.Format.numberFormatter('00')(aDate.getSeconds())";
214 break;
215 case "O":
216 result = " + aDate.getGMTOffset()";
217 break;
218 case "T":
219 result = " + Clipperz.Date.getTimezone(aDate)";
220 break;
221 case "Z":
222 result = " + ( + aDate.getTimezoneOffset() * -60)";
223 break;
224 default:
225 result = " + '" + aCharacter + "'";
226 break;
227 };
228
229 return result;
230 },
231
232 //=========================================================================
233
234 'formatDateWithPHPLikeTemplateAndLocale': function(aDate, aFormat, aLocale) {
235 var result;
236 var formatterCode;
237 var formatter;
238 var i,c;
239
240 formatterCode = "Clipperz.Date.__scratchFormatter = function(aDate, aLocale){return ''";
241
242 c = aFormat.length;
243 i = 0;
244
245 while (i<c) {
246 var character;
247
248 character = aFormat.charAt(i);
249 if (character == "\\") {
250 i++;
251 character = aFormat.charAt(i);
252 formatterCode += " + '" + character + "'"
253 } else {
254 formatterCode += Clipperz.Date.getPHPLikeFormatCode(character);
255 }
256
257 i++;
258 }
259
260 formatterCode += ";}";
261 eval(formatterCode);
262
263 result = Clipperz.Date.__scratchFormatter.call(this, aDate, aLocale);
264 delete Clipperz.Date.__scratchFormatter;
265
266 return result;
267 },
268
269 //-------------------------------------------------------------------------
270
271 'parseDateWithPHPLikeTemplateAndLocale': function(aString, aFormat, aLocale) {
272 return new Date();
273 },
274
275 //=========================================================================
276
277 'formatDateWithUTCFormatAndLocale': function(aDate, aLocale) {
278 // return Clipperz.Date.formatWithJavaLikeTemplateAndLocale(aDate, "EEE, dd MMMM yyyy HH:mm:ss zzz", aLocale);
279 return aDate.toString();
280 },
281
282 'parseDateWithUTCFormatAndLocale': function(aValue, aLocale) {
283 return new Date(Date.parse(aValue));
284 },
285
286 //=========================================================================
287
288 'exception': {
289 // 'AbstractMethod': new MochiKit.Base.NamedError("Clipperz.Base.exception.AbstractMethod"),
290 // 'UnknownType': new MochiKit.Base.NamedError("Clipperz.Base.exception.UnknownType")
291 },
292
293 //-------------------------------------------------------------------------
294 __syntaxFix__: "syntax fix"
295
296});
297