@Test public void jsToDate_NativeDate() throws Exception { Date date = new Date( 1 ); Scriptable value = ctx.newObject( scope, "Date", new Object[] { date.getTime() } ); assertEquals( date, JavaScriptUtils.jsToDate( value, "org.mozilla.javascript.NativeDate" ) ); }
public static Date jsToDate( Object value, String classType ) throws KettleValueException { double dbl; if ( classType.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) { return null; } else { if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeDate" ) ) { dbl = Context.toNumber( value ); } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) || classType.equalsIgnoreCase( "java.util.Date" ) ) { try { Date dat = (Date) Context.jsToJava( value, java.util.Date.class ); dbl = dat.getTime(); } catch ( Exception e ) { try { Value v = (Value) Context.jsToJava( value, Value.class ); return v.getDate(); } catch ( Exception e2 ) { try { String string = Context.toString( value ); return XMLHandler.stringToDate( string ); } catch ( Exception e3 ) { throw new KettleValueException( "Can't convert a string to a date" ); } } } } else if ( classType.equalsIgnoreCase( "java.lang.Double" ) ) { dbl = (Double) value; } else { String string = (String) Context.jsToJava( value, String.class ); dbl = Double.parseDouble( string ); } long lng = Math.round( dbl ); return new Date( lng ); } }
JavaScriptUtils { public static Date jsToDate( Object value, String classType ) throws KettleValueException { double dbl; if ( classType.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) { return null; } else { if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeDate" ) ) { dbl = Context.toNumber( value ); } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) || classType.equalsIgnoreCase( "java.util.Date" ) ) { try { Date dat = (Date) Context.jsToJava( value, java.util.Date.class ); dbl = dat.getTime(); } catch ( Exception e ) { try { Value v = (Value) Context.jsToJava( value, Value.class ); return v.getDate(); } catch ( Exception e2 ) { try { String string = Context.toString( value ); return XMLHandler.stringToDate( string ); } catch ( Exception e3 ) { throw new KettleValueException( "Can't convert a string to a date" ); } } } } else if ( classType.equalsIgnoreCase( "java.lang.Double" ) ) { dbl = (Double) value; } else { String string = (String) Context.jsToJava( value, String.class ); dbl = Double.parseDouble( string ); } long lng = Math.round( dbl ); return new Date( lng ); } } }
JavaScriptUtils { public static Date jsToDate( Object value, String classType ) throws KettleValueException { double dbl; if ( classType.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) { return null; } else { if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeDate" ) ) { dbl = Context.toNumber( value ); } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) || classType.equalsIgnoreCase( "java.util.Date" ) ) { try { Date dat = (Date) Context.jsToJava( value, java.util.Date.class ); dbl = dat.getTime(); } catch ( Exception e ) { try { Value v = (Value) Context.jsToJava( value, Value.class ); return v.getDate(); } catch ( Exception e2 ) { try { String string = Context.toString( value ); return XMLHandler.stringToDate( string ); } catch ( Exception e3 ) { throw new KettleValueException( "Can't convert a string to a date" ); } } } } else if ( classType.equalsIgnoreCase( "java.lang.Double" ) ) { dbl = (Double) value; } else { String string = (String) Context.jsToJava( value, String.class ); dbl = Double.parseDouble( string ); } long lng = Math.round( dbl ); return new Date( lng ); } }  }
JavaScriptUtils { public static Date jsToDate( Object value, String classType ) throws KettleValueException { double dbl; if ( classType.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) { return null; } else { if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeDate" ) ) { dbl = Context.toNumber( value ); } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) || classType.equalsIgnoreCase( "java.util.Date" ) ) { try { Date dat = (Date) Context.jsToJava( value, java.util.Date.class ); dbl = dat.getTime(); } catch ( Exception e ) { try { Value v = (Value) Context.jsToJava( value, Value.class ); return v.getDate(); } catch ( Exception e2 ) { try { String string = Context.toString( value ); return XMLHandler.stringToDate( string ); } catch ( Exception e3 ) { throw new KettleValueException( "Can't convert a string to a date" ); } } } } else if ( classType.equalsIgnoreCase( "java.lang.Double" ) ) { dbl = (Double) value; } else { String string = (String) Context.jsToJava( value, String.class ); dbl = Double.parseDouble( string ); } long lng = Math.round( dbl ); return new Date( lng ); } }  static Object convertFromJs( Object value, int type, String fieldName ); static Number jsToNumber( Object value, String classType ); static Long jsToInteger( Object value, Class<?> clazz ); static String jsToString( Object value, String classType ); static Date jsToDate( Object value, String classType ); static BigDecimal jsToBigNumber( Object value, String classType ); }
JavaScriptUtils { public static Date jsToDate( Object value, String classType ) throws KettleValueException { double dbl; if ( classType.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) { return null; } else { if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeDate" ) ) { dbl = Context.toNumber( value ); } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) || classType.equalsIgnoreCase( "java.util.Date" ) ) { try { Date dat = (Date) Context.jsToJava( value, java.util.Date.class ); dbl = dat.getTime(); } catch ( Exception e ) { try { Value v = (Value) Context.jsToJava( value, Value.class ); return v.getDate(); } catch ( Exception e2 ) { try { String string = Context.toString( value ); return XMLHandler.stringToDate( string ); } catch ( Exception e3 ) { throw new KettleValueException( "Can't convert a string to a date" ); } } } } else if ( classType.equalsIgnoreCase( "java.lang.Double" ) ) { dbl = (Double) value; } else { String string = (String) Context.jsToJava( value, String.class ); dbl = Double.parseDouble( string ); } long lng = Math.round( dbl ); return new Date( lng ); } }  static Object convertFromJs( Object value, int type, String fieldName ); static Number jsToNumber( Object value, String classType ); static Long jsToInteger( Object value, Class<?> clazz ); static String jsToString( Object value, String classType ); static Date jsToDate( Object value, String classType ); static BigDecimal jsToBigNumber( Object value, String classType );  }