Example usage for java.util Calendar after

List of usage examples for java.util Calendar after

Introduction

In this page you can find the example usage for java.util Calendar after.

Prototype

public boolean after(Object when) 

Source Link

Document

Returns whether this Calendar represents a time after the time represented by the specified Object.

Usage

From source file:com.devnexus.ting.web.controller.admin.RegistrationController.java

private String[] formatTicketTypes(EventSignup signUp) {
    return signUp.getGroups().stream().filter((TicketGroup group) -> {
        Calendar today = Calendar.getInstance();
        return today.after(toCal(group.getOpenDate())) && today.before(toCal(group.getCloseDate()));
    }).map((TicketGroup group) -> {/*from w  w w  . jav a2s  .  co m*/
        return String.format("%s -|-%d\\n", group.getLabel(), group.getId());
    }).toArray(String[]::new);
}

From source file:nl.strohalm.cyclos.services.elements.ReferenceServiceImpl.java

/**
 * Returns true if a member or an operator are in time to make the feedback.
 * @param transactionFeedback//from   w w  w.j  a  va2  s  .  c om
 * @return
 */
private boolean canFeedbackNow(final TransactionFeedback transactionFeedback) {
    Payment payment = transactionFeedback.getPayment();
    payment = fetchService.fetch(payment, Payment.Relationships.TYPE);
    Calendar paymentDate;
    if (payment instanceof ScheduledPayment) {
        paymentDate = payment.getDate();
    } else {
        paymentDate = payment.getProcessDate();
    }
    final Calendar commentLimit = payment.getType().getFeedbackExpirationTime().add(paymentDate);
    return commentLimit.after(Calendar.getInstance());
}

From source file:net.frontlinesms.plugins.reminders.RemindersThinletTabController.java

/**
 * Send a Reminder//from w w  w .jav a2  s . com
 */
public void sendReminder(Reminder reminder) {
    LOG.debug("sendReminder: " + reminder);
    LOG.debug("sendReminder: " + reminder);
    if (reminder != null) {
        if (reminder.getType() == Reminder.Type.EMAIL) {
            if (reminder.getEmailAccount() != null) {
                for (String contactName : reminder.getRecipientsArray()) {
                    LOG.debug("Sending EMAIL");
                    Contact contact = this.contactDao.getContactByName(contactName);
                    Email email = new Email(reminder.getEmailAccount(), contact.getEmailAddress(),
                            reminder.getSubject(), reminder.getContent());
                    this.emailDao.saveEmail(email);
                    this.emailManager.sendEmail(email);
                }
                this.ui.setStatus(
                        InternationalisationUtils.getI18NString(RemindersConstants.EMAIL_REMINDER_SENT));
            } else {
                this.ui.alert(
                        InternationalisationUtils.getI18NString(RemindersConstants.MISSING_EMAIL_ACCOUNT));
            }
        } else if (reminder.getType() == Reminder.Type.MESSAGE) {
            for (String contactName : reminder.getRecipientsArray()) {
                Contact contact = this.contactDao.getContactByName(contactName);
                if (contact != null) {
                    LOG.debug("Sending MESSAGE");
                    this.frontlineController.sendTextMessage(contact.getPhoneNumber(), reminder.getContent());
                }
            }
            this.ui.setStatus(InternationalisationUtils.getI18NString(RemindersConstants.SMS_REMINDER_SENT));
        }
        Calendar now = Calendar.getInstance();
        if (now.equals(reminder.getEndCalendar())) {
            LOG.debug("now == end: " + reminder);
            reminder.setStatus(Reminder.Status.SENT);
        } else if (now.after(reminder.getEndCalendar())) {
            LOG.debug("now > end: " + reminder);
            reminder.setStatus(Reminder.Status.SENT);
        }
        this.reminderDao.updateReminder(reminder);
    }
    this.pagerReminders.refresh();
}

From source file:com.android.deskclock.alarms.AlarmStateManager.java

/**
 * Fix and update all alarm instance when a time change event occurs.
 *
 * @param context application context/*  www  . j  av  a  2s.  c o  m*/
 */
