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