Example usage for java.text DateFormat setLenient

List of usage examples for java.text DateFormat setLenient

Introduction

In this page you can find the example usage for java.text DateFormat 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.sarm.aussiepayslipgenerator.view.PaySlipController.java

@InitBinder
public void initBinder(WebDataBinder binder) {

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    dateFormat.setLenient(false);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));

}

From source file:com.haulmont.chile.core.datatypes.impl.DateDatatype.java

@Override
public Date parse(String value, Locale locale) throws ParseException {
    if (StringUtils.isBlank(value)) {
        return null;
    }//from   w  ww.  j a v a  2s . c om

    FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale);
    if (formatStrings == null) {
        return parse(value);
    }

    DateFormat format = new SimpleDateFormat(formatStrings.getDateFormat());
    format.setLenient(false);

    return normalize(format.parse(value.trim()));
}

From source file:org.springframework.binding.convert.converters.StringToDate.java

protected DateFormat getDateFormat() {
    Locale locale = determineLocale(this.locale);
    DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    format.setLenient(false);
    if (format instanceof SimpleDateFormat) {
        String pattern = determinePattern(this.pattern);
        ((SimpleDateFormat) format).applyPattern(pattern);
    } else {/*w w  w  .j  av a  2 s . co m*/
        logger.warn("Unable to apply format pattern '" + pattern
                + "'; Returned DateFormat is not a SimpleDateFormat");
    }
    return format;
}

From source file:biblivre3.administration.ReportsHandler.java

private ReportsDTO populateDto(HttpServletRequest request, HashMap<String, String> model) throws Exception {
    ReportsDTO dto = new ReportsDTO();

    String reportId = model.get("reportId");
    ReportType type = ReportType.getById(reportId);
    dto.setType(type);/*from  w w w. j a  v  a 2  s.  co  m*/

    if (type.isTimePeriod()) {
        String defaultFormat = I18nUtils.getText(request.getSession(), "biblivre3", "DEFAULT_DATE_FORMAT");
        DateFormat formatter = new SimpleDateFormat(defaultFormat);
        formatter.setLenient(false);

        String initialDate = model.get("initialDate");
        Date parsedStartDate = (Date) formatter.parse(initialDate);
        dto.setInitialDate(parsedStartDate);

        String finalDate = model.get("finalDate");
        Date parsedFinalDate = (Date) formatter.parse(finalDate);
        dto.setFinalDate(parsedFinalDate);
    }

    String database = model.get("database");
    dto.setDatabase(Database.valueOf(database));

    String order = model.get("order");
    dto.setOrder(order);

    String userId = model.get("userId");
    dto.setUserId(userId);

    String recordIds = model.get("recordIds");
    dto.setRecordIds(recordIds);

    String authorName = model.get("authorName");
    dto.setAuthorName(authorName);

    String datafield = model.get("datafield");
    dto.setDatafield(datafield);

    String digits = model.get("digits");
    try {
        dto.setDigits(Integer.valueOf(digits));
    } catch (Exception pokemon) {
    }

    return dto;
}

From source file:com.haulmont.cuba.desktop.sys.vcl.DatePicker.DatePicker.java

@Override
public void setFormats(DateFormat... formats) {
    if (formats != null) {
        Contract.asNotNull(formats, "the array of formats " + "must not contain null elements");
    }/*from  w  w w . j av  a  2s . c om*/
    DateFormat[] old = getFormats();
    for (DateFormat format : formats) {
        format.setLenient(false);
    }
    getEditor().setFormatterFactory(
            new DefaultFormatterFactory(new DatePicker.CustomDatePickerFormatter(formats, getLocale())));
    firePropertyChange("formats", old, getFormats());
}

From source file:com.googlecode.jsfFlex.component.ext.AbstractFlexUIDateChooser.java

