List of usage examples for org.apache.commons.lang3.time DateUtils truncate
public static Date truncate(final Object date, final int field)
Truncates a date, leaving the field specified as the most significant field.
For example, if you had the date-time of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 13:00:00.000.
From source file:de.tor.tribes.ui.components.DatePicker.java
/** * Creates new form DatePicker/* w w w . j a v a2 s . com*/ */ public DatePicker() { initComponents(); originalDate = DateUtils.truncate(new Date(), Calendar.DATE); selectedDate = originalDate; init(); }
From source file:com.yukthi.validators.FutureOrTodayValidator.java
@Override public boolean isValid(Date targetDate, ConstraintValidatorContext context) { //if target date is not present, ignore validator if (targetDate == null) { return true; }/* w w w . j a va 2 s .com*/ //compare target date with today Date today = DateUtils.truncate(new Date(), Calendar.DATE); targetDate = DateUtils.truncate(targetDate, Calendar.DATE); return (targetDate.compareTo(today) >= 0); }
From source file:com.u2apple.tool.dao.AndroidDeviceDaoImpl.java
@Override public List<AndroidDeviceRanking> getUnidentifiedDevicesOfRootSpirit(int days) throws IOException, JSchException { SqlSession sqlSession = MyBatisHelper.getRootSqlSessionFactory().openSession(); RootDeviceMapper mapper = sqlSession.getMapper(RootDeviceMapper.class); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_MONTH, -days); calendar = DateUtils.truncate(calendar, Calendar.DATE); return mapper.selectUnidentifiedDevices(SqlUtils.getMonthlyTable("log_root_solution"), calendar.getTime()); }
From source file:de.fischer.thotti.reportgen.combiner.MedianIterator.java
@Override DatePoint getNextElementComputed() {// w ww. j a va2s . co m double medianValue; int numOfValues = elements.size(); int remainder = numOfValues % 2; int idxFirstElementAboveMedian = ((numOfValues - remainder) / 2) - 1 - 1 /* Adjustment for 0 based index of collections. */; System.out.println("E: " + elements.size()); System.out.println("R: " + remainder); Iterator<NDResultEntity> itr = elements.iterator(); for (int index = 0; index <= idxFirstElementAboveMedian; index++) { itr.next(); } NDResultEntity firstAboveMedian = itr.next(); double executionTimeA = firstAboveMedian.getExecutionTime(); if (numOfValues == 1) { medianValue = executionTimeA; } else { NDResultEntity firstBelowMedian = itr.next(); double executionTimeB = firstBelowMedian.getExecutionTime(); medianValue = (executionTimeA + executionTimeB) / 2; } DatePoint result = new DatePoint(); Date date = DateUtils.truncate(firstAboveMedian.getStartedAt(), Calendar.DAY_OF_MONTH); result.setPointInTime(date); result.setValue(medianValue); return result; }
From source file:de.tor.tribes.ui.components.DatePicker.java
public DatePicker(Date date) { initComponents();//from ww w. j ava 2 s .co m if (date == null) { originalDate = DateUtils.truncate(new Date(), Calendar.DATE); } else { originalDate = DateUtils.truncate(date, Calendar.DATE); } selectedDate = originalDate; init(); }
From source file:com.feilong.core.date.DateUtilTest.java
/** * Test get first date of this day./* w w w.j a v a 2s . co m*/ */ @Test public void testGetFirstDateOfThisDay() { logDate(DateUtil.getFirstDateOfThisDay(NOW)); logDate(DateUtils.truncate(NOW, Calendar.DAY_OF_MONTH)); }
From source file:com.feilong.core.date.DateUtilTest.java
/** * Test get last date of this day./*from ww w .j a va 2 s . c om*/ */ @Test public void testGetLastDateOfThisDay() { logDate(DateUtil.getLastDateOfThisDay(NOW)); LOGGER.debug(StringUtils.repeat("*", 20)); logDate(DateUtils.ceiling(NOW, Calendar.DAY_OF_MONTH)); logDate(DateUtils.round(NOW, Calendar.DAY_OF_MONTH)); logDate(DateUtils.truncate(NOW, Calendar.DAY_OF_MONTH)); LOGGER.debug(StringUtils.repeat("*", 20)); logDate(DateUtils.ceiling(NOW, Calendar.MONTH)); logDate(DateUtils.round(NOW, Calendar.MONTH)); logDate(DateUtils.truncate(NOW, Calendar.MONTH)); }
From source file:com.yukthi.validators.LessThanValidator.java
@Override public boolean isValid(Object bean, Object fieldValue) { Object otherValue = null;//from w w w . jav a 2s . c o m try { otherValue = PropertyUtils.getSimpleProperty(bean, lessThanField); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { throw new IllegalStateException("Invalid/inaccessible property \"" + lessThanField + "\" specified with matchWith validator in bean: " + bean.getClass().getName()); } if (fieldValue == null || otherValue == null || !fieldValue.getClass().equals(otherValue.getClass())) { return true; } if (otherValue instanceof Number) { return (((Number) fieldValue).doubleValue() < ((Number) otherValue).doubleValue()); } if (otherValue instanceof Date) { Date dateValue = DateUtils.truncate((Date) fieldValue, Calendar.DATE); Date otherDateValue = DateUtils.truncate((Date) otherValue, Calendar.DATE); return (dateValue.compareTo(otherDateValue) < 0); } return true; }
From source file:com.yukthi.validators.GreaterThanEqualsValidator.java
@Override public boolean isValid(Object bean, Object fieldValue) { if (bean == null) { return true; }/*from w w w . j ava2 s . co m*/ //fetch other field value Object otherValue = null; try { otherValue = PropertyUtils.getProperty(bean, greaterThanField); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { throw new IllegalStateException("Invalid/inaccessible property \"" + greaterThanField + "\" specified with matchWith validator in bean: " + bean.getClass().getName()); } //ensure other field value is present and is of same type if (fieldValue == null || otherValue == null || !fieldValue.getClass().equals(otherValue.getClass())) { return true; } //number comparison if (otherValue instanceof Number) { return (((Number) fieldValue).doubleValue() >= ((Number) otherValue).doubleValue()); } //date comparison if (otherValue instanceof Date) { Date dateValue = DateUtils.truncate((Date) fieldValue, Calendar.DATE); Date otherDateValue = DateUtils.truncate((Date) otherValue, Calendar.DATE); return (dateValue.compareTo(otherDateValue) >= 0); } return true; }
From source file:com.yukthi.validators.LessThanEqualsValidator.java
@Override public boolean isValid(Object bean, Object fieldValue) { //fetch other field value Object otherValue = null;/*from w w w .ja va 2 s. c o m*/ try { otherValue = PropertyUtils.getSimpleProperty(bean, lessThanField); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { throw new IllegalStateException("Invalid/inaccessible property \"" + lessThanField + "\" specified with matchWith validator in bean: " + bean.getClass().getName()); } //if value is null or of different data type if (fieldValue == null || otherValue == null || !fieldValue.getClass().equals(otherValue.getClass())) { return true; } //number comparison if (otherValue instanceof Number) { return (((Number) fieldValue).doubleValue() <= ((Number) otherValue).doubleValue()); } //date comparison if (otherValue instanceof Date) { Date dateValue = DateUtils.truncate((Date) fieldValue, Calendar.DATE); Date otherDateValue = DateUtils.truncate((Date) otherValue, Calendar.DATE); return (dateValue.compareTo(otherDateValue) <= 0); } return true; }