List of usage examples for java.text SimpleDateFormat setLenient
public void setLenient(boolean lenient)
From source file:abm.jakaria.school.CommiteeController.java
@InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); }
From source file:us.mn.state.health.lims.common.util.validator.DateValidator.java
/** * <p>Checks if the field is a valid date. The pattern is used with * <code>java.text.SimpleDateFormat</code>. If strict is true, then the * length will be checked so '2/12/1999' will not pass validation with * the format 'MM/dd/yyyy' because the month isn't two digits. * The setLenient method is set to <code>false</code> for all.</p> * //from w ww . j a va 2 s . c o m * @param value The value validation is being performed on. * @param datePattern The pattern passed to <code>SimpleDateFormat</code>. * @param strict Whether or not to have an exact match of the datePattern. */ public boolean isValid(String value, String datePattern, boolean strict) { if (value == null || datePattern == null || datePattern.length() <= 0) { return false; } //System.out.println("value & datePattern " + value + " " + datePattern); SimpleDateFormat formatter = new SimpleDateFormat(datePattern); formatter.setLenient(false); try { formatter.parse(value); } catch (ParseException e) { //bugzilla 2154 LogEvent.logError("DateValidator", "isValid()", e.toString()); return false; } if (strict && (datePattern.length() != value.length())) { return false; } return true; }
From source file:com.aplikasi.penjualan.controller.DataBarangHtmlController.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)); }
From source file:com.persistent.cloudninja.controller.TaskScheduleController.java
@InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); }
From source file:org.motechproject.server.omod.web.controller.MessagePatientController.java
@InitBinder public void initBinder(WebDataBinder binder) { String datePattern = "yyyy-MM-dd HH:mm:ss"; SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true, datePattern.length())); binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); }
From source file:org.syncope.core.persistence.beans.AbstractBaseBean.java
public final SimpleDateFormat getDateFormatter() { final SimpleDateFormat dateFormatter = DATE_FORMAT.get(); dateFormatter.setLenient(false); return dateFormatter; }
From source file:jp.co.nemuzuka.service.impl.CalendarServiceImpl.java
/** * ??.//from w w w .ja v a2 s . c o m * ????????????? * ?????????????????? * @param targetYyyyMM ? * @return ?(yyyyMM?) */ private String getYyyyMM(String targetYyyyMM) { if (StringUtils.isNotEmpty(targetYyyyMM)) { //???? SimpleDateFormat sdf = DateTimeUtils.createSdf("yyyyMM"); sdf.setLenient(false); try { sdf.parse(targetYyyyMM); //???????? return targetYyyyMM; } catch (ParseException e) { } } //?? return DateTimeUtils.getMonth(); }
From source file:de.hybris.platform.acceleratorstorefrontcommons.forms.validation.QuoteExpirationTimeValidator.java
@Override public boolean isValid(final Object expirationTime, final ConstraintValidatorContext constraintValidatorContext) { if (StringUtils.isEmpty((String) expirationTime)) { return true; }/*from w w w.jav a 2 s . co m*/ try { final Locale currentLocale = getI18nService().getCurrentLocale(); final String dateParsingFormat = getMessageSource().getMessage(DATE_FORMAT_KEY, null, currentLocale); final SimpleDateFormat dateFormat = new SimpleDateFormat(dateParsingFormat, currentLocale); dateFormat.setLenient(false); final Date expirationDate = QuoteExpirationTimeUtils .getEndOfDay(dateFormat.parse((String) expirationTime)); return QuoteExpirationTimeUtils.isExpirationTimeValid(expirationDate, getTimeService().getCurrentDateWithTimeNormalized()); } catch (final ParseException e) { return false; } }
From source file:org.motechproject.server.omod.web.dwr.DWRMotechService.java
public List<WebPatient> findMatchingPatients(String firstName, String lastName, String prefName, String birthDate, String facilityId, String phoneNumber, String nhisNumber, String motechId) { if (log.isDebugEnabled()) { log.debug("Get Matching Patients: " + firstName + ", " + lastName + ", " + prefName + ", " + birthDate + ", " + facilityId + ", " + phoneNumber + ", " + nhisNumber + ", " + motechId); }/*from w w w. j a v a2s .co m*/ List<WebPatient> resultList = new ArrayList<WebPatient>(); String datePattern = "dd/MM/yyyy"; SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern); dateFormat.setLenient(false); Date parsedBirthDate = null; try { parsedBirthDate = dateFormat.parse(birthDate); } catch (ParseException e) { } Integer parsedFacilityId = null; try { parsedFacilityId = Integer.parseInt(facilityId); } catch (NumberFormatException e) { } List<Patient> matchingPatients = contextService.getRegistrarBean().getDuplicatePatients(firstName, lastName, prefName, parsedBirthDate, parsedFacilityId, phoneNumber, nhisNumber, motechId); for (Patient patient : matchingPatients) { WebPatient webPatient = new WebPatient(); webModelConverter.patientToWeb(patient, webPatient); resultList.add(webPatient); } return resultList; }
From source file:DateValidator.java
/** * <p>Checks if the field is a valid date. The pattern is used with * <code>java.text.SimpleDateFormat</code>. If strict is true, then the * length will be checked so '2/12/1999' will not pass validation with * the format 'MM/dd/yyyy' because the month isn't two digits. * The setLenient method is set to <code>false</code> for all.</p> * * @param value The value validation is being performed on. * @param datePattern The pattern passed to <code>SimpleDateFormat</code>. * @param strict Whether or not to have an exact match of the datePattern. * @return true if the date is valid./*from w w w. j a va 2 s. co m*/ */ public boolean isValid(String value, String datePattern, boolean strict) { if (value == null || datePattern == null || datePattern.length() <= 0) { return false; } SimpleDateFormat formatter = new SimpleDateFormat(datePattern); formatter.setLenient(false); try { formatter.parse(value); } catch (ParseException e) { return false; } if (strict && (datePattern.length() != value.length())) { return false; } return true; }