Example usage for com.liferay.portal.kernel.util CalendarUtil getLTDate

List of usage examples for com.liferay.portal.kernel.util CalendarUtil getLTDate

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util CalendarUtil getLTDate.

Prototype

public static Date getLTDate(Calendar cal) 

Source Link

Usage

From source file:com.liferay.portlet.calendar.service.impl.CalEventLocalServiceImpl.java

License:Open Source License

public List<CalEvent> getEvents(long groupId, Calendar cal, String[] types) throws SystemException {

    if (types != null) {
        types = ArrayUtil.distinct(types);

        Arrays.sort(types);//ww  w.j ava  2  s  . c om
    }

    Map<String, List<CalEvent>> eventsPool = CalEventLocalUtil.getEventsPool(groupId);

    String key = CalUtil.toString(cal, types);

    List<CalEvent> events = eventsPool.get(key);

    if (events == null) {

        // Time zone sensitive

        List<CalEvent> events1 = calEventFinder.findByG_SD_T(groupId, CalendarUtil.getGTDate(cal),
                CalendarUtil.getLTDate(cal), true, types);

        // Time zone insensitive

        Calendar tzICal = CalendarFactoryUtil.getCalendar(TimeZoneUtil.getTimeZone(StringPool.UTC));

        tzICal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE));

        List<CalEvent> events2 = calEventFinder.findByG_SD_T(groupId, CalendarUtil.getGTDate(tzICal),
                CalendarUtil.getLTDate(tzICal), false, types);

        // Create new list

        events = new ArrayList<CalEvent>();

        events.addAll(events1);
        events.addAll(events2);

        // Add repeating events

        events.addAll(getRepeatingEvents(groupId, cal, types));

        events = new UnmodifiableList<CalEvent>(events);

        eventsPool.put(key, events);
    }

    return events;
}

From source file:com.liferay.portlet.timesheet.service.persistence.TimesheetTaskFinderImpl.java

License:Open Source License

public List<Object[]> findByC_U(Date currentDate, long userId) throws SystemException {

    Calendar currentDateGT = Calendar.getInstance();
    Calendar currentDateLT = Calendar.getInstance();

    currentDateGT.setTime(currentDate);/*from  w  w  w  .j  a va 2  s.  c  o m*/
    currentDateLT.setTime(currentDate);

    Timestamp currentDateGT_TS = CalendarUtil.getTimestamp(CalendarUtil.getGTDate(currentDateGT));
    Timestamp currentDateLT_TS = CalendarUtil.getTimestamp(CalendarUtil.getLTDate(currentDateLT));

    Session session = null;

    try {
        session = openSession();

        String sql = CustomSQLUtil.get(FIND_BY_C_U);

        SQLQuery q = session.createSQLQuery(sql);

        q.addScalar("taskId", Type.LONG);
        q.addScalar("segmentId", Type.LONG);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(0);
        qPos.add(currentDateGT_TS);
        qPos.add(currentDateLT_TS);

        Iterator<Object[]> itr = q.iterate();

        List<Object[]> resultList = new ArrayList<Object[]>();

        while (itr.hasNext()) {
            resultList.add(itr.next());
        }

        return resultList;
    } catch (Exception e) {
        throw new SystemException(e);
    } finally {
        closeSession(session);
    }
}