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:nl.strohalm.cyclos.services.transactions.ScheduledPaymentServiceImpl.java

@Override
public boolean canUnblock(final ScheduledPayment scheduledPayment) {
    Transfer firstBlockedTransfer = null;
    for (Transfer transfer : scheduledPayment.getTransfers()) {
        if (transfer.getStatus() == Status.BLOCKED) {
            firstBlockedTransfer = transfer;
            break;
        }//from w  w  w  . j ava  2  s  . c  om
    }
    if (firstBlockedTransfer == null) {
        // No blocked transfer - cannot unblock
        return false;
    }
    final Calendar now = Calendar.getInstance();
    final Calendar date = firstBlockedTransfer.getDate();
    if (now.after(date)) {
        return false;
    }
    return hasBlockPermission(scheduledPayment);
}

From source file:com.sos.CredentialStore.KeePass.pl.sind.keepass.kdb.v1.Entry.java

public boolean isExpired() {
    Calendar today = Calendar.getInstance();
    today.set(Calendar.HOUR_OF_DAY, 0);
    Calendar dteExpiryDate = Calendar.getInstance();
    dteExpiryDate.setTime(this.ExpirationDate());
    boolean flgIsExpired = today.after(dteExpiryDate);
    return flgIsExpired;
}

From source file:de.azapps.mirakel.reminders.ReminderAlarm.java

