Mercurial > urweb
comparison lib/js/urweb.js @ 1986:b2254554542f
Add Datetime JavaScript support.
author | Patrick Hurst <phurst@mit.edu> |
---|---|
date | Mon, 17 Feb 2014 19:21:46 -0500 |
parents | a671e5258a2c |
children | abb6981a2c4c |
comparison
equal
deleted
inserted
replaced
1985:5195378deeca | 1986:b2254554542f |
---|---|
215 g: function (d) { return xPad(parseInt(Dt.formats.G(d)%100, 10), 0); }, | 215 g: function (d) { return xPad(parseInt(Dt.formats.G(d)%100, 10), 0); }, |
216 G: function (d) { | 216 G: function (d) { |
217 var y = d.getFullYear(); | 217 var y = d.getFullYear(); |
218 var V = parseInt(Dt.formats.V(d), 10); | 218 var V = parseInt(Dt.formats.V(d), 10); |
219 var W = parseInt(Dt.formats.W(d), 10); | 219 var W = parseInt(Dt.formats.W(d), 10); |
220 | 220 |
221 if(W > V) { | 221 if(W > V) { |
222 y++; | 222 y++; |
223 } else if(W===0 && V>=52) { | 223 } else if(W===0 && V>=52) { |
224 y--; | 224 y--; |
225 } | 225 } |
226 | 226 |
227 return y; | 227 return y; |
228 }, | 228 }, |
229 H: ["getHours", "0"], | 229 H: ["getHours", "0"], |
230 I: function (d) { var I=d.getHours()%12; return xPad(I===0?12:I, 0); }, | 230 I: function (d) { var I=d.getHours()%12; return xPad(I===0?12:I, 0); }, |
231 j: function (d) { | 231 j: function (d) { |
260 } | 260 } |
261 else if(idow === 0) | 261 else if(idow === 0) |
262 { | 262 { |
263 idow = Dt.formats.V(new Date("" + (d.getFullYear()-1) + "/12/31")); | 263 idow = Dt.formats.V(new Date("" + (d.getFullYear()-1) + "/12/31")); |
264 } | 264 } |
265 | 265 |
266 return xPad(idow, 0); | 266 return xPad(idow, 0); |
267 }, | 267 }, |
268 w: "getDay", | 268 w: "getDay", |
269 W: function (d) { | 269 W: function (d) { |
270 var doy = parseInt(Dt.formats.j(d), 10); | 270 var doy = parseInt(Dt.formats.j(d), 10); |
343 function strftime(fmt, thisTime) | 343 function strftime(fmt, thisTime) |
344 { | 344 { |
345 var thisDate = new Date(); | 345 var thisDate = new Date(); |
346 thisDate.setTime(Math.floor(thisTime / 1000)); | 346 thisDate.setTime(Math.floor(thisTime / 1000)); |
347 return Dt.format(thisDate, fmt); | 347 return Dt.format(thisDate, fmt); |
348 }; | 348 }; |
349 | |
350 function fromDatetime(year, month, date, hour, minute, second) { | |
351 console.log(arguments); | |
352 return (new Date(year, month, date, hour, minute, second)).getTime() * 1000; | |
353 }; | |
354 | |
355 function datetimeYear(t) { | |
356 return (new Date(t / 1000)).getYear() + 1900; | |
357 }; | |
358 | |
359 function datetimeMonth(t) { | |
360 return (new Date(t / 1000)).getMonth(); | |
361 }; | |
362 | |
363 function datetimeDay(t) { | |
364 return (new Date(t / 1000)).getDate(); | |
365 }; | |
366 | |
367 function datetimeHour(t) { | |
368 return (new Date(t / 1000)).getHours(); | |
369 }; | |
370 | |
371 function datetimeMinute(t) { | |
372 return (new Date(t / 1000)).getMinutes(); | |
373 }; | |
374 | |
375 function datetimeSecond(t) { | |
376 return (new Date(t / 1000)).getSeconds(); | |
377 }; | |
378 | |
379 function datetimeDayOfWeek(t) { | |
380 return (new Date(t / 1000)).getDay(); | |
381 }; | |
349 | 382 |
350 | 383 |
351 // Error handling | 384 // Error handling |
352 | 385 |
353 function uw_debug(msg) { | 386 function uw_debug(msg) { |
715 | 748 |
716 function runScripts(node) { | 749 function runScripts(node) { |
717 if (node.tagName == "SCRIPT") { | 750 if (node.tagName == "SCRIPT") { |
718 var savedScript = thisScript; | 751 var savedScript = thisScript; |
719 thisScript = node; | 752 thisScript = node; |
720 | 753 |
721 try { | 754 try { |
722 eval(thisScript.text); | 755 eval(thisScript.text); |
723 } catch (v) { | 756 } catch (v) { |
724 doExn(v); | 757 doExn(v); |
725 } | 758 } |
1100 var x = document.createElement("script"); | 1133 var x = document.createElement("script"); |
1101 x.dead = false; | 1134 x.dead = false; |
1102 x.signal = s_class; | 1135 x.signal = s_class; |
1103 x.sources = null; | 1136 x.sources = null; |
1104 x.closures = htmlCls; | 1137 x.closures = htmlCls; |
1105 | 1138 |
1106 x.recreate = function(v) { | 1139 x.recreate = function(v) { |
1107 for (var ls = x.closures; ls != htmlCls; ls = ls.next) | 1140 for (var ls = x.closures; ls != htmlCls; ls = ls.next) |
1108 freeClosure(ls.data); | 1141 freeClosure(ls.data); |
1109 | 1142 |
1110 var cls = {v : null}; | 1143 var cls = {v : null}; |
1121 var x = document.createElement("script"); | 1154 var x = document.createElement("script"); |
1122 x.dead = false; | 1155 x.dead = false; |
1123 x.signal = s_style; | 1156 x.signal = s_style; |
1124 x.sources = null; | 1157 x.sources = null; |
1125 x.closures = htmlCls2; | 1158 x.closures = htmlCls2; |
1126 | 1159 |
1127 x.recreate = function(v) { | 1160 x.recreate = function(v) { |
1128 for (var ls = x.closures; ls != htmlCls2; ls = ls.next) | 1161 for (var ls = x.closures; ls != htmlCls2; ls = ls.next) |
1129 freeClosure(ls.data); | 1162 freeClosure(ls.data); |
1130 | 1163 |
1131 var cls = {v : null}; | 1164 var cls = {v : null}; |