2004/01/03 04:27:27
[org.ibex.core.git] / src / org / xwt / js / JSDate.java
index 345e3d4..ca9c5b7 100644 (file)
@@ -61,7 +61,7 @@ public class JSDate extends JS {
 
     public String coerceToString() { return date_format(date, FORMATSPEC_FULL); }
 
-    public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) {
+    public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
         switch(nargs) {
             case 0: {
                 //#switch(method)
@@ -126,7 +126,7 @@ public class JSDate extends JS {
         return super.callMethod(method, a0, a1, a2, rest, nargs);
     }
 
-    public Object get(Object key) {
+    public Object get(Object key) throws JSExn {
         //#switch(key)
         case "toString": return METHOD;
         case "toTimeString": return METHOD;
@@ -896,71 +896,62 @@ public class JSDate extends JS {
     private static double _toNumber(Object[] o, int index) { return JS.toDouble(o[index]); }
     private static double toDouble(double d) { return d; }
 
-    // FIXME: switch to new calling convention here
-    public JSDate(JSArray args_) {
-        Object[] args = new Object[args_.length()];
-        for(int i=0; i<args.length; i++) args[i] = args_.elementAt(i);
-        JSDate obj = this;
-
-        // if called as a constructor with no args,
-        // return a new Date with the current time.
-        if (args.length == 0) {
-            obj.date = Now();
-            return;
-        }
+    public JSDate(Object a0, Object a1, Object a2, Object[] rest, int nargs) {
 
-        // if called with just one arg -
-        if (args.length == 1) {
-            double date;
-            if (args[0] instanceof JS)
-                args[0] = ((JS) args[0]).toString();
-            if (!(args[0] instanceof String)) {
-                // if it's not a string, use it as a millisecond date
-                date = _toNumber(args[0]);
-            } else {
-                // it's a string; parse it.
-                String str = (String) args[0];
-                date = date_parseString(str);
+        JSDate obj = this;
+        switch (nargs) {
+            case 0: {
+                obj.date = Now();
+                return;
             }
-            obj.date = TimeClip(date);
-            return;
-        }
-
-        // multiple arguments; year, month, day etc.
-        double array[] = new double[MAXARGS];
-        int loop;
-        double d;
-
-        for (loop = 0; loop < MAXARGS; loop++) {
-            if (loop < args.length) {
-                d = _toNumber(args[loop]);
-
-                if (d != d || Double.isInfinite(d)) {
-                    obj.date = Double.NaN;
-                    return;
+            case 1: {
+                double date;
+                if (a0 instanceof JS)
+                    a0 = ((JS) a0).toString();
+                if (!(a0 instanceof String)) {
+                    // if it's not a string, use it as a millisecond date
+                    date = _toNumber(a0);
+                } else {
+                    // it's a string; parse it.
+                    String str = (String) a0;
+                    date = date_parseString(str);
                 }
-                array[loop] = toDouble(args[loop]);
-            } else {
-                array[loop] = 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]);
+                    if (d != d || Double.isInfinite(d)) {
+                        obj.date = Double.NaN;
+                        return;
+                    }
+                    array[i] = d;
+                }
+                
+                /* adjust 2-digit years into the 20th century */
+                if (array[0] >= 0 && array[0] <= 99)
+                    array[0] += 1900;
+                
+                /* if we got a 0 for 'date' (which is out of range)
+                 * pretend it's a 1 */
+                if (array[2] < 1)
+                    array[2] = 1;
+                
+                double day = MakeDay(array[0], array[1], array[2]);
+                double time = MakeTime(array[3], array[4], array[5], array[6]);
+                time = MakeDate(day, time);
+                time = internalUTC(time);
+                obj.date = TimeClip(time);
+                
+                return;
             }
         }
-
-        /* adjust 2-digit years into the 20th century */
-        if (array[0] >= 0 && array[0] <= 99)
-            array[0] += 1900;
-
-        /* if we got a 0 for 'date' (which is out of range)
-         * pretend it's a 1 */
-        if (array[2] < 1)
-            array[2] = 1;
-
-        double day = MakeDay(array[0], array[1], array[2]);
-        double time = MakeTime(array[3], array[4], array[5], array[6]);
-        time = MakeDate(day, time);
-        time = internalUTC(time);
-        obj.date = TimeClip(time);
-
-        return;
     }
 
     /* constants for toString, toUTCString */