Example usage for org.apache.commons.lang.time DateUtils addMinutes

List of usage examples for org.apache.commons.lang.time DateUtils addMinutes

Introduction

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

Prototype

public static Date addMinutes(Date date, int amount) 

Source Link

Document

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

Usage

From source file:org.jasig.schedassist.web.VisibleScheduleTag.java

@Override
public int doStartTagInternal() {
    final ServletContext servletContext = pageContext.getServletContext();

    final Date scheduleStart = visibleSchedule.getScheduleStart();
    if (null == scheduleStart) {
        // the visibleSchedule is empty, short circuit
        try {//from ww  w  .  j  a  v  a 2  s .  c  om
            StringBuilder noappointments = new StringBuilder();
            noappointments.append("<span class=\"none-available\">");
            noappointments.append(getMessageSource().getMessage("no.available.appointments", null, null));
            noappointments.append("</span>");
            pageContext.getOut().write(noappointments.toString());
        } catch (IOException e) {
            LOG.error("IOException occurred in doStartTag", e);
        }
        // SKIP_BODY means don't print any content from body of tag
        return SKIP_BODY;
    }

    LOG.debug("scheduleStart: " + scheduleStart);
    SortedMap<Date, List<AvailableBlock>> dailySchedules = new TreeMap<Date, List<AvailableBlock>>();
    Date index = DateUtils.truncate(scheduleStart, java.util.Calendar.DATE);
    Date scheduleEnd = visibleSchedule.getScheduleEnd();
    while (index.before(scheduleEnd)) {
        dailySchedules.put(index, new ArrayList<AvailableBlock>());
        index = DateUtils.addDays(index, 1);
    }
    final Date lastMapKey = dailySchedules.lastKey();
    LOG.debug("visibleSchedule spans " + dailySchedules.keySet().size() + " days");

    try {
        SortedMap<AvailableBlock, AvailableStatus> scheduleBlockMap = visibleSchedule.getBlockMap();
        int numberOfEventsToDisplay = 0;
        for (AvailableBlock block : scheduleBlockMap.keySet()) {
            Date eventStartDate = block.getStartTime();
            LOG.debug("event start date: " + eventStartDate);
            Date mapKey = DateUtils.truncate(eventStartDate, java.util.Calendar.DATE);
            if (CommonDateOperations.equalsOrAfter(eventStartDate, scheduleStart)
                    && dailySchedules.containsKey(mapKey)) {
                dailySchedules.get(mapKey).add(block);
                numberOfEventsToDisplay++;
            }
        }
        LOG.debug("number of events to display: " + numberOfEventsToDisplay);
        if (numberOfEventsToDisplay == 0) {
            // no available times in this range!
            StringBuilder noappointments = new StringBuilder();
            noappointments.append("<span class=\"none-available\">");
            noappointments.append(getMessageSource().getMessage("no.available.appointments", null, null));
            noappointments.append("</span>");
            pageContext.getOut().write(noappointments.toString());
        } else {
            int weekNumber = 1;
            Date currentWeekStart = DateUtils.truncate(scheduleStart, java.util.Calendar.DATE);
            Date currentWeekFinish = DateUtils.addDays(currentWeekStart,
                    CommonDateOperations.numberOfDaysUntilSunday(currentWeekStart));
            currentWeekFinish = DateUtils.addMinutes(currentWeekFinish, -1);

            boolean renderAnotherWeek = true;

            while (renderAnotherWeek) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("will render another week using currentWeekStart " + currentWeekStart
                            + " and currentWeekFinish " + currentWeekFinish);
                }
                SortedMap<Date, List<AvailableBlock>> subMap = dailySchedules.subMap(currentWeekStart,
                        currentWeekFinish);
                renderWeek(servletContext, pageContext.getOut(), weekNumber++, subMap, scheduleBlockMap);

                currentWeekStart = DateUtils.addMinutes(currentWeekFinish, 1);
                currentWeekFinish = DateUtils.addDays(currentWeekStart, 7);
                currentWeekFinish = DateUtils.addMinutes(currentWeekFinish, -1);

                if (LOG.isDebugEnabled()) {
                    LOG.debug("recalculated currentWeekStart " + currentWeekStart + ", currentWeekFinish "
                            + currentWeekFinish);
                }

                if (currentWeekStart.after(lastMapKey)) {
                    renderAnotherWeek = false;
                    LOG.debug("will not render another week");
                }
            }
        }

    } catch (IOException e) {
        LOG.error("IOException occurred in doStartTag", e);
    }
    // SKIP_BODY means don't print any content from body of tag
    return SKIP_BODY;
}