public static void fixAlarmInstances(Context context) {
    // Register all instances after major time changes or when phone restarts
    final ContentResolver contentResolver = context.getContentResolver();
    final Calendar currentTime = getCurrentTime();
    for (AlarmInstance instance : AlarmInstance.getInstances(contentResolver, null)) {
        final Alarm alarm = Alarm.getAlarm(contentResolver, instance.mAlarmId);
        if (alarm == null) {
            unregisterInstance(context, instance);
            AlarmInstance.deleteInstance(contentResolver, instance.mId);
            LogUtils.e("Found instance without matching alarm; deleting instance %s", instance);
            continue;
        }
        final Calendar priorAlarmTime = alarm.getPreviousAlarmTime(instance.getAlarmTime());
        final Calendar missedTTLTime = instance.getMissedTimeToLive();
        if (currentTime.before(priorAlarmTime) || currentTime.after(missedTTLTime)) {
            final Calendar oldAlarmTime = instance.getAlarmTime();
            final Calendar newAlarmTime = alarm.getNextAlarmTime(currentTime);
            final CharSequence oldTime = DateFormat.format("MM/dd/yyyy hh:mm a", oldAlarmTime);
            final CharSequence newTime = DateFormat.format("MM/dd/yyyy hh:mm a", newAlarmTime);
            LogUtils.i("A time change has caused an existing alarm scheduled to fire at %s to"
                    + " be replaced by a new alarm scheduled to fire at %s", oldTime, newTime);

            // The time change is so dramatic the AlarmInstance doesn't make any sense;
            // remove it and schedule the new appropriate instance.
            AlarmStateManager.deleteInstanceAndUpdateParent(context, instance);
        } else {
            registerInstance(context, instance, false);
        }
    }

    updateNextAlarm(context);
}

From source file:org.linagora.linshare.core.service.impl.UploadRequestUrlServiceImpl.java

private void accessBusinessCheck(UploadRequestUrl requestUrl, String password) throws BusinessException {
    UploadRequest request = requestUrl.getUploadRequest();
    if (!isValidPassword(requestUrl, password)) {
        throw new BusinessException(BusinessErrorCode.UPLOAD_REQUEST_URL_FORBIDDEN,
                "You do not have the right to get this upload request url : " + requestUrl.getUuid());
    }//from  w w  w  .j  av  a 2 s  .c o m

    if (!(request.getStatus().equals(UploadRequestStatus.STATUS_ENABLED)
            || request.getStatus().equals(UploadRequestStatus.STATUS_CLOSED))) {
        throw new BusinessException(BusinessErrorCode.UPLOAD_REQUEST_READONLY_MODE,
                "The current upload request url is not available : " + requestUrl.getUuid());
    }

    Calendar now = GregorianCalendar.getInstance();
    Calendar compare = GregorianCalendar.getInstance();
    compare.setTime(request.getActivationDate());
    if (now.before(compare)) {
        throw new BusinessException(BusinessErrorCode.UPLOAD_REQUEST_NOT_ENABLE_YET,
                "The current upload request url is not enable yet : " + requestUrl.getUuid());
    }
    if (request.getExpiryDate() != null) {
        compare.setTime(request.getExpiryDate());
        if (now.after(compare)) {
            throw new BusinessException(BusinessErrorCode.UPLOAD_REQUEST_NOT_ENABLE_YET,
                    "The current upload request url is no more available now. : " + requestUrl.getUuid());
        }
    }
}

From source file:com.forrestguice.suntimeswidget.EquinoxView.java

private EquinoxNote findClosestNote(Calendar now, boolean upcoming) {
    if (notes == null || now == null) {
        return null;
    }/* ww  w .  j av  a2  s.  c  o  m*/

    EquinoxNote closest = null;
    long timeDeltaMin = Long.MAX_VALUE;
    for (EquinoxNote note : notes) {
        Calendar noteTime = note.getTime();
        if (noteTime != null) {
            if (upcoming && !noteTime.after(now))
                continue;

            long timeDelta = Math.abs(noteTime.getTimeInMillis() - now.getTimeInMillis());
            if (timeDelta < timeDeltaMin) {
                timeDeltaMin = timeDelta;
                closest = note;
            }
        }
    }
    return closest;
}

From source file:org.nuxeo.cm.demo.UpdateDemoData.java

private Calendar _buildDate(Calendar inDate, int inDays) {
    Calendar d = (Calendar) inDate.clone();

    d.add(Calendar.DATE, inDays);
    if (d.after(_today)) {
        d = (Calendar) _today.clone();
    }/*  w w w.  j  ava2  s.c  om*/

    return d;
}

