Diffstat (limited to 'frontend/delta/js/MochiKit/DateTime.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/delta/js/MochiKit/DateTime.js | 199 |
1 files changed, 199 insertions, 0 deletions
diff --git a/frontend/delta/js/MochiKit/DateTime.js b/frontend/delta/js/MochiKit/DateTime.js new file mode 100644 index 0000000..24ca087 --- a/dev/null +++ b/frontend/delta/js/MochiKit/DateTime.js | |||
@@ -0,0 +1,199 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2013 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz, the online password manager. | ||
6 | For further information about its features and functionalities please | ||
7 | refer 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 | |||
24 | /*** | ||
25 | |||
26 | MochiKit.DateTime 1.5 | ||
27 | |||
28 | See <http://mochikit.com/> for documentation, downloads, license, etc. | ||
29 | |||
30 | (c) 2005 Bob Ippolito. All rights Reserved. | ||
31 | |||
32 | ***/ | ||
33 | |||
34 | MochiKit.Base.module(MochiKit, 'DateTime', '1.5', ['Base']); | ||
35 | |||
36 | /** @id MochiKit.DateTime.isoDate */ | ||
37 | MochiKit.DateTime.isoDate = function (str) { | ||
38 | str = str + ""; | ||
39 | if (typeof(str) != "string" || str.length === 0) { | ||
40 | return null; | ||
41 | } | ||
42 | var iso = str.split('-'); | ||
43 | if (iso.length === 0) { | ||
44 | return null; | ||
45 | } | ||
46 | var date = new Date(parseInt(iso[0], 10), parseInt(iso[1], 10) - 1, parseInt(iso[2], 10)); | ||
47 | date.setFullYear(iso[0]); | ||
48 | date.setMonth(iso[1] - 1); | ||
49 | date.setDate(iso[2]); | ||
50 | return date; | ||
51 | }; | ||
52 | |||
53 | MochiKit.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}))?)?)?)?)?/; | ||
54 | |||
55 | /** @id MochiKit.DateTime.isoTimestamp */ | ||
56 | MochiKit.DateTime.isoTimestamp = function (str) { | ||
57 | str = str + ""; | ||
58 | if (typeof(str) != "string" || str.length === 0) { | ||
59 | return null; | ||
60 | } | ||
61 | var res = str.match(MochiKit.DateTime._isoRegexp); | ||
62 | if (typeof(res) == "undefined" || res === null) { | ||
63 | return null; | ||
64 | } | ||
65 | var year, month, day, hour, min, sec, msec; | ||
66 | year = parseInt(res[1], 10); | ||
67 | if (typeof(res[2]) == "undefined" || res[2] === '') { | ||
68 | return new Date(year); | ||
69 | } | ||
70 | month = parseInt(res[2], 10) - 1; | ||
71 | day = parseInt(res[3], 10); | ||
72 | if (typeof(res[4]) == "undefined" || res[4] === '') { | ||
73 | return new Date(year, month, day); | ||
74 | } | ||
75 | hour = parseInt(res[4], 10); | ||
76 | min = parseInt(res[5], 10); | ||
77 | sec = (typeof(res[6]) != "undefined" && res[6] !== '') ? parseInt(res[6], 10) : 0; | ||
78 | if (typeof(res[7]) != "undefined" && res[7] !== '') { | ||
79 | msec = Math.round(1000.0 * parseFloat("0." + res[7])); | ||
80 | } else { | ||
81 | msec = 0; | ||
82 | } | ||
83 | if ((typeof(res[8]) == "undefined" || res[8] === '') && (typeof(res[9]) == "undefined" || res[9] === '')) { | ||
84 | return new Date(year, month, day, hour, min, sec, msec); | ||
85 | } | ||
86 | var ofs; | ||
87 | if (typeof(res[9]) != "undefined" && res[9] !== '') { | ||
88 | ofs = parseInt(res[10], 10) * 3600000; | ||
89 | if (typeof(res[11]) != "undefined" && res[11] !== '') { | ||
90 | ofs += parseInt(res[11], 10) * 60000; | ||
91 | } | ||
92 | if (res[9] == "-") { | ||
93 | ofs = -ofs; | ||
94 | } | ||
95 | } else { | ||
96 | ofs = 0; | ||
97 | } | ||
98 | return new Date(Date.UTC(year, month, day, hour, min, sec, msec) - ofs); | ||
99 | }; | ||
100 | |||
101 | /** @id MochiKit.DateTime.toISOTime */ | ||
102 | MochiKit.DateTime.toISOTime = function (date, realISO/* = false */) { | ||
103 | if (typeof(date) == "undefined" || date === null) { | ||
104 | return null; | ||
105 | } | ||
106 | var _padTwo = MochiKit.DateTime._padTwo; | ||
107 | if (realISO) { | ||
108 | // adjust date for UTC timezone | ||
109 | date = new Date(date.getTime() + (date.getTimezoneOffset() * 60000)); | ||
110 | } | ||
111 | var lst = [ | ||
112 | (realISO ? _padTwo(date.getHours()) : date.getHours()), | ||
113 | _padTwo(date.getMinutes()), | ||
114 | _padTwo(date.getSeconds()) | ||
115 | ]; | ||
116 | return lst.join(":") + (realISO ? "Z" : ""); | ||
117 | }; | ||
118 | |||
119 | /** @id MochiKit.DateTime.toISOTimeStamp */ | ||
120 | MochiKit.DateTime.toISOTimestamp = function (date, realISO/* = false*/) { | ||
121 | if (typeof(date) == "undefined" || date === null) { | ||
122 | return null; | ||
123 | } | ||
124 | var time = MochiKit.DateTime.toISOTime(date, realISO); | ||
125 | var sep = realISO ? "T" : " "; | ||
126 | if (realISO) { | ||
127 | // adjust date for UTC timezone | ||
128 | date = new Date(date.getTime() + (date.getTimezoneOffset() * 60000)); | ||
129 | } | ||
130 | return MochiKit.DateTime.toISODate(date) + sep + time; | ||
131 | }; | ||
132 | |||
133 | /** @id MochiKit.DateTime.toISODate */ | ||
134 | MochiKit.DateTime.toISODate = function (date) { | ||
135 | if (typeof(date) == "undefined" || date === null) { | ||
136 | return null; | ||
137 | } | ||
138 | var _padTwo = MochiKit.DateTime._padTwo; | ||
139 | var _padFour = MochiKit.DateTime._padFour; | ||
140 | return [ | ||
141 | _padFour(date.getFullYear()), | ||
142 | _padTwo(date.getMonth() + 1), | ||
143 | _padTwo(date.getDate()) | ||
144 | ].join("-"); | ||
145 | }; | ||
146 | |||
147 | /** @id MochiKit.DateTime.americanDate */ | ||
148 | MochiKit.DateTime.americanDate = function (d) { | ||
149 | d = d + ""; | ||
150 | if (typeof(d) != "string" || d.length === 0) { | ||
151 | return null; | ||
152 | } | ||
153 | var a = d.split('/'); | ||
154 | return new Date(a[2], a[0] - 1, a[1]); | ||
155 | }; | ||
156 | |||
157 | MochiKit.DateTime._padTwo = function (n) { | ||
158 | return (n > 9) ? n : "0" + n; | ||
159 | }; | ||
160 | |||
161 | MochiKit.DateTime._padFour = function(n) { | ||
162 | switch(n.toString().length) { | ||
163 | case 1: return "000" + n; break; | ||
164 | case 2: return "00" + n; break; | ||
165 | case 3: return "0" + n; break; | ||
166 | case 4: | ||
167 | default: | ||
168 | return n; | ||
169 | } | ||
170 | }; | ||
171 | |||
172 | /** @id MochiKit.DateTime.toPaddedAmericanDate */ | ||
173 | MochiKit.DateTime.toPaddedAmericanDate = function (d) { | ||
174 | if (typeof(d) == "undefined" || d === null) { | ||
175 | return null; | ||
176 | } | ||
177 | var _padTwo = MochiKit.DateTime._padTwo; | ||
178 | return [ | ||
179 | _padTwo(d.getMonth() + 1), | ||
180 | _padTwo(d.getDate()), | ||
181 | d.getFullYear() | ||
182 | ].join('/'); | ||
183 | }; | ||
184 | |||
185 | /** @id MochiKit.DateTime.toAmericanDate */ | ||
186 | MochiKit.DateTime.toAmericanDate = function (d) { | ||
187 | if (typeof(d) == "undefined" || d === null) { | ||
188 | return null; | ||
189 | } | ||
190 | return [d.getMonth() + 1, d.getDate(), d.getFullYear()].join('/'); | ||
191 | }; | ||
192 | |||
193 | MochiKit.DateTime.__new__ = function () { | ||
194 | MochiKit.Base.nameFunctions(this); | ||
195 | }; | ||
196 | |||
197 | MochiKit.DateTime.__new__(); | ||
198 | |||
199 | MochiKit.Base._exportSymbols(this, MochiKit.DateTime); | ||