private static void updateAlarms(final Context ctx) {
    new Thread(new Runnable() {
        @Override//from   ww w .  ja  va  2s. co  m
        public void run() {
            Log.e(TAG, "update");
            alarmManager = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
            // Update the Notifications at midnight
            final Intent intent = new Intent(ctx, ReminderAlarm.class);
            intent.setAction(UPDATE_NOTIFICATION);
            final PendingIntent pendingIntent = PendingIntent.getBroadcast(ctx, 0, intent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            final Calendar triggerCal = new GregorianCalendar();
            triggerCal.set(Calendar.HOUR_OF_DAY, 0);
            triggerCal.set(Calendar.MINUTE, 0);
            triggerCal.add(Calendar.DAY_OF_MONTH, 1);
            alarmManager.setRepeating(AlarmManager.RTC, triggerCal.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
                    pendingIntent);
            // Alarms
            final List<Task> tasks = Task.getTasksWithReminders();
            final Calendar now = new GregorianCalendar();
            for (final Pair<Task, PendingIntent> p : activeAlarms) {
                final Task t = p.first;
                final Task newTask = Task.get(t.getId()).orNull();
                if ((newTask == null) || !newTask.getReminder().isPresent() || newTask.isDone()
                        || newTask.getReminder().get().after(new GregorianCalendar())) {
                    cancelAlarm(ctx, t, newTask, p, p.second);
                } else if (newTask.getReminder().isPresent()) {
                    if (newTask.getReminder().get().after(now) && !newTask.getRecurringReminder().isPresent()) {
                        closeNotificationFor(ctx, t.getId());
                        updateAlarm(ctx, newTask);
                    } else if (newTask.getReminder().get().after(now)
                            && newTask.getRecurringReminder().isPresent()
                            && (newTask.getReminder().get()
                                    .compareTo(newTask.getRecurringReminder().get()
                                            .addRecurring(newTask.getReminder()).orNull()) > 0)
                            && !now.after(newTask.getReminder())) {
                        updateAlarm(ctx, newTask);
                    } else if ((t.getRecurringReminderId() != newTask.getRecurringReminderId())
                            || t.getRecurringReminder().isPresent()) {
                        if (t.getRecurringReminder().isPresent()
                                && newTask.getRecurringReminder().isPresent()) {
                            if (!t.getRecurringReminder().get().equals(newTask.getRecurringReminder().get())) {
                                updateAlarm(ctx, newTask);
                                cancelAlarm(ctx, t, newTask, p, p.second);
                            }
                        } else if (t.getRecurringReminder().isPresent() != newTask.getRecurringReminder()
                                .isPresent()) {
                            updateAlarm(ctx, newTask);
                            cancelAlarm(ctx, t, newTask, p, p.second);
                        }
                    } else {
                        updateAlarm(ctx, newTask);
                    }
                }
            }
            for (final Task t : tasks) {
                try {
                    if (!isAlarm(t)) {
                        Log.d(TAG, "add: " + t.getName());
                        Log.i(TAG, "id " + t.getId());
                        final PendingIntent p = updateAlarm(ctx, t);
                        activeAlarms.add(new Pair<>(t, p));
                    }
                } catch (final NoSuchTaskException e) {
                    Log.wtf(TAG, "Task not found", e);
                }
            }
        }
    }).start();
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorContext.java

/**
 * @return {@code false} if persisted lastUpdated time for index is after {@code calendar}. {@code true} otherwise
 *///ww  w  .  j  a  v a  2  s  .c o m
private boolean isIndexUpdatedAfter(Calendar calendar) {
    NodeBuilder indexStats = definitionBuilder.child(":status");
    PropertyState indexLastUpdatedValue = indexStats.getProperty("lastUpdated");
    if (indexLastUpdatedValue != null) {
        Calendar indexLastUpdatedTime = ISO8601.parse(indexLastUpdatedValue.getValue(Type.DATE));
        return indexLastUpdatedTime.after(calendar);
    } else {
        return true;
    }
}

From source file:nl.strohalm.cyclos.services.accounts.guarantees.PaymentObligationServiceImpl.java

public boolean canChangeStatus(final PaymentObligation paymentObligation, final Status newStatus) {
    boolean isBuyer;
    boolean isSeller;
    switch (newStatus) {
    case PUBLISHED:
        final Calendar today = DateHelper.truncate(Calendar.getInstance());
        final Calendar maxPublishDate = paymentObligation.getMaxPublishDate();
        isBuyer = guaranteeService.isBuyer() && paymentObligation.getBuyer().equals(LoggedUser.accountOwner());
        final boolean validDates = maxPublishDate.equals(today) || maxPublishDate.after(today);
        return isBuyer && validDates && isInSomeStatus(paymentObligation, Status.REGISTERED);
    case REGISTERED: // conceal
        isBuyer = guaranteeService.isBuyer() && paymentObligation.getBuyer().equals(LoggedUser.accountOwner());
        return isBuyer && isInSomeStatus(paymentObligation, Status.PUBLISHED);
    case ACCEPTED:
    case REJECTED:
        isSeller = guaranteeService.isSeller()
                && paymentObligation.getSeller().equals(LoggedUser.accountOwner());
        return isSeller && isInSomeStatus(paymentObligation, Status.PUBLISHED);
    default:/*from w  w  w . j  ava2  s.c o  m*/
        throw new PaymentObligationStatusChangeException(newStatus,
                "Can't change payment obligation's status, unsupported target status: " + newStatus);
    }
}

From source file:com.epam.cme.storefront.forms.validation.PaymentDetailsValidator.java

@Override
public void validate(final Object object, final Errors errors) {
    final PaymentDetailsForm form = (PaymentDetailsForm) object;

    if (StringUtils.isNotBlank(form.getStartMonth()) && StringUtils.isNotBlank(form.getStartYear())
            && StringUtils.isNotBlank(form.getExpiryMonth()) && StringUtils.isNotBlank(form.getExpiryYear())) {
        final Calendar start = Calendar.getInstance();
        start.set(Calendar.DAY_OF_MONTH, 0);
        start.set(Calendar.MONTH, Integer.parseInt(form.getStartMonth()) - 1);
        start.set(Calendar.YEAR, Integer.parseInt(form.getStartYear()) - 1);

        final Calendar expiration = Calendar.getInstance();
        expiration.set(Calendar.DAY_OF_MONTH, 0);
        expiration.set(Calendar.MONTH, Integer.parseInt(form.getExpiryMonth()) - 1);
        expiration.set(Calendar.YEAR, Integer.parseInt(form.getExpiryYear()) - 1);

        if (start.after(expiration)) {
            errors.rejectValue("startMonth", "payment.startDate.invalid");
        }//from  w ww.  jav  a 2 s. co m
    }

    final boolean editMode = StringUtils.isNotBlank(form.getPaymentId());
    if (editMode || Boolean.TRUE.equals(form.getNewBillingAddress())) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.titleCode", "address.title.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.firstName",
                "address.firstName.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.lastName",
                "address.lastName.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.line1", "address.line1.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.townCity",
                "address.townCity.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.postcode",
                "address.postcode.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.countryIso",
                "address.country.invalid");
        // ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.line2",
        // "address.line2.invalid"); // for some addresses this field is required by cybersource
    }
}