From source file:org.nuxeo.cm.demo.UpdateDemoData.java

private Calendar _buildDate(Calendar inDate, int inDays, boolean inOkIfAfterToday) {
    Calendar d = (Calendar) inDate.clone();

    d.add(Calendar.DATE, inDays);
    if (d.after(_today) && !inOkIfAfterToday) {
        d = (Calendar) _today.clone();
    }/*from   w w  w  .  j a  v  a 2s .c o  m*/

    return d;
}

From source file:org.msec.LogQuery.java

public List<String> getTableList(String startDateStr, String endDateStr) throws ParseException, SQLException {
    Date startDate = dateFormatter.parse(startDateStr);
    Date endDate = dateFormatter.parse(endDateStr);
    List<String> ret = new ArrayList<String>();

    Calendar start = Calendar.getInstance();
    start.setTime(startDate);/*w w w. j av a 2  s. com*/
    Calendar end = Calendar.getInstance();
    end.setTime(endDate);

    for (Date date = start.getTime(); !start.after(end); start.add(Calendar.DATE, 1), date = start.getTime()) {
        //
        String tableName = tableNamePrefix + dayFormatter.format(date);
        DatabaseMetaData md = conn.getMetaData();
        ResultSet rs = md.getTables(null, null, tableName, null);
        if (rs.next()) {
            ret.add(tableNamePrefix + dayFormatter.format(date));
        }
    }
    return ret;
}

From source file:org.apache.oozie.coord.CoordELFunctions.java

/**
 *
 * @param n offset amount (integer)//from w  w w . j a v a 2  s .  com
 * @param timeUnit TimeUnit for offset n ("MINUTE", "HOUR", "DAY", "MONTH", "YEAR")
 * @return the offset time from the effective nominal time <p> return empty string ("") if the Action_Creation_time or the
 *         offset instance <p> is earlier than the Initial_Instance of dataset.
 * @throws Exception
 */
private static String coord_offset_sync(int n, String timeUnit) throws Exception {
    Calendar rawCal = resolveOffsetRawTime(n, TimeUnit.valueOf(timeUnit), null);
    if (rawCal == null) {
        // warning already logged by resolveOffsetRawTime()
        return "";
    }

    int freq = getDSFrequency();
    TimeUnit freqUnit = getDSTimeUnit();
    int freqCount = 0;
    // We're going to manually turn back/forward cal by decrements/increments of freq and then check that it gives the same
    // time as rawCal; this is to check that the offset time resolves to a frequency offset of the effective nominal time
    // In other words, that there exists an integer x, such that coord:offset(n, timeUnit) == coord:current(x) is true
    // If not, then we'll "rewind" rawCal to the latest instance earlier than rawCal and use that.
    Calendar cal = getInitialInstanceCal();
    if (rawCal.before(cal)) {
        while (cal.after(rawCal)) {
            cal.add(freqUnit.getCalendarUnit(), -freq);
            freqCount--;
        }
    } else if (rawCal.after(cal)) {
        while (cal.before(rawCal)) {
            cal.add(freqUnit.getCalendarUnit(), freq);
            freqCount++;
        }
    }
    if (cal.before(rawCal)) {
        rawCal = cal;
    } else if (cal.after(rawCal)) {
        cal.add(freqUnit.getCalendarUnit(), -freq);
        rawCal = cal;
        freqCount--;
    }
    String rawCalStr = DateUtils.formatDateOozieTZ(rawCal);

    Calendar nominalInstanceCal = getInitialInstanceCal();
    nominalInstanceCal.add(freqUnit.getCalendarUnit(), freq * freqCount);
    if (nominalInstanceCal.getTime().compareTo(getInitialInstance()) < 0) {
        XLog.getLog(CoordELFunctions.class)
                .warn("If the initial instance of the dataset is later than the offset instance"
                        + " specified, such as coord:offset({0}, {1}) in this case, an empty string is returned. This means that no"
                        + " data is available at the offset instance specified by the user and the user could try modifying his"
                        + " initial-instance to an earlier time.", n, timeUnit);
        return "";
    }
    String nominalCalStr = DateUtils.formatDateOozieTZ(nominalInstanceCal);

    if (!rawCalStr.equals(nominalCalStr)) {
        throw new RuntimeException("Shouldn't happen");
    }
    return rawCalStr;
}