From source file:org.jumpmind.symmetric.statistic.AbstractStatsByPeriodMap.java

public AbstractStatsByPeriodMap(Date start, Date end, List<M> list, int periodSizeInMinutes) {
    Iterator<M> stats = list.iterator();
    Calendar startCal = Calendar.getInstance();
    startCal.setTime(start);// w  ww. j a va 2  s. c o m
    startCal.set(Calendar.SECOND, 0);
    startCal.set(Calendar.MILLISECOND, 0);
    startCal.set(Calendar.MINUTE, round(startCal.get(Calendar.MINUTE)));
    Date periodStart = startCal.getTime();
    Date periodEnd = DateUtils.addMinutes(periodStart, periodSizeInMinutes);
    M stat = null;
    while (periodStart.before(end)) {
        if (stat == null && stats.hasNext()) {
            stat = stats.next();
        }
        if (stat != null && (periodStart.equals(stat.getStartTime()) || periodStart.before(stat.getStartTime()))
                && periodEnd.after(stat.getStartTime())) {
            add(periodStart, stat);
            stat = null;
        } else {
            if (stat != null && stat.getStartTime().before(periodStart)) {
                stat = null;
            }
            if (!containsKey(periodStart)) {
                addBlank(periodStart);
            }
            periodStart = periodEnd;
            periodEnd = DateUtils.addMinutes(periodStart, periodSizeInMinutes);
        }
    }
}

From source file:org.kuali.kra.committee.bo.CommitteeSchedule.java

/**
 * This method is BO persistent accessor method, which adds Time to Date on each call. 
 * In support to UI.// w  w  w.jav  a2s  . c o  m
 * @return
 */
public Timestamp getTime() {
    java.util.Date dt = new java.util.Date(this.time.getTime());
    dt = DateUtils.round(dt, Calendar.DAY_OF_MONTH);
    if (viewTime != null) {
        dt = new java.util.Date(0); // 12/31/1969 19:00:00
        dt = DateUtils.round(dt, Calendar.DAY_OF_MONTH);
        dt = DateUtils.addMinutes(dt, viewTime.findMinutes()); // to set it to 1970-01-01
        //dt = DateUtils.addMinutes(dt, viewTime.findMinutes());
        //dt = DateUtils.addMinutes(dt, getViewTime().findMinutes());
        this.time = new Timestamp(dt.getTime());
    }
    return time;
}

From source file:org.kuali.kra.committee.bo.CommitteeSchedule.java

public Timestamp getStartTime() {
    if (startTime == null || startTime.getTime() == 0) {
        java.util.Date dt = new java.util.Date(0);
        dt = DateUtils.round(dt, Calendar.DAY_OF_MONTH);
        if (viewStartTime != null) {
            dt = DateUtils.addMinutes(dt, viewStartTime.findMinutes());
            // dt = DateUtils.addMinutes(dt, getViewTime().findMinutes());
        }/*from w  ww.  ja  v a 2 s  . c om*/
        this.startTime = new Timestamp(dt.getTime());
    }

    return startTime;
}

From source file:org.kuali.kra.committee.bo.CommitteeSchedule.java

public Timestamp getEndTime() {
    if (endTime == null || endTime.getTime() == 0) {
        java.util.Date dt = new java.util.Date(0); // set to 1969/12/31 19:00 ?
        dt = DateUtils.round(dt, Calendar.DAY_OF_MONTH); // force it to 1970-01-01
        if (viewEndTime != null) {
            dt = DateUtils.addMinutes(dt, viewEndTime.findMinutes());
            // dt = DateUtils.addMinutes(dt, getViewTime().findMinutes());
        }//  w  w  w. j  a  v  a  2  s . co  m
        this.endTime = new Timestamp(dt.getTime());
    }
    return endTime;
}

From source file:org.kuali.kra.committee.service.impl.CommitteeScheduleServiceImpl.java

/**
 * Helper method to convert date and minutes into Time24HrFmt object.
 * @param date/*from  w  w  w . ja  va  2 s  . c  o m*/
 * @param min
 * @return
 * @throws ParseException
 */
