Example usage for java.text SimpleDateFormat setLenient

List of usage examples for java.text SimpleDateFormat setLenient

Introduction

In this page you can find the example usage for java.text SimpleDateFormat setLenient.

Prototype

public void setLenient(boolean lenient) 

Source Link

Document

Specify whether or not date/time parsing is to be lenient.

Usage

From source file:com.indicator_engine.controller.RegistrationController.java

/**
 * Register Property Editors//from w  w w .  jav  a 2s . c o m
 */
@InitBinder
public void initBinder(WebDataBinder binder) {
    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
    sdf.setLenient(true);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
    // You can register other Custom Editors with the WebDataBinder,
    // like CustomNumberEditor for Integers and Longs, or StringTrimmerEditor for Strings
}

From source file:org.openmrs.module.openhmis.cashier.web.controller.CashierController.java

@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(CashPoint.class, new EntityPropertyEditor<CashPoint>(ICashPointService.class));
    binder.registerCustomEditor(Provider.class, new ProviderPropertyEditor());

    SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
    dateFormat.setLenient(false);

    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}

From source file:oscar.dms.EDocUtil.java

private static boolean hasSubdir(String fileName) {
    boolean res = false;

    try {/*from   w  w  w . j  a v a2  s. c o m*/
        String prefix = fileName.substring(0, fileName.indexOf("."));
        if (prefix.length() == 6) {
            SimpleDateFormat format = new SimpleDateFormat("yyyyMM");
            format.setLenient(false);
            Date test = format.parse(prefix);
            res = true;
        }
    } catch (Exception ex) {
    }

    return res;
}

From source file:cz.muni.fi.pa165.mvc.controllers.GameController.java

@InitBinder
protected void initBinder(WebDataBinder binder) {
    if (binder.getTarget() instanceof GameCreateDTO) {
        binder.addValidators(new GameCreateDTOValidator());
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
        sdf.setLenient(true);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
    }/*from w ww .ja v a  2 s . c  o  m*/
}

From source file:us.mn.state.health.lims.upload.sample.TestResultPersister.java

@Override
public RowResult<CSVSample> validate(CSVSample csvSample) {
    String registrationNumberFormat = getStNumberFormat();
    registrationNumberFormat = registrationNumberFormat.substring(1, registrationNumberFormat.length() - 1);
    String fullRegistrationNumber = csvSample.healthCenter + csvSample.patientRegistrationNumber;
    StringBuilder errorMessage = new StringBuilder();

    if (isEmpty(csvSample.healthCenter) || !getHealthCenterCodes().contains(csvSample.healthCenter)) {
        errorMessage.append("Invalid Subcenter code.\n");
    }/*from   ww w  .j a va 2  s .c o  m*/

    if (isEmpty(csvSample.patientRegistrationNumber))
        errorMessage.append("Registration Number is mandatory.\n");

    if (!fullRegistrationNumber.matches(registrationNumberFormat))
        errorMessage.append("PatientID does not conform to the allowed format.\n");

    errorMessage.append(validateTestNames(csvSample.testResults));
    //        errorMessage.append(validateAtLeastOneTestIsNonEmpty(csvSample.testResults));
    //        errorMessage.append(validateAllTestResultsAreValid(csvSample.testResults));

    if (isEmpty(csvSample.accessionNumber)) {
        errorMessage.append("AccessionNumber should not be blank.\n");
    }

    if (!csvSample.accessionNumber.matches("^[\\d-]+$")) {
        errorMessage.append("AccessionNumber format is invalid.\n");
    }

    try {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
        simpleDateFormat.setLenient(false);
        simpleDateFormat.parse(csvSample.sampleDate);
    } catch (ParseException e) {
        errorMessage.append("Date should be in dd-mm-yyyy format and should be a valid date.\n");
    }

    if (isEmpty(errorMessage.toString()))
        return new RowResult<>(csvSample);

    return new RowResult<>(csvSample, errorMessage.toString());
}

From source file:com.trenako.web.controllers.CollectionsController.java

@InitBinder
public void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    dateFormat.setLenient(false);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    binder.registerCustomEditor(Integer.class, new CustomNumberEditor(Integer.class, true));
}

From source file:cz.muni.fi.pa165.mvc.controllers.PlayerController.java

@InitBinder
protected void initBinder(WebDataBinder binder) {
    if (binder.getTarget() instanceof PlayerCreateDTO) {
        binder.addValidators(new PlayerCreateDTOValidator());
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
        sdf.setLenient(true);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
    }//w w  w  .j  ava2s.c  o m
}

From source file:edu.harvard.iq.dataverse.DatasetFieldValueValidator.java

private boolean isValidDate(String dateString, String pattern) {
    boolean valid = true;
    Date date;//from   w  ww  . j  a  va 2s. c om
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);
    sdf.setLenient(false);
    try {
        dateString = dateString.trim();
        date = sdf.parse(dateString);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int year = calendar.get(Calendar.YEAR);
        int era = calendar.get(Calendar.ERA);
        if (era == GregorianCalendar.AD) {
            if (year > 9999) {
                valid = false;
            }
        }
    } catch (ParseException e) {
        valid = false;
    }
    if (dateString.length() > pattern.length()) {
        valid = false;
    }
    return valid;
}

From source file:com.persistent.cloudninja.controller.MangeUsersController.java

@InitBinder
public void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
    dateFormat.setLenient(false);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));

}

From source file:org.eclipse.riena.ui.ridgets.validation.AbstractValidDate.java

private boolean isDate(final String value, final String pattern, final boolean strict) {
    if (value == null || pattern == null || pattern.length() <= 0) {

        return false;
    }//w w w.j a v a2s. c o m
    if (strict && value.length() != pattern.length()) {
        return false;
    }
    final SimpleDateFormat formatter = new SimpleDateFormat(pattern);
    formatter.setLenient(false);

    final ParsePosition pos = new ParsePosition(0);
    formatter.parse(value, pos);
    if (pos.getErrorIndex() != -1) {
        return false;
    }
    if (strict) {
        if (pos.getIndex() < value.length()) {
            return false;
        }
    }
    return true;
}