changeset 1980:334b5cbff198

Bare-bones Datetime JS support.
author Patrick Hurst <phurst@mit.edu>
date Mon, 20 Jan 2014 04:34:42 -0500
parents 81bc76aa4acd
children fa044101ad99
files lib/js/urweb.js src/settings.sml
diffstat 2 files changed, 44 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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);
--- 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"),