Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rhino: coercing NativeDate to java.util.Date

0 views
Skip to first unread message

Hannes Wallnöfer

unread,
Oct 9, 2002, 7:12:17 AM10/9/02
to
It's currently (rhino 1.5 R3) not possible to call Java methods from
JavaScript that take a java.util.Date parameter with a native JavaScript
Date object. What I would like to do is something like this:

var date = new Date();
var format = new java.text.SimpleDateFormat();
var d = format.format(date);

which throws

org.mozilla.javascript.EvaluatorException: Cannot convert
org.mozilla.javascript.NativeDate@299a21 to java.util.Date

in NativeJavaObject.coerceType(NativeJavaObject.java:685).

I know I could use java.util.Date directly, but I already have the
native date object and would prefer not to create another date object
just for formatting.

It seems this is easy to fix by adding a case in
NativeJavaObject.coerceType and a method that returns the time in
milliseconds in NativeDate, but before making a patch I wanted to
reassure myself whether this would be accepted by the maintainers or
whether I'm overlooking something and there's a reason for there not to
be automatic coercion (standards, different semantics...).

Hannes

0 new messages