Subj : JavaScript vs Java Date To : netscape.public.mozilla.jseng From : Tarek Hammoud Date : Sat Oct 30 2004 05:58 pm Hello, I have this test program which I exepcted to return true. I construct a Java date to be 10/30/2004 and an equivalent JS date. However, when I compare them by calling getTime(), the result is always false. Thanks for any pointers. T Hammoud > import java.util.Date; > > import org.mozilla.javascript.Context; > import org.mozilla.javascript.Function; > import org.mozilla.javascript.Scriptable; > import org.mozilla.javascript.ScriptableObject; > import org.mozilla.javascript.WrapFactory; > > public class JavaDate { > > public void runJavaScriptTest(int n) { > > Context cx = Context.enter(); > > try { > ScriptableObject scope = cx.initStandardObjects(); > > cx.setWrapFactory(new MyWrapFactory()); > > String s = "function foo(javaConvertedDate) {return new Date(2004, 10, 30).getTime() == javaConvertedDate.getTime()} "; > Function f = cx.compileFunction(scope, s, "", 1, null); > > Object args[] = {new Date("10/30/2004")}; > Object rc = f.call(cx, scope, f, args); <================================= It is always false. > System.out.println("Test1 Call result " + rc + " :" + rc.getClass()); > > } catch (Exception e) { > e.printStackTrace(); > } > finally { > // Exit from the context. > Context.exit(); > } > } > > static class MyWrapFactory extends WrapFactory { > public Scriptable wrapAsJavaObject(Context cx, > Scriptable scope, > java.lang.Object javaObject, > java.lang.Class staticType) { > > if (javaObject instanceof java.util.Date) { > long time=((java.util.Date) javaObject).getTime(); > return cx.newObject(scope, "Date", new Object[] { new Double(time) }); > } > return super.wrapAsJavaObject(cx, scope, javaObject, staticType); > } > } > > public static void main(String[] args) { > JavaDate myTest = new JavaDate(); > myTest.runJavaScriptTest(1); > } > } .