Example usage for java.util Calendar setLenient

List of usage examples for java.util Calendar setLenient

Introduction

In this page you can find the example usage for java.util Calendar setLenient.

Prototype

public void setLenient(boolean lenient) 

Source Link

Document

Specifies whether or not date/time interpretation is to be lenient.

Usage

From source file:jp.co.ctc_g.jfw.core.util.Dates.java

/**
 * ????//from  ww w. ja  v  a  2  s.  c o m
 * @param date ??
 * @return ??
 */
public static Date nextMonth(Date date) {
    if (date == null)
        return null;
    Calendar calendar = Calendar.getInstance();
    calendar.setLenient(true);
    calendar.setTime(date);
    calendar.add(Calendar.MONTH, 1);
    return calendar.getTime();
}

From source file:jp.co.ctc_g.jfw.core.util.Dates.java

/**
 * ????//from   www.j  av a 2s  . c  o m
 * @param date ??
 * @return ??
 */
public static Date nextDay(Date date) {
    if (date == null)
        return null;
    Calendar calendar = Calendar.getInstance();
    calendar.setLenient(true);
    calendar.setTime(date);
    calendar.add(Calendar.DAY_OF_MONTH, 1);
    return calendar.getTime();
}

From source file:jp.co.ctc_g.jfw.core.util.Dates.java

/**
 * ?????/*from  w  w  w  . j av  a  2 s  .  c om*/
 * @param date ??
 * @return ??
 */
public static Date previousYear(Date date) {
    if (date == null)
        return null;
    Calendar calendar = Calendar.getInstance();
    calendar.setLenient(true);
    calendar.setTime(date);
    calendar.add(Calendar.YEAR, -1);
    return calendar.getTime();
}

From source file:jp.co.ctc_g.jfw.core.util.Dates.java

/**
 * ?????//from www  .j  a  v a  2s.  c om
 * @param date ??
 * @return ??
 */
public static Date previousMonth(Date date) {
    if (date == null)
        return null;
    Calendar calendar = Calendar.getInstance();
    calendar.setLenient(true);
    calendar.setTime(date);
    calendar.add(Calendar.MONTH, -1);
    return calendar.getTime();
}

From source file:jp.co.ctc_g.jfw.core.util.Dates.java

/**
 * ?????/*from w  w w .ja v a  2  s . c  o  m*/
 * @param date ??
 * @return ??
 */
public static Date previousDay(Date date) {
    if (date == null)
        return null;
    Calendar calendar = Calendar.getInstance();
    calendar.setLenient(true);
    calendar.setTime(date);
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    return calendar.getTime();
}

From source file:jp.co.ctc_g.jfw.core.util.Dates.java

/**
 * ?????????/* w ww  .j  a va  2  s.  c om*/
 * @param date ??
 * @return ?????
 */
public static int lastDay(Date date) {
    if (date == null)
        return -1;
    Calendar calendar = Calendar.getInstance();
    calendar.setLenient(true);
    calendar.setTime(date);
    calendar.add(Calendar.MONTH, 1);
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    return calendar.get(Calendar.DAY_OF_MONTH);
}

From source file:com.espertech.esper.regression.pattern.TestCronParameter.java

private boolean checkDayValidInMonth(int day, int month, int year) {
    try {/*  w  w w .ja  va  2 s .c om*/
        Calendar calendar = Calendar.getInstance();
        calendar.setLenient(false);
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month);
        calendar.set(Calendar.DAY_OF_MONTH, day);
        calendar.getTime();
    } catch (IllegalArgumentException e) {
        return false;
    }
    return true;
}

From source file:com.examples.with.different.packagename.testcarver.DateTimeConverter.java

/**
 * Convert a long value to the specified Date type for this
 * <i>Converter</i>.// w ww  . j av  a 2 s .c o  m
 * <p>
 *
 * This method handles conversion to the following types:
 * <ul>
 *     <li><code>java.util.Date</code></li>
 *     <li><code>java.util.Calendar</code></li>
 *     <li><code>java.sql.Date</code></li>
 *     <li><code>java.sql.Time</code></li>
 *     <li><code>java.sql.Timestamp</code></li>
 * </ul>
 *
 * @param type The Date type to convert to
 * @param value The long value to convert.
 * @return The converted date value.
 */
