List of usage examples for java.util Calendar setLenient
public void setLenient(boolean lenient)
From source file:com.silverpeas.jcrutil.RandomGenerator.java
public static Calendar getOutdatedCalendar() { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_MONTH, -(1 + random.nextInt(10))); calendar.set(Calendar.HOUR_OF_DAY, getRandomHour()); calendar.set(Calendar.MINUTE, getRandomMinutes()); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); calendar.setLenient(false); try {//from w w w. j av a2 s . c o m calendar.getTime(); } catch (IllegalArgumentException ie) { return getOutdatedCalendar(); } return calendar; }
From source file:com.espertech.esper.schedule.ScheduleComputeHelper.java
private static boolean checkDayValidInMonth(int day, int month, int year) { try {/*from ww w .j ava2 s. c o m*/ 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:edu.psu.iam.cpr.core.api.helper.FindPersonHelper.java
/** * Convert a Date object into a Calendar object. * /*from www.j a v a2s . co m*/ * @param d The date to convert * @param lenient Should parsing be lenient * * @return a Calendar object */ public static final Calendar convertDateToCalendar(final Date d, final boolean lenient) { Calendar cal = Calendar.getInstance(Locale.US); cal.setLenient(lenient); cal.setTime(d); return cal; }
From source file:br.msf.commons.util.AbstractDateUtils.java
protected static Calendar addAge(final Object date, final Age age) { if (date == null) { return null; }/* www . j a v a 2 s .co m*/ final Calendar c = toUtcCalendar(date); c.setLenient(true); if (age != null) { c.add(Calendar.YEAR, age.getYears()); c.add(Calendar.MONTH, age.getMonths()); c.add(Calendar.DAY_OF_MONTH, age.getDays()); c.add(Calendar.HOUR_OF_DAY, age.getHours()); c.add(Calendar.MINUTE, age.getMinutes()); c.add(Calendar.SECOND, age.getSeconds()); c.add(Calendar.MILLISECOND, age.getMilliseconds()); } return c; }
From source file:com.silverpeas.jcrutil.RandomGenerator.java
public static Calendar getRandomCalendar() { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_MONTH, getRandomDay()); calendar.set(Calendar.MONTH, getRandomMonth()); calendar.set(Calendar.YEAR, getRandomYear()); calendar.set(Calendar.HOUR_OF_DAY, getRandomHour()); calendar.set(Calendar.MINUTE, getRandomMinutes()); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); calendar.setLenient(false); try {/* w w w. j a v a 2s. com*/ calendar.getTime(); } catch (IllegalArgumentException ie) { return getRandomCalendar(); } return calendar; }
From source file:com.aurel.track.report.dashboard.AverageTimeToCloseItem.java
/** * Created a regular time period/*from w w w. ja v a2 s. c o m*/ * @param period * @param year * @param timeInterval * @return */ public static Date createDate(int period, int year, int timeInterval) { Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.setLenient(true); calendar.set(Calendar.YEAR, year); switch (timeInterval) { case TIME_INTERVAL.DAY: calendar.set(Calendar.DAY_OF_YEAR, period); break; case TIME_INTERVAL.WEEK: calendar.set(Calendar.WEEK_OF_YEAR, period); break; default: calendar.set(Calendar.MONTH, period); } return calendar.getTime(); }
From source file:br.msf.commons.util.AbstractDateUtils.java
/** * Converte a data para {@link Calendar}. O argumento deve ser um {@link Date} ou {@link Calendar}. * <p/>//from w ww .j ava 2 s . c o m * Se date for do tipo Calendar, apenas retorna o cast: <code>return (Calendar) date</code>. * <p/> * Seno, retorna um <code>(new Calendar()).setTime((Date) date);</code> * * @param date O objeto a ser convertido. * @param assureLenient Indica se o Calendar retornado deve ter a propriedade "lenient" forada para "true". * @return O Calendar convertido de date. */ public static Calendar castToCalendar(final Object date, final boolean assureLenient) { if (date == null) { return null; } final Calendar c; if (isCalendar(date)) { c = (Calendar) date; } else if (isDate(date)) { c = Calendar.getInstance(); c.setTime((Date) date); } else { throw new IllegalArgumentException("Argument must be Date or Calendar"); } if (assureLenient) { c.setLenient(true); } return c; }
From source file:example.users.webservice.persistence.mock.UsersMockDao.java
private void initUsers() { Calendar calendar = new GregorianCalendar(); calendar.setLenient(false); calendar.set(1984, 1, 23);/* w w w . j av a2 s .com*/ try { User user1 = new User("Antonio", "Genovese", "Regist", calendar.getTime()); calendar.set(1981, 6, 25); User user2 = new User("Gianluca", "Genovese", "Gianblues", calendar.getTime()); calendar.set(2011, 7, 7); User user3 = new User("Gabriele", "Genovese", "Gaby", calendar.getTime()); this.users.add(user1); this.users.add(user2); this.users.add(user3); } catch (IllegalArgumentException ex) { logger.error("Exception Calendar " + ex.getMessage()); } }
From source file:com.tecapro.inventory.common.util.CheckUtil.java
public boolean isDate(int year, int month, int day) { Calendar cal = Calendar.getInstance(); cal.setLenient(false); cal.set(year, month - 1, day);/*from w w w . j av a2s . c om*/ try { cal.getTime(); } catch (IllegalArgumentException e) { return false; } return true; }
From source file:com.floreantpos.model.dao.TableBookingInfoDAO.java
public List getTodaysBooking() { Session session = null;//from w w w.j a v a2 s . c o m try { Calendar startDate = Calendar.getInstance(); startDate.setLenient(false); startDate.setTime(new Date()); startDate.set(Calendar.HOUR_OF_DAY, 0); startDate.set(Calendar.MINUTE, 0); startDate.set(Calendar.SECOND, 0); startDate.set(Calendar.MILLISECOND, 0); Calendar endDate = Calendar.getInstance(); endDate.setLenient(false); endDate.setTime(new Date()); endDate.set(Calendar.HOUR_OF_DAY, 23); endDate.set(Calendar.MINUTE, 59); endDate.set(Calendar.SECOND, 59); session = createNewSession(); Criteria criteria = session.createCriteria(TableBookingInfo.class); criteria.add(Restrictions.ge(TableBookingInfo.PROP_FROM_DATE, startDate.getTime())) .add(Restrictions.le(TableBookingInfo.PROP_FROM_DATE, endDate.getTime())) .add(Restrictions.eq(TableBookingInfo.PROP_STATUS, TableBookingInfo.STATUS_OPEN)); List list = criteria.list(); return list; } catch (Exception e) { PosLog.error(getClass(), e); } finally { session.close(); } return null; }