List of usage examples for java.text SimpleDateFormat setLenient
public void setLenient(boolean lenient)
From source file:jp.co.ctc_g.jfw.core.util.Dates.java
/** * ??????????//from w w w . ja v a 2 s .com * {@link Date}???? * ?<code>null</code>??????????? * ???<code>null</code>???? * ?{@link SimpleDateFormat}???? * ?????????? * ?????????null???? * @param source ?? * @param pattern * @return ????{@link Date} */ public static Date makeFrom(String source, String pattern) { if (Strings.isEmpty(source) || Strings.isEmpty(pattern)) return null; SimpleDateFormat sdf = new SimpleDateFormat(pattern); sdf.setLenient(true); ParsePosition pos = new ParsePosition(0); Date date = sdf.parse(source, pos); if (pos.getErrorIndex() != -1 && L.isDebugEnabled()) { Map<String, Object> replace = new HashMap<String, Object>(3); replace.put("pattern", pattern); replace.put("index", pos.getErrorIndex() + 1); replace.put("target", source); L.debug(Strings.substitute(R.getString("D-UTIL#0002"), replace)); } return date; }
From source file:org.openTwoFactor.clientExt.net.sf.ezmorph.object.DateMorpher.java
public Object morph(Object value) { if (value == null) { return null; }//www.j a v a2s. c o m if (Date.class.isAssignableFrom(value.getClass())) { return (Date) value; } if (!supports(value.getClass())) { throw new MorphException(value.getClass() + " is not supported"); } String strValue = (String) value; SimpleDateFormat dateParser = null; for (int i = 0; i < formats.length; i++) { if (dateParser == null) { dateParser = new SimpleDateFormat(formats[i], locale); } else { dateParser.applyPattern(formats[i]); } dateParser.setLenient(lenient); try { return dateParser.parse(strValue.toLowerCase()); } catch (ParseException pe) { // ignore exception, try the next format } } // unable to parse the date if (isUseDefault()) { return defaultValue; } else { throw new MorphException("Unable to parse the date " + value); } }
From source file:org.opentaps.rest.ezmorph.TimestampMorpher.java
@Override public Object morph(Object value) { if (value == null) { return null; }// w ww . j a va 2s. c o m if (Timestamp.class.isAssignableFrom(value.getClass())) { return value; } if (!supports(value.getClass())) { throw new MorphException(value.getClass() + " is not supported"); } String strValue = (String) value; SimpleDateFormat dateParser = null; for (int i = 0; i < formats.length; i++) { if (dateParser == null) { dateParser = new SimpleDateFormat(formats[i], locale); } else { dateParser.applyPattern(formats[i]); } dateParser.setLenient(lenient); try { return new Timestamp(dateParser.parse(strValue.toLowerCase()).getTime()); } catch (ParseException pe) { // ignore exception, try the next format } } // unable to parse the date if (isUseDefault()) { return defaultValue; } else { throw new MorphException("Unable to parse the date " + value); } }
From source file:com.amazon.aws.samplecode.travellog.web.TravelLogController.java
@InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); dateFormat.setLenient(true); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }
From source file:au.org.intersect.dms.webapp.controller.LocationController.java
@InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }
From source file:org.pentaho.reporting.libraries.designtime.swing.date.TimeCellEditor.java
private DateFormat createDateFormat(final String parameterFormatString, final Locale locale, final TimeZone timeZone) { if (parameterFormatString != null) { try {// w w w . jav a2 s.com final SimpleDateFormat dateFormat = new SimpleDateFormat(parameterFormatString, new DateFormatSymbols(locale)); dateFormat.setTimeZone(timeZone); dateFormat.setLenient(true); return dateFormat; } catch (Exception e) { // boo! Not a valid pattern ... // its not a show-stopper either, as the pattern is a mere hint, not a mandatory thing logger.warn("Parameter format-string for date-parameter was not a valid date-format-string", e); } } final SimpleDateFormat dateFormat = new SimpleDateFormat(DEFAULT_FORMAT, new DateFormatSymbols(locale)); dateFormat.setTimeZone(timeZone); dateFormat.setLenient(true); return dateFormat; }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopTimeField.java
private Object validateRawValue(String value) throws NumberFormatException, ParseException { if (value.equals(StringUtils.replaceChars(mask, "#U", "__"))) { return null; }/* w w w.jav a2 s .c o m*/ SimpleDateFormat sdf = new SimpleDateFormat(timeFormat); sdf.setLenient(false); try { Date parsedValue = sdf.parse(value); Class targetType = null; if (datasource != null && metaPropertyPath != null) { targetType = metaPropertyPath.getRangeJavaClass(); } if (targetType == java.sql.Time.class) { return new Time(parsedValue.getTime()); } if (targetType == java.sql.Date.class) { log.warn("Do not use java.sql.Date with time field"); return new java.sql.Date(parsedValue.getTime()); } return parsedValue; } catch (ParseException e) { showValidationMessage(); return prevValue; } }
From source file:com.pax.pay.trans.action.activity.InputTransData2Activity.java
/** * //from w ww.j ava 2 s .c om */ private String process(EditText editText, EInputType inputType, int maxLen, int minLen) { String content = editText.getText().toString().trim(); if (content.length() == 0) { return null; } switch (inputType) { case DATE: if (content.length() != 4) { return ""; } SimpleDateFormat dateFormat = new SimpleDateFormat("MMdd"); try { dateFormat.setLenient(false); dateFormat.parse(content); } catch (Exception e) { return ""; } return content; case NUM: if (content.length() >= minLen && content.length() <= maxLen) { return content; } else { return ""; } case ALPHNUM: if (content.length() >= minLen && content.length() <= maxLen) { if (content.length() < maxLen) { int flag = maxLen1 - content.length(); for (int i = 0; i < flag; i++) { content = "0" + content; } } } else { return ""; } default: break; } return content; }
From source file:com.isomorphic.maven.mojo.AbstractPackagerMojo.java
/** * Provides some initialization and validation steps around the collection and transformation of an Isomorphic SDK. * /*from w w w . java 2 s . co m*/ * @throws MojoExecutionException When any fatal error occurs. * @throws MojoFailureException When any non-fatal error occurs. */ public void execute() throws MojoExecutionException, MojoFailureException { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); if (buildDate == null) { buildDate = dateFormat.format(new Date()); } try { dateFormat.parse(buildDate); } catch (ParseException e) { throw new MojoExecutionException( String.format("buildDate '%s' must take the form yyyy-MM-dd.", buildDate)); } LOGGER.debug("buildDate set to '{}'", buildDate); String buildNumberFormat = "\\d.*\\.\\d.*[d|p]"; if (!buildNumber.matches(buildNumberFormat)) { throw new MojoExecutionException( String.format("buildNumber '%s' must take the form [major].[minor].[d|p]. e.g., 4.1d", buildNumber, buildNumberFormat)); } File basedir = FileUtils.getFile(workdir, product.toString(), license.toString(), buildNumber, buildDate); //add optional modules to the list of downloads List<License> licenses = new ArrayList<License>(); licenses.add(license); if (license == POWER || license == ENTERPRISE) { if (includeAnalytics) { licenses.add(ANALYTICS_MODULE); } if (includeMessaging) { licenses.add(MESSAGING_MODULE); } } //collect the maven artifacts and send them along to the abstract method Set<Module> artifacts = collect(licenses, basedir); File bookmarkable = new File(basedir.getParent(), "latest"); LOGGER.info("Copying distribution to '{}'", bookmarkable.getAbsolutePath()); try { FileUtils.forceMkdir(bookmarkable); FileUtils.cleanDirectory(bookmarkable); FileUtils.copyDirectory(basedir, bookmarkable, FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter("zip"))); } catch (IOException e) { throw new MojoFailureException("Unable to copy distribution contents", e); } String[] executables = { "bat", "sh", "command" }; Collection<File> scripts = FileUtils.listFiles(basedir, executables, true); scripts.addAll(FileUtils.listFiles(bookmarkable, executables, true)); for (File script : scripts) { script.setExecutable(true); LOGGER.debug("Enabled execute permissions on file '{}'", script.getAbsolutePath()); } doExecute(artifacts); }
From source file:vn.jv.web.controller.UserDashboardController.java
@InitBinder protected void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat( vn.jv.constant.WebConstants.FixValue.DEFAULT_DATE_FORMAT); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); }