AnsweredAssumed Answered

Groovy script for simpledateformat (MMddyy)

Question asked by asha120987 on Oct 19, 2018
Latest reply on Oct 22, 2018 by trey.yeager826393

Hello All,

 

  When am trying to implement code in groovy with MMddyy format am facing unparceable date format can anyone help me on this!! please...

 

import java.util.Properties;
import java.io.InputStream;
import com.boomi.execution.ExecutionUtil;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

for( int i = 0; i < dataContext.getDataCount(); i++ ) {
InputStream is = dataContext.getStream(i);
Properties props = dataContext.getProperties(i);
logger = ExecutionUtil.getBaseLogger();

String fileName = props.getProperty("document.dynamic.userdefined.file2");
String days = props.getProperty("document.dynamic.userdefined.Days");

int noofdays=Integer.parseInt(days);
int day=-noofdays;
logger.info("LOOP ENETERED OVER HERE");

substr = fileName.substring(fileName.length()-17, fileName.length()-10);
logger.info(substr);
Date date = new Date();
SimpleDateFormat df = new SimpleDateFormat("MMddyy");  //this is the line .....
Date d = df.parse(substr);
logger.info("filetime"+d);

Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, day);

logger.info("before checking");

logger.info("purging time"+cal.getTime());

if (d.before(cal.getTime())) {
logger.info("deleting1");

props.setProperty("document.dynamic.userdefined.userdate", substr);

logger.info("deleting");
}

dataContext.storeStream(is, props);
}

Outcomes