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
@@ -5,28 +5,28 @@ MochiKit.DateTime 1.5
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 */
@@ -77,43 +77,46 @@ MochiKit.DateTime.isoTimestamp = function (str) {
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};
@@ -130,20 +133,20 @@ MochiKit.DateTime.americanDate = function (d) {
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;