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

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

Introduction

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

Prototype

public static Date addDays(final Date date, final int amount) 

Source Link

Document

Adds a number of days to a date returning a new object.

Usage

From source file:com.mtt.myapp.home.model.PanelEntry.java

public boolean isNew() {
    return DateUtils.addDays(lastUpdatedDate, NEW_LIMIT).compareTo(new Date()) > 0;
}

From source file:com.alibaba.utils.date.CommonDateUtils.java

/**
 * <pre>//from   w  ww  .  ja  va 2 s . com
 * 
 * 
 * 2013.09.20,2
 * 2013.09.20 2013.09.21 2013.09.22
 * </pre>
 * @param currentDate
 * @param days
 * @return
 */
public static List<Date> afterCurrentDate(Date currentDate, int days) {
    List<Date> dateList = new ArrayList<Date>();
    // 0. 
    if (currentDate == null) {
        return null;
    }
    if (days <= 0) {
        dateList.add(DateUtils.truncate(currentDate, Calendar.DAY_OF_MONTH));
        return dateList;
    }

    // 1. 
    Date startDate = new Date(currentDate.getTime());
    for (int i = 0; i <= days; ++i) {
        Date date = DateUtils.addDays(startDate, i);
        dateList.add(DateUtils.truncate(date, Calendar.DAY_OF_MONTH));
    }

    return dateList;
}

From source file:com.dominion.salud.mpr.negocio.repositories.integracion.impl.BuzonInHisRepositoryImpl.java

public List<BuzonInHis> findAllByAntiguedad() {
    Date antiguedad = DateUtils.addDays(new Date(), (MPRConstantes._TASK_BUZON_IN_HIS_CLEAN_OLD * -1));

    return entityManager.createQuery("from BuzonInHis where fechaIn < :fechaIn", BuzonInHis.class)
            .setParameter("fechaIn", antiguedad).getResultList();
}

From source file:com.dominion.salud.mpr.negocio.repositories.integracion.impl.BuzonOutHisRepositoryImpl.java

public List<BuzonOutHis> findAllByAntiguedad() {
    Date antiguedad = DateUtils.addDays(new Date(), (MPRConstantes._TASK_BUZON_OUT_HIS_CLEAN_OLD * -1));

    return entityManager.createQuery("from BuzonOutHis where fechaOut < :fechaOut", BuzonOutHis.class)
            .setParameter("fechaOut", antiguedad).getResultList();
}

From source file:io.github.benas.randombeans.randomizers.DateRangeRandomizerTest.java

@Before
public void setUp() {
    today = new Date();
    tomorrow = DateUtils.addDays(today, 1);
    randomizer = new DateRangeRandomizer(today, tomorrow);
}

From source file:com.bjond.utilities.DateTimeUtils.java

/**
 * Returns 11:59:59.999 PM tomorrow of date.
 *
 * @param date Valid non-null java.util.Date object
 * @return New date. Original is not altered.
 *//*w ww  .  j  ava  2  s.c om*/
public static Date tomorrow(final Date date) {
    return getEndOfDay(DateUtils.addDays(date, 1));
}

From source file:com.bjond.utilities.DateTimeUtils.java

/**
 * Returns 00:01:01.000 yesterday.// ww w .  j  a  va2 s .  co m
 *
 * @param date Valid non-null java.util.Date object
 * @return New date. Original is not altered.
 */
public static Date yesterday(final Date date) {
    return getStartOfDay(DateUtils.addDays(date, -1));
}

From source file:com.daphne.es.personal.calendar.web.controller.CalendarController.java

