Example usage for com.liferay.portal.kernel.cal Recurrence isInRecurrence

List of usage examples for com.liferay.portal.kernel.cal Recurrence isInRecurrence

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.cal Recurrence isInRecurrence.

Prototype

public boolean isInRecurrence(Calendar current) 

Source Link

Document

Method isInRecurrence

Usage

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

License:Open Source License

public void checkEvents() throws PortalException, SystemException {
    List<CalEvent> events = calEventFinder.findByFutureReminders();

    for (CalEvent event : events) {
        User user = userPersistence.fetchByPrimaryKey(event.getUserId());

        if (user == null) {
            deleteEvent(event);// w  w w .j  av a  2 s  . com

            continue;
        }

        Calendar now = CalendarFactoryUtil.getCalendar(user.getTimeZone(), user.getLocale());

        if (!event.isTimeZoneSensitive()) {
            Calendar temp = CalendarFactoryUtil.getCalendar();

            temp.setTime(Time.getDate(now));

            now = temp;
        }

        Calendar startDate = null;

        if (event.isTimeZoneSensitive()) {
            startDate = CalendarFactoryUtil.getCalendar(user.getTimeZone(), user.getLocale());
        } else {
            startDate = CalendarFactoryUtil.getCalendar();
        }

        if (event.isRepeating()) {
            double daysToCheck = Math
                    .ceil(CalEventConstants.REMINDERS[CalEventConstants.REMINDERS.length - 1] / Time.DAY);

            Calendar cal = (Calendar) now.clone();

            for (int i = 0; i <= daysToCheck; i++) {
                Recurrence recurrence = event.getRecurrenceObj();

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

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

                Calendar recurrenceCal = getRecurrenceCal(cal, tzICal, event);

                if (recurrence.isInRecurrence(recurrenceCal)) {
                    remindUser(event, user, recurrenceCal, now);
                }

                cal.add(Calendar.DAY_OF_YEAR, 1);
            }
        } else {
            startDate.setTime(event.getStartDate());

            remindUser(event, user, startDate, now);
        }
    }
}