From source file:com.sean.takeastand.storage.ScheduleEditor.java

public void editActivated(AlarmSchedule alarmSchedule) {
    int UID = alarmSchedule.getUID();
    scheduleDatabaseAdapter.updateActivated(UID, alarmSchedule.getActivated());
    FixedAlarmSchedule fixedAlarmSchedule = new FixedAlarmSchedule(alarmSchedule);
    if (alarmSchedule.getActivated()) {
        Calendar startTime = alarmSchedule.getStartTime();
        Calendar endTime = alarmSchedule.getEndTime();
        setDailyRepeatingAlarm(UID, Utils.calendarToTimeString(startTime));
        Calendar rightNow = Calendar.getInstance();
        boolean today = Utils.isTodayActivated(alarmSchedule);
        //Check to see if need to start a repeating alarm now
        if (today && startTime.before(rightNow) && endTime.after(rightNow)) {
            new ScheduledRepeatingAlarm(mContext, fixedAlarmSchedule).setRepeatingAlarm();
            Utils.setImageStatus(mContext, Constants.SCHEDULE_RUNNING);
        }/*from   ww  w .j  a v a  2  s.co m*/
    } else {
        cancelDailyRepeatingAlarm(UID);
        if (UID == Utils.getRunningScheduledAlarm(mContext)) {
            new ScheduledRepeatingAlarm(mContext, fixedAlarmSchedule).cancelAlarm();
        }
    }
}

From source file:org.taverna.server.master.localworker.ForkRunFactory.java

/**
 * Makes the subprocess that manufactures runs.
 * // w  w w . j ava 2  s .  c o m
 * @throws Exception
 *             If anything goes wrong.
 */
public void initFactory() throws Exception {
    if (factory != null)
        return;
    // Generate the arguments to use when spawning the subprocess
    factoryProcessName = state.getFactoryProcessNamePrefix() + randomUUID();
    ProcessBuilder p = new ProcessBuilder(getJavaBinary());
    p.command().addAll(asList(getExtraArguments()));
    p.command().add("-jar");
    p.command().add(getServerWorkerJar());
    p.command().add(getExecuteWorkflowScript());
    p.command().add(factoryProcessName);
    p.redirectErrorStream(true);
    p.directory(new File(getProperty("javax.servlet.context.tempdir", getProperty("java.io.tmpdir"))));

    // Spawn the subprocess
    log.info("about to create subprocess: " + p.command());
    factoryProcess = p.start();
    Thread logger = new Thread(new OutputLogger(factoryProcessName, factoryProcess),
            factoryProcessName + ".Logger");
    logger.setDaemon(true);
    logger.start();

    // Wait for the subprocess to register itself in the RMI registry
    Calendar deadline = Calendar.getInstance();
    deadline.add(SECOND, state.getWaitSeconds());
    Exception lastException = null;
    lastStartupCheckCount = 0;
    while (deadline.after(Calendar.getInstance())) {
        try {
            sleep(state.getSleepMS());
            lastStartupCheckCount++;
            log.info("about to look up resource called " + factoryProcessName);
            try {
                // Validate registry connection first
                getTheRegistry().list();
            } catch (ConnectException ce) {
                log.warn("connection problems with registry", ce);
            } catch (ConnectIOException e) {
                log.warn("connection problems with registry", e);
            }
            factory = (RemoteRunFactory) getTheRegistry().lookup(factoryProcessName);
            log.info("successfully connected to factory subprocess " + factoryProcessName);
            if (interhost != null)
                factory.setInteractionServiceDetails(interhost, interport, interwebdav, interfeed);
            return;
        } catch (InterruptedException ie) {
            continue;
        } catch (NotBoundException nbe) {
            lastException = nbe;
            log.info("resource \"" + factoryProcessName + "\" not yet registered...");
            continue;
        } catch (RemoteException re) {
            // Unpack a remote exception if we can
            lastException = re;
            try {
                if (re.getCause() != null)
                    lastException = (Exception) re.getCause();
            } catch (Throwable t) {
                // Ignore!
            }
        } catch (Exception e) {
            lastException = e;
        }
    }
    throw lastException;
}

From source file:com.acc.validator.CCPaymentInfoValidator.java

