Calendar cal = UtilDateTime.toCalendar(now, timeZone, locale);
Timestamp reminderStamp = reminder.getTimestamp("reminderDateTime");
Date eventDateTime = workEffort.getTimestamp("estimatedStartDate");
String tempExprId = workEffort.getString("tempExprId");
if (UtilValidate.isNotEmpty(tempExprId)) {
TemporalExpression temporalExpression = null;
try {
temporalExpression = TemporalExpressionWorker.getTemporalExpression(delegator, tempExprId);
} catch (GenericEntityException e) {
Debug.logWarning("Error while getting temporal expression, id = " + tempExprId + ": " + e, module);
}
if (temporalExpression != null) {
eventDateTime = temporalExpression.first(cal).getTime();
Date reminderDateTime = null;
long recurrenceOffset = reminder.get("recurrenceOffset") == null ? 0 : reminder.getLong("recurrenceOffset").longValue();
if (reminderStamp == null) {
if (recurrenceOffset != 0) {
cal.setTime(eventDateTime);
TimeDuration duration = TimeDuration.fromLong(recurrenceOffset);
duration.addToCalendar(cal);
reminderDateTime = cal.getTime();
} else {
reminderDateTime = eventDateTime;
}
} else {
reminderDateTime = new Date(reminderStamp.getTime());
}
if (reminderDateTime.before(now) && reminderStamp != null) {
try {
parameters.put("eventDateTime", new Timestamp(eventDateTime.getTime()));
processEventReminder(ctx, reminder, parameters);
if (repeatCount != 0 && currentCount + 1 >= repeatCount) {
reminder.remove();
} else {
cal.setTime(reminderDateTime);
Date newReminderDateTime = null;
if (recurrenceOffset != 0) {
TimeDuration duration = TimeDuration.fromLong(-recurrenceOffset);
duration.addToCalendar(cal);
cal.setTime(temporalExpression.next(cal).getTime());
duration = TimeDuration.fromLong(recurrenceOffset);
duration.addToCalendar(cal);
newReminderDateTime = cal.getTime();
} else {
newReminderDateTime = temporalExpression.next(cal).getTime();
}
reminder.set("currentCount", new Long(currentCount + 1));
reminder.set("reminderDateTime", new Timestamp(newReminderDateTime.getTime()));
reminder.store();
}