private Date convertDate ( final Object data ) { if ( data == null ) { return null ; } else if ( data instanceof Date ) { return ( Date ) data ; } else if ( data instanceof Long ) { return new Date ( ( Long ) data ) ; } else if ( data instanceof Calendar ) { return ( ( Calendar ) data ) . getTime ( ) ; } else if ( data instanceof String ) { try { SimpleDateFormat sdf = new SimpleDateFormat ( INTERNAL_DATE_FORMAT ) ; sdf . setLenient ( lenient ) ; return sdf . parse ( ( String ) data ) ; } catch ( ParseException e ) { throw new SystemException ( "Could not convert String data [" + data + "] to a date." ) ; } } throw new SystemException ( "Cannot convert data type " + data . getClass ( ) + " to a date." ) ; }
Attempts to convert the given object to a date . Throws a SystemException on error .