summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/MochiKit/DateTime.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/MochiKit/DateTime.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/MochiKit/DateTime.js173
1 files changed, 173 insertions, 0 deletions
diff --git a/frontend/gamma/js/MochiKit/DateTime.js b/frontend/gamma/js/MochiKit/DateTime.js
new file mode 100644
index 0000000..c7b2d25
--- a/dev/null
+++ b/frontend/gamma/js/MochiKit/DateTime.js
@@ -0,0 +1,173 @@
1/***
2
3MochiKit.DateTime 1.5
4
5See <http://mochikit.com/> for documentation, downloads, license, etc.
6
7(c) 2005 Bob Ippolito. All rights Reserved.
8
9***/
10
11MochiKit.Base._module('DateTime', '1.5', ['Base']);
12
13/** @id MochiKit.DateTime.isoDate */
14MochiKit.DateTime.isoDate = function (str) {
15 str = str + "";
16 if (typeof(str) != "string" || str.length === 0) {
17 return null;
18 }
19 var iso = str.split('-');
20 if (iso.length === 0) {
21 return null;
22 }
23 var date = new Date(iso[0], iso[1] - 1, iso[2]);
24 date.setFullYear(iso[0]);
25 date.setMonth(iso[1] - 1);
26 date.setDate(iso[2]);
27 return date;
28};
29
30MochiKit.DateTime._isoRegexp = /(\d{4,})(?:-(\d{1,2})(?:-(\d{1,2})(?:[T ](\d{1,2}):(\d{1,2})(?::(\d{1,2})(?:\.(\d+))?)?(?:(Z)|([+-])(\d{1,2})(?::(\d{1,2}))?)?)?)?)?/;
31
32/** @id MochiKit.DateTime.isoTimestamp */
33MochiKit.DateTime.isoTimestamp = function (str) {
34 str = str + "";
35 if (typeof(str) != "string" || str.length === 0) {
36 return null;
37 }
38 var res = str.match(MochiKit.DateTime._isoRegexp);
39 if (typeof(res) == "undefined" || res === null) {
40 return null;
41 }
42 var year, month, day, hour, min, sec, msec;
43 year = parseInt(res[1], 10);
44 if (typeof(res[2]) == "undefined" || res[2] === '') {
45 return new Date(year);
46 }
47 month = parseInt(res[2], 10) - 1;
48 day = parseInt(res[3], 10);
49 if (typeof(res[4]) == "undefined" || res[4] === '') {
50 return new Date(year, month, day);
51 }
52 hour = parseInt(res[4], 10);
53 min = parseInt(res[5], 10);
54 sec = (typeof(res[6]) != "undefined" && res[6] !== '') ? parseInt(res[6], 10) : 0;
55 if (typeof(res[7]) != "undefined" && res[7] !== '') {
56 msec = Math.round(1000.0 * parseFloat("0." + res[7]));
57 } else {
58 msec = 0;
59 }
60 if ((typeof(res[8]) == "undefined" || res[8] === '') && (typeof(res[9]) == "undefined" || res[9] === '')) {
61 return new Date(year, month, day, hour, min, sec, msec);
62 }
63 var ofs;
64 if (typeof(res[9]) != "undefined" && res[9] !== '') {
65 ofs = parseInt(res[10], 10) * 3600000;
66 if (typeof(res[11]) != "undefined" && res[11] !== '') {
67 ofs += parseInt(res[11], 10) * 60000;
68 }
69 if (res[9] == "-") {
70 ofs = -ofs;
71 }
72 } else {
73 ofs = 0;
74 }
75 return new Date(Date.UTC(year, month, day, hour, min, sec, msec) - ofs);
76};
77
78/** @id MochiKit.DateTime.toISOTime */
79MochiKit.DateTime.toISOTime = function (date, realISO/* = false */) {
80 if (typeof(date) == "undefined" || date === null) {
81 return null;
82 }
83 var hh = date.getHours();
84 var mm = date.getMinutes();
85 var ss = date.getSeconds();
86 var lst = [
87 ((realISO && (hh < 10)) ? "0" + hh : hh),
88 ((mm < 10) ? "0" + mm : mm),
89 ((ss < 10) ? "0" + ss : ss)
90 ];
91 return lst.join(":");
92};
93
94/** @id MochiKit.DateTime.toISOTimeStamp */
95MochiKit.DateTime.toISOTimestamp = function (date, realISO/* = false*/) {
96 if (typeof(date) == "undefined" || date === null) {
97 return null;
98 }
99 var sep = realISO ? "T" : " ";
100 var foot = realISO ? "Z" : "";
101 if (realISO) {
102 date = new Date(date.getTime() + (date.getTimezoneOffset() * 60000));
103 }
104 return MochiKit.DateTime.toISODate(date) + sep + MochiKit.DateTime.toISOTime(date, realISO) + foot;
105};
106
107/** @id MochiKit.DateTime.toISODate */
108MochiKit.DateTime.toISODate = function (date) {
109 if (typeof(date) == "undefined" || date === null) {
110 return null;
111 }
112 var _padTwo = MochiKit.DateTime._padTwo;
113 var _padFour = MochiKit.DateTime._padFour;
114 return [
115 _padFour(date.getFullYear()),
116 _padTwo(date.getMonth() + 1),
117 _padTwo(date.getDate())
118 ].join("-");
119};
120
121/** @id MochiKit.DateTime.americanDate */
122MochiKit.DateTime.americanDate = function (d) {
123 d = d + "";
124 if (typeof(d) != "string" || d.length === 0) {
125 return null;
126 }
127 var a = d.split('/');
128 return new Date(a[2], a[0] - 1, a[1]);
129};
130
131MochiKit.DateTime._padTwo = function (n) {
132 return (n > 9) ? n : "0" + n;
133};
134
135MochiKit.DateTime._padFour = function(n) {
136 switch(n.toString().length) {
137 case 1: return "000" + n; break;
138 case 2: return "00" + n; break;
139 case 3: return "0" + n; break;
140 case 4:
141 default:
142 return n;
143 }
144};
145
146/** @id MochiKit.DateTime.toPaddedAmericanDate */
147MochiKit.DateTime.toPaddedAmericanDate = function (d) {
148 if (typeof(d) == "undefined" || d === null) {
149 return null;
150 }
151 var _padTwo = MochiKit.DateTime._padTwo;
152 return [
153 _padTwo(d.getMonth() + 1),
154 _padTwo(d.getDate()),
155 d.getFullYear()
156 ].join('/');
157};
158
159/** @id MochiKit.DateTime.toAmericanDate */
160MochiKit.DateTime.toAmericanDate = function (d) {
161 if (typeof(d) == "undefined" || d === null) {
162 return null;
163 }
164 return [d.getMonth() + 1, d.getDate(), d.getFullYear()].join('/');
165};
166
167MochiKit.DateTime.__new__ = function () {
168 MochiKit.Base.nameFunctions(this);
169};
170
171MochiKit.DateTime.__new__();
172
173MochiKit.Base._exportSymbols(this, MochiKit.DateTime);