@Override
public void decode(FacesContext context) {
    super.decode(context);

    java.util.Map<String, String> requestMap = context.getExternalContext().getRequestParameterMap();

    String selectedDateId = getId() + SELECTED_DATE_ID_APPENDED;
    String selectedDateUpdateVal = requestMap.get(selectedDateId);

    if (selectedDateUpdateVal != null && selectedDateUpdateVal.length() > 0) {
        /*//from w  w w  .  j  a  v a  2 s .c  o m
         * HACK: Since ActionScript returns date in format of "Thu Aug 23 00:00:00 GMT-0700 2009"
         * and "EEE MMM dd HH:mm:ss zZ yyyy" pattern doesn't seem to match it within SimpleDateFormat,
         * place a space between z + Z
         */
        int dashIndex = selectedDateUpdateVal.indexOf("-");
        if (dashIndex != -1) {
            selectedDateUpdateVal = selectedDateUpdateVal.substring(0, dashIndex) + " "
                    + selectedDateUpdateVal.substring(dashIndex);
        }
        Calendar instance = Calendar.getInstance();
        try {
            DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_DEFAULT);
            dateFormat.setLenient(true);
            instance.setTime(dateFormat.parse(selectedDateUpdateVal));
            setSelectedDate(instance);
            setSubmittedValue(selectedDateUpdateVal);
        } catch (ParseException parsingException) {
            setValid(false);
            context.addMessage(getId(),
                    new FacesMessage("Parsing exception for value : " + selectedDateUpdateVal));
            _log.error("Parsing exception for value : " + selectedDateUpdateVal, parsingException);
        }
    }
}

From source file:org.kuali.coeus.common.questionnaire.framework.answer.SaveQuestionnaireAnswerRule.java

private boolean validateAttributeFormat(Answer answer, String errorKey, int questionIndex) {
    boolean valid = true;

    ValidationPattern validationPattern = VALIDATION_CLASSES
            .get(answer.getQuestion().getQuestionTypeId().toString());

    // if there is no data type matched, then set error ?
    Pattern validationExpression = validationPattern.getRegexPattern();

    String validFormat = getValidFormat(answer.getQuestion().getQuestionTypeId().toString());

    if (validFormat.equals(Constants.DATA_TYPE_STRING) || validFormat.equals(Constants.DATA_TYPE_NUMBER)) {
        if (!validationExpression.matcher(answer.getAnswer()).matches()) {
            GlobalVariables.getMessageMap().putError(errorKey, KeyConstants.ERROR_INVALID_FORMAT_WITH_FORMAT,
                    new String[] { ANSWER + (questionIndex + 1), answer.getAnswer(), validFormat });
            valid = false;//  ww  w  .  j  a  v  a 2s . c om
        }
    } else if (validFormat.equals(Constants.DATA_TYPE_DATE)) {
        try {
            DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);
            dateFormat.setLenient(false);
            dateFormat.parse(answer.getAnswer());
        } catch (ParseException e) {
            GlobalVariables.getMessageMap().putError(errorKey, RiceKeyConstants.ERROR_INVALID_FORMAT,
                    ANSWER + (questionIndex + 1), answer.getAnswer(), validFormat);
            valid = false;
        }
    }

    return valid;
}

From source file:edu.uiowa.icts.bluebutton.domain.LabTest.java

public void setDateCreated(String dateCreated) {
    try {/* ww w  . j  av  a 2 s .c  o  m*/
        DateFormat formatter = new SimpleDateFormat("dd-MMM-yy");
        formatter.setLenient(true);
        this.dateCreated = formatter.parse(dateCreated);
    } catch (ParseException e) {
        log.error(" ParseException setting date for DateCreated", e);
    }
}

From source file:edu.uiowa.icts.bluebutton.domain.LabTest.java

public void setDateUpdated(String dateUpdated) {
    try {/*from  w w w .ja va  2  s  .  co  m*/
        DateFormat formatter = new SimpleDateFormat("dd-MMM-yy");
        formatter.setLenient(true);
        this.dateUpdated = formatter.parse(dateUpdated);
    } catch (ParseException e) {
        log.error(" ParseException setting date for DateUpdated", e);
    }
}

From source file:org.sipfoundry.sipxconfig.vm.VoicemailTest.java

/**
 * XCF-1519//from   w ww.  j av  a2  s . co m
 */
public void testGetDateWithNoTimezone() throws ParseException {
    DateFormat formatter = new SimpleDateFormat(MessageDescriptor.TIMESTAMP_FORMAT_NO_ZONE);
    formatter.setLenient(true);
    formatter.parse("Sun, 11-Feb-2007 04:07:31 AM");
}