@Test public void testConvert() throws Throwable { long expected = -404614800000L; myClassUnderTest.setDatePattern( "dd.MM.yy" ); Date actual = myClassUnderTest.convert( "7.3.57" ); long time = actual.getTime(); myLog.debug( "actual: " + actual ); Assert.assertNotNull( actual ); myLog.debug( "actual.time: " + time ); Assert.assertEquals( expected, actual.getTime() ); }
@Override public Date convert( String aValue ) throws SdiException { if ( !StringUtils.hasText( aValue ) ) { myLog.debug( "Given value is null" ); return null; } DateFormat df; if ( StringUtils.hasText( myDatePattern ) ) { df = new SimpleDateFormat( myDatePattern ); } else { df = new SimpleDateFormat(); } Date result; try { result = df.parse( aValue ); } catch ( ParseException t ) { throw new SdiException( "Problems converting date: " + aValue + "; myDatePattern: " + myDatePattern, SdiException.EXIT_CODE_PARSE_ERROR ); } return result; }
ConverterDate implements FieldConverter<Date> { @Override public Date convert( String aValue ) throws SdiException { if ( !StringUtils.hasText( aValue ) ) { myLog.debug( "Given value is null" ); return null; } DateFormat df; if ( StringUtils.hasText( myDatePattern ) ) { df = new SimpleDateFormat( myDatePattern ); } else { df = new SimpleDateFormat(); } Date result; try { result = df.parse( aValue ); } catch ( ParseException t ) { throw new SdiException( "Problems converting date: " + aValue + "; myDatePattern: " + myDatePattern, SdiException.EXIT_CODE_PARSE_ERROR ); } return result; } }
ConverterDate implements FieldConverter<Date> { @Override public Date convert( String aValue ) throws SdiException { if ( !StringUtils.hasText( aValue ) ) { myLog.debug( "Given value is null" ); return null; } DateFormat df; if ( StringUtils.hasText( myDatePattern ) ) { df = new SimpleDateFormat( myDatePattern ); } else { df = new SimpleDateFormat(); } Date result; try { result = df.parse( aValue ); } catch ( ParseException t ) { throw new SdiException( "Problems converting date: " + aValue + "; myDatePattern: " + myDatePattern, SdiException.EXIT_CODE_PARSE_ERROR ); } return result; } ConverterDate(); }
ConverterDate implements FieldConverter<Date> { @Override public Date convert( String aValue ) throws SdiException { if ( !StringUtils.hasText( aValue ) ) { myLog.debug( "Given value is null" ); return null; } DateFormat df; if ( StringUtils.hasText( myDatePattern ) ) { df = new SimpleDateFormat( myDatePattern ); } else { df = new SimpleDateFormat(); } Date result; try { result = df.parse( aValue ); } catch ( ParseException t ) { throw new SdiException( "Problems converting date: " + aValue + "; myDatePattern: " + myDatePattern, SdiException.EXIT_CODE_PARSE_ERROR ); } return result; } ConverterDate(); @Override ConverterDate init( Environment aEnv, String aFieldname ); @Override Date convert( String aValue ); String getDatePattern(); void setDatePattern( String aDatePattern ); }
ConverterDate implements FieldConverter<Date> { @Override public Date convert( String aValue ) throws SdiException { if ( !StringUtils.hasText( aValue ) ) { myLog.debug( "Given value is null" ); return null; } DateFormat df; if ( StringUtils.hasText( myDatePattern ) ) { df = new SimpleDateFormat( myDatePattern ); } else { df = new SimpleDateFormat(); } Date result; try { result = df.parse( aValue ); } catch ( ParseException t ) { throw new SdiException( "Problems converting date: " + aValue + "; myDatePattern: " + myDatePattern, SdiException.EXIT_CODE_PARSE_ERROR ); } return result; } ConverterDate(); @Override ConverterDate init( Environment aEnv, String aFieldname ); @Override Date convert( String aValue ); String getDatePattern(); void setDatePattern( String aDatePattern ); static final String CONVERTER_NAME; static final String PATTERN_SUFFIX; }