Issue Type: Improvement Improvement
Assignee: Unassigned
Components: Java Integration
Created: 26/May/13 10:09 PM
Description:

When a script passes in a Ruby Time object, JRuby automatically converts this to java.util.Date (this is probably fine, although converting to an org.joda.time.DateTime would obviously be superior.)

However, in the other direction, when Java returns a java.util.Date object, this is not converted at all, but instead gets passed straight through.

Demonstration:

    @Test
    public void testReceivingTimeViaObject() throws Exception {
        ObjectMethods object = new ObjectMethods();
        engine.put("object", object);
        engine.eval("object.value = Time.new");
        assertThat(object.value.getClass(), is(equalTo((Class) Date.class)));
    }

    @Test
    public void testReturningTimeViaObject_JodaDateTime() throws Exception {
        ObjectMethods object = new ObjectMethods();
        object.value = DateTime.now();
        engine.put("object", object);
        assertThat((String) engine.eval("object.value.class.name"),
                   is(equalTo("Time")));
        assertThat((Boolean) engine.eval("object.value.is_a?(Time)"), is(true));
    }

    @Test
    public void testReturningTimeViaObject_JavaUtilDate() throws Exception {
        ObjectMethods object = new ObjectMethods();
        object.value = new Date();
        engine.put("object", object);
        assertThat((String) engine.eval("object.value.class.name"),
                   is(equalTo("Time")));
        assertThat((Boolean) engine.eval("object.value.is_a?(Time)"), is(true));
    }

    @Before
    public void setUp() throws Exception {
        ScriptEngineManager manager = new ScriptEngineManager();
        engine = manager.getEngineByExtension("rb");
    }

    public static class ObjectMethods {
        private Object value;

        public void setValue(Object value) {
            this.value = value;
        }

        public Object getValue() {
            return value;
        }
    }

It would be good if this at least worked consistently in both directions. In the ideal case, regardless of which kind of date came from the Java side (java.util.Date or org.joda.time.DateTime), it would be good if it behaved like a Time.

Project: JRuby
Priority: Major Major
Reporter: Trejkaz
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

Reply via email to