@Override
public void validate(final Object target, final Errors errors) {
    final CCPaymentInfoData ccPaymentData = (CCPaymentInfoData) target;

    if (StringUtils.isNotBlank(ccPaymentData.getStartMonth())
            && StringUtils.isNotBlank(ccPaymentData.getStartYear())
            && StringUtils.isNotBlank(ccPaymentData.getExpiryMonth())
            && StringUtils.isNotBlank(ccPaymentData.getExpiryYear())) {
        final Calendar start = Calendar.getInstance();
        start.set(Calendar.DAY_OF_MONTH, 0);
        start.set(Calendar.MONTH, Integer.parseInt(ccPaymentData.getStartMonth()) - 1);
        start.set(Calendar.YEAR, Integer.parseInt(ccPaymentData.getStartYear()) - 1);

        final Calendar expiration = Calendar.getInstance();
        expiration.set(Calendar.DAY_OF_MONTH, 0);
        expiration.set(Calendar.MONTH, Integer.parseInt(ccPaymentData.getExpiryMonth()) - 1);
        expiration.set(Calendar.YEAR, Integer.parseInt(ccPaymentData.getExpiryYear()) - 1);

        if (start.after(expiration)) {
            errors.rejectValue("startMonth", "payment.startDate.invalid");
        }//w ww .j  av  a  2  s . c o  m
    }

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "accountHolderName", "field.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cardType", "field.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cardNumber", "field.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "expiryMonth", "field.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "expiryYear", "field.required");

    paymentAddressValidator.validate(ccPaymentData, errors);
}

From source file:org.kuali.coeus.s2sgen.impl.datetime.S2SDateTimeServiceImpl.java

/**
 *
 * This method computes the number of months between any 2 given {@link java.sql.Date} objects
 *
 * @param dateStart starting date.//from ww w .  j av a 2  s .  c  o  m
 * @param dateEnd end date.
 *
 * @return number of months between the start date and end date.
 */
@Override
public ScaleTwoDecimal getNumberOfMonths(java.util.Date dateStart, java.util.Date dateEnd) {
    ScaleTwoDecimal monthCount = ScaleTwoDecimal.ZERO;
    int fullMonthCount = 0;

    Calendar startDate = Calendar.getInstance();
    Calendar endDate = Calendar.getInstance();
    startDate.setTime(dateStart);
    endDate.setTime(dateEnd);

    startDate.clear(Calendar.HOUR);
    startDate.clear(Calendar.MINUTE);
    startDate.clear(Calendar.SECOND);
    startDate.clear(Calendar.MILLISECOND);

    endDate.clear(Calendar.HOUR);
    endDate.clear(Calendar.MINUTE);
    endDate.clear(Calendar.SECOND);
    endDate.clear(Calendar.MILLISECOND);

    if (startDate.after(endDate)) {
        return ScaleTwoDecimal.ZERO;
    }
    int startMonthDays = startDate.getActualMaximum(Calendar.DATE) - startDate.get(Calendar.DATE);
    startMonthDays++;
    int startMonthMaxDays = startDate.getActualMaximum(Calendar.DATE);
    BigDecimal startMonthFraction = BigDecimal.valueOf(startMonthDays).setScale(2, RoundingMode.HALF_UP).divide(
            BigDecimal.valueOf(startMonthMaxDays).setScale(2, RoundingMode.HALF_UP), RoundingMode.HALF_UP);

    int endMonthDays = endDate.get(Calendar.DATE);
    int endMonthMaxDays = endDate.getActualMaximum(Calendar.DATE);

    BigDecimal endMonthFraction = BigDecimal.valueOf(endMonthDays).setScale(2, RoundingMode.HALF_UP).divide(
            BigDecimal.valueOf(endMonthMaxDays).setScale(2, RoundingMode.HALF_UP), RoundingMode.HALF_UP);

    startDate.set(Calendar.DATE, 1);
    endDate.set(Calendar.DATE, 1);

    while (startDate.getTimeInMillis() < endDate.getTimeInMillis()) {
        startDate.set(Calendar.MONTH, startDate.get(Calendar.MONTH) + 1);
        fullMonthCount++;
    }
    fullMonthCount = fullMonthCount - 1;
    monthCount = monthCount.add(new ScaleTwoDecimal(fullMonthCount))
            .add(new ScaleTwoDecimal(startMonthFraction)).add(new ScaleTwoDecimal(endMonthFraction));
    return monthCount;
}