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