function preProcessor(q, field, document, userId, logger) { 
    //logger.info("------TESTING DATE PREPROCESSOR");
    let moment = require('moment');
    
    if (document[field.name]) {
        let saveValue = document[field.name];
        //**************************************
         if(saveValue instanceof Date && isNaN(saveValue.getTime()) === false) {
            // document[field.name] = moment(document[field.name], "MM/DD/YYYY hh:mm a").toDate();
            return document;
        } else if (!isNaN(saveValue)) {
            document[field.name] = new Date(saveValue);
            return document;
        } else {
            // turning on strict parsing with the true at the end of the moment() call 
            let date = moment(document[field.name], ["DD/MM/YYYY hh:mm a", "DD/MM/YYYY", "hh:mm a","DD/MM/YY","DD/MM/YY hh:mm a","DD/MM",moment.ISO_8601], true);
            if (date.isValid()) {
                document[field.name] = date.toDate();
                return document;
            } else {
                let errMsg = field.componentName + " field named " + field.name +
                    " has invalid value \"" + saveValue + "\"";
                logger.error("Preprocessing Failure : " + errMsg);
                return null;
            }
        }
    } else {
        return document;
    }
}
module.exports = preProcessor;
