# HG changeset patch # User Patrick Hurst # Date 1390210482 18000 # Node ID 334b5cbff198bd24f542f622d657b00256fa2fe7 # Parent 81bc76aa4acd2e37c57fa14c17ade71f3ea9fa3c Bare-bones Datetime JS support. diff -r 81bc76aa4acd -r 334b5cbff198 lib/js/urweb.js --- a/lib/js/urweb.js Sat Jan 18 18:26:24 2014 -0500 +++ b/lib/js/urweb.js Mon Jan 20 04:34:42 2014 -0500 @@ -217,13 +217,13 @@ var y = d.getFullYear(); var V = parseInt(Dt.formats.V(d), 10); var W = parseInt(Dt.formats.W(d), 10); - + if(W > V) { y++; } else if(W===0 && V>=52) { y--; } - + return y; }, H: ["getHours", "0"], @@ -262,7 +262,7 @@ { idow = Dt.formats.V(new Date("" + (d.getFullYear()-1) + "/12/31")); } - + return xPad(idow, 0); }, w: "getDay", @@ -345,7 +345,36 @@ var thisDate = new Date(); thisDate.setTime(Math.floor(thisTime / 1000)); return Dt.format(thisDate, fmt); -}; +}; + + +function datetimeYear(tm) { + return new Date(tm).getYear(); +} + +function datetimeMonth(tm) { + return new Date(tm).getMonth(); +} + +function datetimeDay(tm) { + return new Date(tm).getDate(); +} + +function datetimeHour(tm) { + return new Date(tm).getHours(); +} + +function datetimeMinute(tm) { + return new Date(tm).getMinutes(); +} + +function datetimeSecond(tm) { + return new Date(tm).getSeconds(); +} + +function datetimeDayOfWeek(tm) { + return new Date(tm).getDay(); +} // Error handling @@ -717,7 +746,7 @@ if (node.tagName == "SCRIPT") { var savedScript = thisScript; thisScript = node; - + try { eval(thisScript.text); } catch (v) { @@ -1102,7 +1131,7 @@ x.signal = s_class; x.sources = null; x.closures = htmlCls; - + x.recreate = function(v) { for (var ls = x.closures; ls != htmlCls; ls = ls.next) freeClosure(ls.data); @@ -1123,7 +1152,7 @@ x.signal = s_style; x.sources = null; x.closures = htmlCls2; - + x.recreate = function(v) { for (var ls = x.closures; ls != htmlCls2; ls = ls.next) freeClosure(ls.data); diff -r 81bc76aa4acd -r 334b5cbff198 src/settings.sml --- a/src/settings.sml Sat Jan 18 18:26:24 2014 -0500 +++ b/src/settings.sml Mon Jan 20 04:34:42 2014 -0500 @@ -331,6 +331,14 @@ ("toMilliseconds", "toMilliseconds"), ("diffInMilliseconds", "diffInMilliseconds"), + ("datetimeYear", "datetimeYear"), + ("datetimeMonth", "datetimeMonth"), + ("datetimeDay", "datetimeDay"), + ("datetimeHour", "datetimeHour"), + ("datetimeMinute", "datetimeMinute"), + ("datetimeSecond", "datetimeSecond"), + ("datetimeDayOfWeek", "datetimeDayOfWeek"), + ("onClick", "uw_onClick"), ("onDblclick", "uw_onDblclick"), ("onKeydown", "uw_onKeydown"),