private Object toDate(Class type, long value) {

    // java.util.Date
    if (type.equals(Date.class)) {
        return new Date(value);
    }

    // java.sql.Date
    if (type.equals(java.sql.Date.class)) {
        return new java.sql.Date(value);
    }

    // java.sql.Time
    if (type.equals(java.sql.Time.class)) {
        return new java.sql.Time(value);
    }

    // java.sql.Timestamp
    if (type.equals(java.sql.Timestamp.class)) {
        return new java.sql.Timestamp(value);
    }

    // java.util.Calendar
    if (type.equals(Calendar.class)) {
        Calendar calendar = null;
        if (locale == null && timeZone == null) {
            calendar = Calendar.getInstance();
        } else if (locale == null) {
            calendar = Calendar.getInstance(timeZone);
        } else if (timeZone == null) {
            calendar = Calendar.getInstance(locale);
        } else {
            calendar = Calendar.getInstance(timeZone, locale);
        }
        calendar.setTime(new Date(value));
        calendar.setLenient(false);
        return calendar;
    }

    String msg = toString(getClass()) + " cannot handle conversion to '" + toString(type) + "'";
    throw new ConversionException(msg);
}

From source file:javadz.beanutils.converters.DateTimeConverter.java

/**
 * Convert a long value to the specified Date type for this
 * <i>Converter</i>./*from   w w  w .  j a  v  a  2s  . c o  m*/
 * <p>
 *
 * This method handles conversion to the following types:
 * <ul>
 *     <li><code>java.util.Date</code></li>
 *     <li><code>java.util.Calendar</code></li>
 *     <li><code>java.sql.Date</code></li>
 *     <li><code>java.sql.Time</code></li>
 *     <li><code>java.sql.Timestamp</code></li>
 * </ul>
 *
 * @param type The Date type to convert to
 * @param value The long value to convert.
 * @return The converted date value.
 */
private Object toDate(Class type, long value) {

    // java.util.Date
    if (type.equals(Date.class)) {
        return new Date(value);
    }

    // java.sql.Date
    if (type.equals(java.sql.Date.class)) {
        return new java.sql.Date(value);
    }

    // java.sql.Time
    if (type.equals(java.sql.Time.class)) {
        return new java.sql.Time(value);
    }

    // java.sql.Timestamp
    if (type.equals(java.sql.Timestamp.class)) {
        return new java.sql.Timestamp(value);
    }

    // java.util.Calendar
    if (type.equals(Calendar.class)) {
        Calendar calendar = null;
        if (locale == null && timeZone == null) {
            calendar = Calendar.getInstance();
        } else if (locale == null) {
            calendar = Calendar.getInstance(timeZone);
        } else if (timeZone == null) {
            calendar = Calendar.getInstance(locale);
        } else {
            calendar = Calendar.getInstance(timeZone, locale);
        }
        calendar.setTime(new Date(value));
        calendar.setLenient(false);
        return calendar;
    }

    String msg = toString(getClass()) + " cannot handle conversion to '" + toString(type) + "'";
    if (log().isWarnEnabled()) {
        log().warn("    " + msg);
    }
    throw new ConversionException(msg);
}

From source file:com.all.login.view.NewAccountFormPanel.java

void validateDate() {
    Date date = getUser().getBirthday();

    if (date == null) {
        date = new Date();
    }/*from  w w  w  .ja  v  a2  s .c  o  m*/

    if (month >= 0 && day > 0 && year > 0) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.MONTH, month);
        c.set(Calendar.DAY_OF_MONTH, day);
        c.set(Calendar.YEAR, year);
        c.setLenient(false); // this validates the date
        // TODO manage valid date exception
        date.setTime(c.getTimeInMillis());
        getUser().setBirthday(date);
        // TODO: remove this comment after we decide to add mediagraphics info
        // validateAllUserData();
        // end TODO
    } else {
        getUser().setBirthday(null);
    }

}