@RequestMapping("/load")
@ResponseBody//  w w w  .ja  v  a2 s  .  co  m
public Collection<Map> ajaxLoad(Searchable searchable, @CurrentUser User loginUser) {
    searchable.addSearchParam("userId_eq", loginUser.getId());
    List<Calendar> calendarList = calendarService.findAllWithNoPageNoSort(searchable);

    return Lists.<Calendar, Map>transform(calendarList, new Function<Calendar, Map>() {
        @Override
        public Map apply(Calendar c) {
            Map<String, Object> m = Maps.newHashMap();

            Date startDate = new Date(c.getStartDate().getTime());
            Date endDate = DateUtils.addDays(startDate, c.getLength() - 1);
            boolean allDays = c.getStartTime() == null && c.getEndTime() == null;

            if (!allDays) {
                startDate.setHours(c.getStartTime().getHours());
                startDate.setMinutes(c.getStartTime().getMinutes());
                startDate.setSeconds(c.getStartTime().getSeconds());
                endDate.setHours(c.getEndTime().getHours());
                endDate.setMinutes(c.getEndTime().getMinutes());
                endDate.setSeconds(c.getEndTime().getSeconds());
            }

            m.put("id", c.getId());
            m.put("start", DateFormatUtils.format(startDate, "yyyy-MM-dd HH:mm:ss"));
            m.put("end", DateFormatUtils.format(endDate, "yyyy-MM-dd HH:mm:ss"));
            m.put("allDay", allDays);
            m.put("title", c.getTitle());
            m.put("details", c.getDetails());
            if (StringUtils.isNotEmpty(c.getBackgroundColor())) {
                m.put("backgroundColor", c.getBackgroundColor());
                m.put("borderColor", c.getBackgroundColor());
            }
            if (StringUtils.isNotEmpty(c.getTextColor())) {
                m.put("textColor", c.getTextColor());
            }
            return m;
        }
    });
}

From source file:com.galaxy.service.user.ShiroDbRealm.java

/**
 * ?,./*  w w  w.j a v a2  s.  c  om*/
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
        throws AuthenticationException {
    UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
    User user = userService.findUserByLoginName(token.getUsername());
    if (user != null) {
        byte[] salt = Encodes.decodeHex(user.getSalt());
        LoginUserModel loginUser = new LoginUserModel();
        loginUser.setEmail(user.getEmail());
        loginUser.setLoginName(token.getUsername());
        loginUser.setMobile(user.getMobile());
        loginUser.setNickName(user.getNick());
        loginUser.setUserId(user.getId());
        loginUser.setAvatar(user.getAvatar());
        loginUser.setToken(tokenService.generateToken());
        loginUser.setExpiredToken(tokenService.generateToken());
        loginUser.setExpireshIn(DateUtils.addDays(new Date(), 30).getTime());
        return new SimpleAuthenticationInfo(loginUser, user.getPassword(), ByteSource.Util.bytes(salt),
                getName());
    } else {
        return null;
    }
}

From source file:love.sola.netsupport.api.stuff.TicketLog.java

@SuppressWarnings("unchecked")
@Override//from w w w. ja va 2s.com
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
    int first;
    int limit;
    Date start;
    Date end;
    first = req.getParameter("first") == null ? 0 : Integer.parseInt(req.getParameter("first"));
    limit = req.getParameter("limit") == null ? 20 : Integer.parseInt(req.getParameter("limit"));
    start = req.getParameter("start") == null ? getToday() : dateFormat.parse(req.getParameter("start"));
    end = req.getParameter("end") == null ? getToday() : dateFormat.parse(req.getParameter("end"));
    end = DateUtils.addDays(end, 1);
    try (Session s = SQLCore.sf.openSession()) {
        AuditReader reader = TableTicket.getAuditReader(s);
        List<Object[]> resultList = reader.createQuery().forRevisionsOfEntity(Ticket.class, false, true)
                .addOrder(AuditEntity.revisionNumber().desc())
                .add(AuditEntity.revisionProperty("timestamp").between(start.getTime(), end.getTime()))
                .setFirstResult(first).setMaxResults(limit).getResultList();
        return TableTicket.initializeTickets(resultList);
    }
}