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:org.mifos.framework.util.helpers.DateUtils.java

/**
 * "as sent from browser" is a bit of a misnomer; it really is (at least in
 * many cases), as formatted by a routine on the server side like
 * ClientCustActionForm#getDateOfBirth()
 *
 * @throws InvalidDateException//from  ww  w  . j av a2s.  c  o m
 */
public static java.sql.Date getDateAsSentFromBrowser(String value) throws InvalidDateException {
    if (value == null || value == "") {
        return null;
    }
    try {
        String formatStr = "d" + dateSeparator + "M" + dateSeparator + "yy";
        SimpleDateFormat format = new SimpleDateFormat(formatStr, internalLocale);

        format.setLenient(false);
        return new java.sql.Date(format.parse(value).getTime());
    }

    catch (ParseException e) {
        throw new InvalidDateException(value);
    }
}

From source file:org.mifos.framework.util.helpers.DateUtils.java

public static Date parseDate(String dateStr) throws ParseException {
    SimpleDateFormat dateFormat = new SimpleDateFormat(getShortDateFormat(dateLocale), dateLocale);
    dateFormat.setLenient(false);
    return dateFormat.parse(dateStr);
}

From source file:org.mifos.framework.util.helpers.DateUtils.java

public static String formatDate(Date date) {
    SimpleDateFormat dateFormat = new SimpleDateFormat(getShortDateFormat(dateLocale), dateLocale);
    dateFormat.setLenient(false);
    return dateFormat.format(date);
}

From source file:org.mifos.framework.util.helpers.DateUtils.java

public static java.sql.Date getLocaleDate(Locale locale, String value) throws InvalidDateException {
    // the following line is for 1.1 release and will be removed when date
    // is localized
    locale = internalLocale;/*from w w  w.  ja v  a 2  s .  c om*/
    java.sql.Date result = null;
    if (locale != null && StringUtils.isNotBlank(value)) {
        SimpleDateFormat shortFormat = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, locale);
        shortFormat.setLenient(false);
        String userPattern = shortFormat.toPattern();
        String dbDate = convertUserToDbFmt(value, userPattern);
        result = java.sql.Date.valueOf(dbDate);
    }
    return result;
}

From source file:adalid.commons.util.TimeUtils.java

private static SimpleDateFormat dateFormatter() {
    SimpleDateFormat formatter = dateFormatter.get();
    if (formatter == null) {
        formatter = new SimpleDateFormat(getDateFormat());
        formatter.setLenient(false);
        dateFormatter.set(formatter);/*from  www  .  java  2 s  .  co  m*/
    }
    return formatter;
}

From source file:adalid.commons.util.TimeUtils.java

private static SimpleDateFormat timeFormatter() {
    SimpleDateFormat formatter = timeFormatter.get();
    if (formatter == null) {
        formatter = new SimpleDateFormat(getTimeFormat());
        formatter.setLenient(false);
        timeFormatter.set(formatter);//ww  w  .  java2 s  . co m
    }
    return formatter;
}

From source file:adalid.commons.util.TimeUtils.java

private static SimpleDateFormat timestampFormatter() {
    SimpleDateFormat formatter = timestampFormatter.get();
    if (formatter == null) {
        formatter = new SimpleDateFormat(getTimestampFormat());
        formatter.setLenient(false);
        timestampFormatter.set(formatter);
    }/*from ww w  .  j a  va  2 s  .com*/
    return formatter;
}

From source file:org.mifos.framework.util.helpers.DateUtils.java

public static boolean isValidDate(String value) {
    try {//w  w  w . ja v  a  2s  . co m
        SimpleDateFormat shortFormat = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT,
                internalLocale);
        shortFormat.setLenient(false);
        shortFormat.parse(value);
        return true;
    }

    catch (java.text.ParseException e) {
        return false;
    }
}

From source file:us.mn.state.health.lims.common.util.DateUtil.java

public static synchronized int decodeTime(String s) throws Exception {
    SimpleDateFormat f = new SimpleDateFormat("HH:mm:ss");
    // System.out.println("Passed in this time " +s);
    TimeZone utcTimeZone = TimeZone.getTimeZone("UTC");
    f.setTimeZone(utcTimeZone);//from   ww  w  .  java 2  s . c  o m
    f.setLenient(false);
    ParsePosition p = new ParsePosition(0);
    Date d = f.parse(s, p);
    if (d == null || !StringUtil.isRestOfStringBlank(s, p.getIndex())) {
        throw new Exception("Invalid time value (hh:mm:ss): \"" + s + "\".");
    }
    return (int) d.getTime();
}

From source file:org.mifos.framework.util.helpers.DateUtils.java

public static java.sql.Date getLocaleDate(String value) {
    if (internalLocale != null && value != null && !value.equals("")) {
        try {//www .j  a  v  a 2  s  . com
            SimpleDateFormat shortFormat = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT,
                    internalLocale);
            shortFormat.setLenient(false);
            String userPattern = shortFormat.toPattern();
            String dbDate = convertUserToDbFmt(value, userPattern);
            return java.sql.Date.valueOf(dbDate);
        } catch (RuntimeException alreadyRuntime) {
            throw alreadyRuntime;
        } catch (Exception e) {
            throw new FrameworkRuntimeException(e);
        }
    } else {
        return null;
    }
}