comparison lib/js/urweb.js @ 1980:334b5cbff198

Bare-bones Datetime JS support.
author Patrick Hurst <phurst@mit.edu>
date Mon, 20 Jan 2014 04:34:42 -0500
parents a671e5258a2c
children
comparison
equal deleted inserted replaced
1979:81bc76aa4acd 1980:334b5cbff198
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
351 function datetimeYear(tm) {
352 return new Date(tm).getYear();
353 }
354
355 function datetimeMonth(tm) {
356 return new Date(tm).getMonth();
357 }
358
359 function datetimeDay(tm) {
360 return new Date(tm).getDate();
361 }
362
363 function datetimeHour(tm) {
364 return new Date(tm).getHours();
365 }
366
367 function datetimeMinute(tm) {
368 return new Date(tm).getMinutes();
369 }
370
371 function datetimeSecond(tm) {
372 return new Date(tm).getSeconds();
373 }
374
375 function datetimeDayOfWeek(tm) {
376 return new Date(tm).getDay();
377 }
349 378
350 379
351 // Error handling 380 // Error handling
352 381
353 function uw_debug(msg) { 382 function uw_debug(msg) {
715 744
716 function runScripts(node) { 745 function runScripts(node) {
717 if (node.tagName == "SCRIPT") { 746 if (node.tagName == "SCRIPT") {
718 var savedScript = thisScript; 747 var savedScript = thisScript;
719 thisScript = node; 748 thisScript = node;
720 749
721 try { 750 try {
722 eval(thisScript.text); 751 eval(thisScript.text);
723 } catch (v) { 752 } catch (v) {
724 doExn(v); 753 doExn(v);
725 } 754 }
1100 var x = document.createElement("script"); 1129 var x = document.createElement("script");
1101 x.dead = false; 1130 x.dead = false;
1102 x.signal = s_class; 1131 x.signal = s_class;
1103 x.sources = null; 1132 x.sources = null;
1104 x.closures = htmlCls; 1133 x.closures = htmlCls;
1105 1134
1106 x.recreate = function(v) { 1135 x.recreate = function(v) {
1107 for (var ls = x.closures; ls != htmlCls; ls = ls.next) 1136 for (var ls = x.closures; ls != htmlCls; ls = ls.next)
1108 freeClosure(ls.data); 1137 freeClosure(ls.data);
1109 1138
1110 var cls = {v : null}; 1139 var cls = {v : null};
1121 var x = document.createElement("script"); 1150 var x = document.createElement("script");
1122 x.dead = false; 1151 x.dead = false;
1123 x.signal = s_style; 1152 x.signal = s_style;
1124 x.sources = null; 1153 x.sources = null;
1125 x.closures = htmlCls2; 1154 x.closures = htmlCls2;
1126 1155
1127 x.recreate = function(v) { 1156 x.recreate = function(v) {
1128 for (var ls = x.closures; ls != htmlCls2; ls = ls.next) 1157 for (var ls = x.closures; ls != htmlCls2; ls = ls.next)
1129 freeClosure(ls.data); 1158 freeClosure(ls.data);
1130 1159
1131 var cls = {v : null}; 1160 var cls = {v : null};