protected Time24HrFmt getTime24hFmt(Date date, int min) throws ParseException {
    Date dt = DateUtils.round(date, Calendar.DAY_OF_MONTH);
    dt = DateUtils.addMinutes(dt, min);
    Calendar cl = new GregorianCalendar();
    cl.setTime(dt);
    StringBuffer sb = new StringBuffer();
    String str = sb.append(cl.get(Calendar.HOUR_OF_DAY)).append(COLON).append(cl.get(Calendar.MINUTE))
            .toString();
    return new Time24HrFmt(str);
}

From source file:org.kuali.kra.common.committee.meeting.MeetingServiceImplBase.java

protected Timestamp addHrMinToDate(Timestamp time, Time12HrFmt viewTime) {
    java.util.Date dt = new java.util.Date(0); // this is actually 12-31-1969 19:00.  its GMT time
    DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy h:mm a");
    try {/*from w  ww. j  a va2s.co  m*/
        // support localization. 
        dt = dateFormat.parse("01/01/1970 " + viewTime.getTime() + " " + viewTime.getMeridiem());
        return new Timestamp(dt.getTime());
    } catch (Exception e) {
        // TODO : not sure to throw runtimeexception or not.
        // folowing may convert date to 07-02-1970 iftz is gmt+12 or more
        dt = DateUtils.round(dt, Calendar.DAY_OF_MONTH);
        return new Timestamp(DateUtils.addMinutes(dt, viewTime.findMinutes()).getTime());

    }
}

From source file:org.kuali.kra.scheduling.service.impl.ScheduleServiceImpl.java

/**
 * This is helper method, wraps date with time accurately in java.util.Date (milliseconds).
 * //ww  w .  j a v  a  2s  .  co m
 * @param date to be wrapped.
 * @param time to be added to date.
 * @return wrapped date & time.
 */
protected Date wrapTime(Date date, Time24HrFmt time) {
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    int hour = calendar.get(Calendar.HOUR);
    int min = calendar.get(Calendar.MINUTE);
    int am_pm = calendar.get(Calendar.AM_PM);
    if (am_pm == Calendar.AM) {
        date = DateUtils.addHours(date, -hour);
        date = DateUtils.addMinutes(date, -min);
    } else {
        date = DateUtils.addHours(date, -hour - 12);
        date = DateUtils.addMinutes(date, -min);
    }
    if (null != time) {
        date = DateUtils.addHours(date, new Integer(time.getHours()));
        date = DateUtils.addMinutes(date, new Integer(time.getMinutes()));
    }
    return date;
}

From source file:org.openkoala.koala.monitor.component.MapCacheDataPool.java

/**
 * ??/*from   w ww  . jav  a 2  s.  c om*/
 * @param sessionId
 */
public void refreshActiveSessions(HttpRequestTrace trace) {
    synchronized (activeSessions) {

        Iterator<ActiveUser> iterator = activeSessions.values().iterator();
        while (iterator.hasNext()) {
            ActiveUser user = iterator.next();
            if (DateUtils.addMinutes(user.getActiveTime(), expireTime).after(new Date()))
                break;
            if (!user.getIp().equals(trace.getIp())) {
                iterator.remove();
            }
        }

        ActiveUser currentUser = activeSessions.remove(trace.getIp());
        if (currentUser == null) {
            currentUser = new ActiveUser();
            currentUser.setIp(trace.getIp());
            currentUser.setBeginTime(trace.getBeginTime());
        }
        currentUser.setActiveTime(trace.getEndTime());
        currentUser.setPrincipal(trace.getPrincipal());
        currentUser.setReferer(trace.getReferer());
        currentUser.addCount();
        activeSessions.put(trace.getIp(), currentUser);
    }
}

From source file:org.openkoala.koala.monitor.component.MapCacheDataPool.java

/**
 * ??//from   ww  w  .  j  a v a2 s  . c  o  m
 */
private void clearExpireTrace() {
    Iterator<List<Trace>> its = cache.values().iterator();
    while (its.hasNext()) {
        Trace trace = its.next().get(0);
        if (trace.getBeginTime().before(DateUtils.addMinutes(new Date(), 0 - expireTime))) {
            its.remove();
        }
    }

}