Mercurial > urweb
changeset 1986:b2254554542f
Add Datetime JavaScript support.
author | Patrick Hurst <phurst@mit.edu> |
---|---|
date | Mon, 17 Feb 2014 19:21:46 -0500 |
parents | 5195378deeca |
children | abb6981a2c4c |
files | lib/js/urweb.js src/settings.sml |
diffstat | 2 files changed, 50 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/js/urweb.js Sat Feb 15 01:04:31 2014 -0500 +++ b/lib/js/urweb.js Mon Feb 17 19:21:46 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,40 @@ var thisDate = new Date(); thisDate.setTime(Math.floor(thisTime / 1000)); return Dt.format(thisDate, fmt); -}; +}; + +function fromDatetime(year, month, date, hour, minute, second) { + console.log(arguments); + return (new Date(year, month, date, hour, minute, second)).getTime() * 1000; +}; + +function datetimeYear(t) { + return (new Date(t / 1000)).getYear() + 1900; +}; + +function datetimeMonth(t) { + return (new Date(t / 1000)).getMonth(); +}; + +function datetimeDay(t) { + return (new Date(t / 1000)).getDate(); +}; + +function datetimeHour(t) { + return (new Date(t / 1000)).getHours(); +}; + +function datetimeMinute(t) { + return (new Date(t / 1000)).getMinutes(); +}; + +function datetimeSecond(t) { + return (new Date(t / 1000)).getSeconds(); +}; + +function datetimeDayOfWeek(t) { + return (new Date(t / 1000)).getDay(); +}; // Error handling @@ -717,7 +750,7 @@ if (node.tagName == "SCRIPT") { var savedScript = thisScript; thisScript = node; - + try { eval(thisScript.text); } catch (v) { @@ -1102,7 +1135,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 +1156,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);
--- a/src/settings.sml Sat Feb 15 01:04:31 2014 -0500 +++ b/src/settings.sml Mon Feb 17 19:21:46 2014 -0500 @@ -331,6 +331,16 @@ ("toMilliseconds", "toMilliseconds"), ("diffInMilliseconds", "diffInMilliseconds"), + ("fromDatetime", "fromDatetime"), + ("datetimeYear", "datetimeYear"), + ("datetimeMonth", "datetimeMonth"), + ("datetimeDay", "datetimeDay"), + ("datetimeHour", "datetimeHour"), + ("datetimeMinute", "datetimeMinute"), + ("datetimeSecond", "datetimeSecond"), + ("datetimeDayOfWeek", "datetimeDayOfWeek"), + + ("onClick", "uw_onClick"), ("onDblclick", "uw_onDblclick"), ("onKeydown", "uw_onKeydown"),