Example usage for org.apache.commons.lang3.time DateUtils truncate

List of usage examples for org.apache.commons.lang3.time DateUtils truncate

Introduction

In this page you can find the example usage for org.apache.commons.lang3.time DateUtils truncate.

Prototype

public static Date truncate(final Object date, final int field) 

Source Link

Document

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.

Usage

From source file:com.yukthi.validators.GreaterThanValidator.java

@Override
public boolean isValid(Object bean, Object fieldValue) {
    //obtain field value to be compared
    Object otherValue = null;/*from ww w  .  ja  v  a  2  s . c o m*/

    try {
        otherValue = PropertyUtils.getSimpleProperty(bean, greaterThanField);
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
        throw new IllegalStateException("Invalid/inaccessible property \"" + greaterThanField
                + "\" specified with matchWith validator in bean: " + bean.getClass().getName());
    }

    //if other value is null or of different 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.inkubator.hrm.service.impl.SchedulerConfigServiceImpl.java

@Override // Harus serialiasai agar tidak tumpang tindih dengan proses schedulerr yang berjalan
@Transactional(readOnly = false, isolation = Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void save(SchedulerConfig entity) throws Exception {
    long totalDuplicates = schedulerConfigDao.getTotalByName(entity.getName());
    if (totalDuplicates > 0) {
        throw new BussinessException("scheduler_config.error_name");
    }/*from   w w  w. ja  v a2s  .  co  m*/
    entity.setId(Long.parseLong(RandomNumberUtil.getRandomNumber(12)));
    entity.setCreatedBy(UserInfoUtil.getUserName());
    entity.setCretedOn(new Date());
    if (entity.getIsTimeDiv()) {
        Date now = new Date();
        String nowString = new SimpleDateFormat("dd MM yyyy HH:mm").format(now);
        //            entity.setLastExecution(new SimpleDateFormat("dd MM yyyy HH:mm").parse(nowString));
        entity.setLastExecution(DateUtils.truncate(now, Calendar.MINUTE));
    }
    schedulerConfigDao.save(entity);
}

From source file:cvr.vist.stat.comps.DateFilterArea.java

public Date getDateBegin() {

    return DateUtils.truncate(dateFrom.getValue(), Calendar.DATE);
}

From source file:com.inkubator.hrm.web.HomeController.java

@PostConstruct
@Override/*w w w  .ja  v a  2  s .  c  o  m*/
public void initialization() {
    super.initialization();
    //        Collection<SimpleGrantedAuthority> authorities = (Collection<SimpleGrantedAuthority>)    SecurityContextHolder.getContext().getAuthentication().getAuthorities();
    //        String role = authorities.toString();
    //        role = role.replace("[", "");
    //        role = role.replace("]", "");
    roleUser = HrmUserInfoUtil.getRolesString();
    roleUser = StringUtils.substringBefore(roleUser, ",");
    /**
     * saving process of User Access History
     */
    StringBuffer urlPath = FacesUtil.getRequest().getRequestURL();
    RiwayatAkses akses = new RiwayatAkses();
    akses.setDateAccess(new Date());
    akses.setPathUrl(urlPath.toString());
    akses.setUserId(UserInfoUtil.getUserName());
    akses.setContextPath(FacesUtil.getRequest().getContextPath());
    //        if (!FacesContext.getCurrentInstance().isPostback()) {
    //            RequestContext.getCurrentInstance().execute("bar.show()");
    //        }

    try {
        riwayatAksesService.doSaveAccess(akses);
    } catch (Exception ex) {
        LOGGER.error("Error when saving User Access History", ex);
    }

    /**
     * do checking announcement web view
     */
    try {
        Long empDataId = HrmUserInfoUtil.getEmpId();
        Date planExecutionDate = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH);
        announcementLog = announcementLogService.getEntityWebView(empDataId, planExecutionDate);
        isRenderAnnouncement = announcementLog != null;
    } catch (Exception ex) {
        LOGGER.error(ex, ex);
    }
}

From source file:cvr.vist.stat.comps.DateFilterArea.java

public Date getDateEnd() {
    return DateUtils.truncate(dateTo.getValue(), Calendar.DATE);
}

From source file:gov.va.isaac.gui.listview.operations.UscrsExportOperation.java

/**
 * Pass in a Date and the function will return a Date, but at the start of that day.
 * @param Date the day and time you would like to modify
 * @return Date and time at the beginning of the day
 *//*  w  w w .ja  va 2  s.  co m*/
public static Date getStartOfDay(Date date) {
    return DateUtils.truncate(date, Calendar.DATE);
}

From source file:io.apiman.test.integration.rest.apis.metrics.AbstractIntervalMetricsIT.java

@Test
public void shouldHaveCorrectLabelOnFirstSubinterval() throws Exception {
    HistogramBean<HistogramDataPoint> metrics = getMetrics();
    Date firstSubinterval = formatter.parse(metrics.getData().get(0).getLabel());

    assertEquals("Unexpected label value of first subinterval",
            DateUtils.truncate(beforeRecoding, Calendar.MINUTE), firstSubinterval);
}

From source file:com.webbfontaine.valuewebb.model.util.Utils.java

public static Date getTomorrowDate() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, 1); //For tomorrow

    return DateUtils.truncate(calendar.getTime(), Calendar.DATE);
}

From source file:io.lavagna.service.StatisticsServiceTest.java

@Before
public void prepare() {
    Helper.createUser(userRepository, "test", "test-user");
    user = userRepository.findUserByName("test", "test-user");
    Project p = projectService.create("test", "TEST", "desc");
    board = boardRepository.createNewBoard("test-board", "TEST-BRD", null, p.getId());
    List<BoardColumnDefinition> definitions = projectService
            .findColumnDefinitionsByProjectId(projectService.findByShortName("TEST").getId());

    for (BoardColumnDefinition def : definitions) {
        if (def.getValue() == ColumnDefinition.OPEN) {
            openCol = boardColumnRepository.addColumnToBoard("col1", def.getId(),
                    BoardColumn.BoardColumnLocation.BOARD, board.getId());
        }// w ww  .  j  a v a 2s.  c  om
    }

    today = DateUtils.truncate(new Date(), Calendar.DATE);
    yesterday = DateUtils.addDays(today, -1);
    oneMonthAgo = DateUtils.addMonths(today, -1);

    lastSnapshot = DateUtils.addYears(today, -10);

    card = cardService.createCard("card1", openCol.getId(), today, user);

    assigned = cardLabelRepository.findLabelByName(p.getId(), "ASSIGNED", CardLabel.LabelDomain.SYSTEM);
    customLabel = cardLabelRepository.addLabel(p.getId(), true, CardLabel.LabelType.USER,
            CardLabel.LabelDomain.USER, "Custom label", 0);
    labelValueToUser = new CardLabelValue.LabelValue(null, null, null, null, user.getId(), null);
}

From source file:io.apiman.test.integration.rest.apis.metrics.AbstractIntervalMetricsIT.java

@Test
public void shouldHaveCorrectLabelOnLastSubinterval() throws Exception {
    HistogramBean<HistogramDataPoint> metrics = getMetrics();
    int last = metrics.getData().size() - 1;
    Date lastSubinterval = formatter.parse(metrics.getData().get(last).getLabel());

    assertEquals("Unexpected label value of last subinterval",
            DateUtils.truncate(tenMinutesAfterRecording, Calendar.MINUTE), lastSubinterval);
}