move to JS interface
[org.ibex.js.git] / src / org / ibex / js / JSDate.java
index dc6d839..203fdc5 100644 (file)
@@ -44,7 +44,8 @@ import java.text.DateFormat;
  * @author Mike McCabe
  * @author Adam Megacz (many modifications
  */
-public class JSDate extends JS {
+public class JSDate extends JS.Immutable {
+    private static final JS.Method METHOD = new JS.Method();
 
     public JSDate() {
         if (thisTimeZone == null) {
@@ -55,10 +56,10 @@ public class JSDate extends JS {
         }
     }
 
-    String coerceToString() { return date_format(date, FORMATSPEC_FULL); }
+    public String coerceToString() { return date_format(date, FORMATSPEC_FULL); }
 
-    public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
-        switch(nargs) {
+    public JS call(JS method, JS[] args) throws JSExn {
+        switch(args.length) {
             case 0: {
                 //#switch(JS.toString(method))
                 case "toString": return JS.S(date_format(date, FORMATSPEC_FULL));
@@ -89,7 +90,7 @@ public class JSDate extends JS {
                 case "getUTCMilliseconds": return N(msFromTime(date));
                 case "getTimezoneOffset": return N(getTimezoneOffset(date));
                 //#end
-                return super.callMethod(method, a0, a1, a2, rest, nargs);
+                return super.call(method, args);
             }
             case 1: {
                 //#switch(JS.toString(method))
@@ -119,7 +120,7 @@ public class JSDate extends JS {
                 //#end
             }
         }
-        return super.callMethod(method, a0, a1, a2, rest, nargs);
+        return super.call(method, args);
     }
 
     public JS get(JS key) throws JSExn {
@@ -892,10 +893,10 @@ public class JSDate extends JS {
     private static double _toNumber(JS[] o, int index) throws JSExn { return JS.toDouble(o[index]); }
     private static double toDouble(double d) { return d; }
 
-    public JSDate(JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
+    public JSDate(JS[] args) throws JSExn {
 
         JSDate obj = this;
-        switch (nargs) {
+        switch (args.length) {
             case 0: {
                 obj.date = Now();
                 return;
@@ -905,18 +906,18 @@ public class JSDate extends JS {
                 if(isString(a0))
                     date = date_parseString(JS.toString(a0));
                 else
-                    date = _toNumber(a0);
+                    date = _toNumber(args[0]);
                 obj.date = TimeClip(date);
                 return;
             }
             default: {
                 // multiple arguments; year, month, day etc.
                 double array[] = new double[MAXARGS];
-                array[0] = toDouble(a0);
-                array[1] = toDouble(a1);
-                if (nargs >= 2) array[2] = toDouble(a2);
-                for(int i=0; i<nargs; i++) {
-                    double d = _toNumber(i==0?a0:i==1?a1:i==2?a2:rest[i-3]);
+                array[0] = Script.toDouble(args[0]);
+                array[1] = Script.toDouble(args[1]);
+                if (args.length >= 2) array[2] = Script.toDouble(args[2]);
+                for (int i=0; i < args.length; i++) {
+                    double d = _toNumber(args[i]);
                     if (d != d || Double.isInfinite(d)) {
                         obj.date = Double.NaN;
                         return;