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.alkacon.opencms.calendar.CmsCalendarDisplay.java

/**
 * Returns all entries for the days of the specified range with their corresponding entries as lists.<p>
 * //from   ww w  .ja v  a2  s  .co  m
 * The key of the Map has to be a Date object.<p>
 * 
 * The Map values are always lists of {@link CmsCalendarEntry} objects, if no entries are available for a specific day,
 * an empty List is stored in the Map.<p>
 * 
 * @param startDay the start day of the range
 * @param endDay the end day of the range
 * @return all entries for the days of the specified range with their corresponding entries as lists
 */
public Map getEntriesForDays(Calendar startDay, Calendar endDay) {

    Map displayDays = new TreeMap();
    // first get all entries to display
    Map displayEntries = getDisplayedEntries(startDay, endDay);
    Calendar runDay = setDayTime(startDay, 0, 0, 0);
    while (true) {
        List entries = (List) displayEntries.get(runDay.getTime());
        if (entries == null) {
            entries = new ArrayList(0);
        }
        displayDays.put(runDay.getTime(), entries);

        // increase day to next day
        runDay.add(Calendar.DAY_OF_YEAR, 1);
        if (runDay.after(endDay)) {
            // runDay has reached endDay -> stop loop
            break;
        }
    }
    return displayDays;
}

From source file:nl.strohalm.cyclos.services.access.AccessServiceImpl.java

@Override
public boolean hasPasswordExpired() {
    Group group = LoggedUser.group();
    if (group instanceof OperatorGroup) {
        group = fetchService.fetch(group,
                RelationshipHelper.nested(OperatorGroup.Relationships.MEMBER, Element.Relationships.GROUP));
    }/*w w  w .  jav  a2  s  . c o  m*/
    final TimePeriod exp = group.getBasicSettings().getPasswordExpiresAfter();
    final Calendar passwordDate = LoggedUser.user().getPasswordDate();
    if (passwordDate == null) {
        return true;
    }
    if (exp != null && exp.getNumber() > 0 && passwordDate != null) {
        final Calendar expiresAt = exp.remove(Calendar.getInstance());
        return expiresAt.after(passwordDate);
    }
    return false;
}

From source file:org.kuali.coeus.s2sgen.impl.generate.support.PHS398FellowshipSupplementalV1_1Generator.java

private ScaleTwoDecimal getNumberOfMonths(Date dateStart, Date dateEnd) {
    BigDecimal monthCount = ScaleTwoDecimal.ZERO.bigDecimalValue();
    int fullMonthCount = 0;

    Calendar startDate = Calendar.getInstance();
    Calendar endDate = Calendar.getInstance();
    startDate.setTime(dateStart);/*from  w w w  .  j ava2s.c o m*/
    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 = new ScaleTwoDecimal(startMonthDays).bigDecimalValue()
            .divide(new ScaleTwoDecimal(startMonthMaxDays).bigDecimalValue(), RoundingMode.HALF_UP);

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

    BigDecimal endMonthFraction = new ScaleTwoDecimal(endMonthDays).bigDecimalValue()
            .divide(new ScaleTwoDecimal(endMonthMaxDays).bigDecimalValue(), 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).bigDecimalValue()).add(startMonthFraction)
            .add(endMonthFraction);
    return new ScaleTwoDecimal(monthCount);
}

From source file:com.ecofactor.qa.automation.newapp.service.MockDataServiceImpl.java

/**
 * List events.//w  w  w  . ja  v a  2s  .  c  om
 * 
 * @param thermostatId
 *            the thermostat id
 * @param startTime
 *            the start time
 * @param endTime
 *            the end time
 * @return the list
 * @see com.ecofactor.qa.automation.algorithm.service.DataService#listEvents(java.lang.Integer,
 *      java.util.Calendar, java.util.Calendar)
 */
@Override
public List<PartitionedThermostatEvent> listEvents(Integer thermostatId, Calendar startTime, Calendar endTime) {

    loadEvents(thermostatId);
    List<PartitionedThermostatEvent> events = new ArrayList<PartitionedThermostatEvent>();
    Set<Calendar> timeSet = timeEventMap.keySet();
    Calendar startTimeUTC = DateUtil.copyToUTC(startTime);
    Calendar endTimeUTC = DateUtil.copyToUTC(endTime);
    for (Calendar time : timeSet) {
        LOGGER.info("Checking event for " + DateUtil.format(time, DateUtil.DATE_FMT_FULL_TZ) + " "
                + timeEventMap.get(time).getAlgorithmId() + ", "
                + DateUtil.format(startTimeUTC, DateUtil.DATE_FMT_FULL_TZ) + ", "
                + DateUtil.format(endTimeUTC, DateUtil.DATE_FMT_FULL_TZ));
        if (time.after(startTimeUTC) && time.before(endTimeUTC)) {
            events.add(timeEventMap.get(time));
            LOGGER.info("Including event for " + DateUtil.format(time, DateUtil.DATE_FMT_FULL_TZ));
        }
    }

    return events;
}

From source file:org.kuali.kra.s2s.service.impl.S2SUtilServiceImpl.java

/**
 * // ww w. jav a2  s. c o m
 * This method computes the number of months between any 2 given
 * {@link Date} objects
 * 
 * @param dateStart
 *            starting date.
 * @param dateEnd
 *            end date.
 * 
 * @return number of months between the start date and end date.
 */
public BudgetDecimal getNumberOfMonths(Date dateStart, Date dateEnd) {
    BudgetDecimal monthCount = BudgetDecimal.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 BudgetDecimal.ZERO;
    }
    int startMonthDays = startDate.getActualMaximum(Calendar.DATE) - startDate.get(Calendar.DATE);
    startMonthDays++;
    int startMonthMaxDays = startDate.getActualMaximum(Calendar.DATE);
    BudgetDecimal startMonthFraction = new BudgetDecimal(startMonthDays)
            .divide(new BudgetDecimal(startMonthMaxDays));

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

    BudgetDecimal endMonthFraction = new BudgetDecimal(endMonthDays).divide(new BudgetDecimal(endMonthMaxDays));

    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 BudgetDecimal(fullMonthCount)).add(startMonthFraction)
            .add(endMonthFraction);
    return monthCount;
}

From source file:com.microsoft.tfs.core.clients.versioncontrol.Workstation.java

/**
 * Checks to see if the default local item exclusions have changed on the
 * server. If force is false, this will only happen once a week.
 *
 * @param force//  w  ww  .ja v a 2 s .com
 *        if true the server is contacted every time, otherwise if enough
 *        time has elapsed since the last check
 */
public void checkForLocalItemExclusionUpdates(final VersionControlClient client, final boolean force) {
    final InternalServerInfo serverInfo = getCache().getServerInfoByGUID(client.getServerGUID(),
            client.getConnection().getBaseURI());

    synchronized (configurationMutex) {
        if (!force) {
            final Calendar lastUpdatePlusSevenDays = getLocalItemExclusionCache()
                    .getLastDefaultExclusionUpdate(serverInfo);
            lastUpdatePlusSevenDays.add(Calendar.DAY_OF_MONTH, 7);
            if (lastUpdatePlusSevenDays.after(Calendar.getInstance())) {
                // nothing to do
                return;
            }
        }

        // Call the server to get the latest default exclusions
        final AtomicBoolean fallbackUsed = new AtomicBoolean();
        final ServerSettings settings = client.getServerSettingsWithFallback(fallbackUsed);

        if (settings.getDefaultLocalItemExclusionSet() != null) {
            getLocalItemExclusionCache().setDefaultExclusions(serverInfo,
                    settings.getDefaultLocalItemExclusionSet());
        }
    }
}

From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartHelper.java

/***********************************************************************************************
 * Crop the specified Vector of CalendarisedData to the range given by the start and end Calendars.
 * Return the cropped CalendarisedData, or NULL on failure.
 *
 * @param calendariseddata/*from w w  w  .j a  v a 2s.co  m*/
 * @param startcalendar
 * @param endcalendar
 *
 * @return Vector<Object>
 */

public static Vector<Object> cropCalendarisedDataToRange(final Vector<Object> calendariseddata,
        final Calendar startcalendar, final Calendar endcalendar) {
    Vector<Object> vecCropped;

    vecCropped = null;

    if ((calendariseddata != null) && (!calendariseddata.isEmpty()) && (startcalendar != null)
            && (endcalendar != null)) {
        vecCropped = new Vector<Object>(calendariseddata.size());

        for (int intDataIndex = 0; intDataIndex < calendariseddata.size(); intDataIndex++) {
            final Vector<Object> vecRow;
            final Calendar calendarRow;

            vecRow = (Vector) calendariseddata.get(intDataIndex);

            // We can safely assume that the data Vector is calendarised
            calendarRow = (Calendar) vecRow.get(DataTranslatorInterface.INDEX_TIMESTAMPED_CALENDAR);

            if ((calendarRow.equals(startcalendar) || calendarRow.after(startcalendar))
                    && (calendarRow.before(endcalendar) || calendarRow.equals(endcalendar))) {
                vecCropped.add(vecRow);
            }
        }
    }

    // Did we gather any data?
    if ((vecCropped != null) && (vecCropped.isEmpty())) {
        // Return NULL on failure
        vecCropped = null;
    }

    return (vecCropped);
}

From source file:org.jahia.ajax.gwt.helper.ContentDefinitionHelper.java

public static void resolveDateConstraint(GWTJahiaPropertyDefinition prop) {
    for (String valueConstraint : prop.getValueConstraints()) {
        final boolean lowerInclusive;
        Calendar lowerLimit;
        final boolean upperInclusive;
        Calendar upperLimit;//  w w  w .ja v  a  2s .  c  o  m

        Pattern pattern = Pattern
                .compile("([\\(\\[]) *([0-9TZ\\.\\+-:]*)? *, *([0-9TZ\\.\\+-:]*)? *([\\)\\]])");
        Matcher matcher = pattern.matcher(valueConstraint);
        if (matcher.matches()) {
            try {
                // group 1 is lower inclusive/exclusive
                String s = matcher.group(1);
                lowerInclusive = s.equals("[");
                // group 2 is lower limit
                s = matcher.group(2);
                if (s == null || s.length() == 0) {
                    lowerLimit = null;
                } else {
                    lowerLimit = DateValue.valueOf(matcher.group(2)).getDate();
                }
                // group 3 is upper limit
                s = matcher.group(3);
                if (s == null || s.length() == 0) {
                    upperLimit = null;
                } else {
                    upperLimit = DateValue.valueOf(matcher.group(3)).getDate();
                }
                // group 4 is upper inclusive/exclusive
                s = matcher.group(4);
                upperInclusive = s.equals("]");

                if (lowerLimit == null && upperLimit == null) {
                    String msg = "'" + valueConstraint
                            + "' is not a valid value constraint format for dates: neither min- nor max-date specified";
                    logger.debug(msg);
                    continue;
                }
                if (lowerLimit != null && upperLimit != null) {
                    if (lowerLimit.after(upperLimit)) {
                        String msg = "'" + valueConstraint
                                + "' is not a valid value constraint format for dates: min-date > max-date";
                        logger.debug(msg);
                        continue;
                    }
                }
                if (upperLimit != null) {
                    prop.setMaxValue(String.valueOf(
                            upperInclusive ? upperLimit.getTimeInMillis() : upperLimit.getTimeInMillis() - 1));
                }
                if (lowerLimit != null) {
                    prop.setMinValue(String.valueOf(
                            lowerInclusive ? lowerLimit.getTimeInMillis() : lowerLimit.getTimeInMillis() + 1));
                }
            } catch (ValueFormatException vfe) {
                String msg = "'" + valueConstraint + "' is not a valid value constraint format for dates";
                logger.debug(msg);
                continue;
            } catch (RepositoryException re) {
                String msg = "'" + valueConstraint + "' is not a valid value constraint format for dates";
                logger.debug(msg);
                continue;
            }
        }
    }
}

From source file:com.ecofactor.qa.automation.newapp.service.MockDataServiceImpl.java

/**
 * Gets the sPO events./*w w  w  . j  a v a2  s.  co m*/
 * 
 * @param thermostatId
 *            the thermostat id
 * @param position
 *            the position
 * @return the sPO events
 */
private List<PartitionedThermostatEvent> getSPOEvents(Integer thermostatId, int position) {

    Calendar currentUTCTime = DateUtil.getUTCCalendar();

    List<PartitionedThermostatEvent> events = new ArrayList<PartitionedThermostatEvent>();
    LOGGER.info("Blackout End/current " + DateUtil.format(moBlackoutEndUTCTime, DateUtil.DATE_FMT_FULL_TZ)
            + " , " + DateUtil.format(currentUTCTime, DateUtil.DATE_FMT_FULL_TZ));
    if (moBlackoutEndUTCTime == null || currentUTCTime.after(moBlackoutEndUTCTime)) {

        for (int i = 0; position > 0 && i < jobDataList.size(); ++i) {

            MockJobData block = jobDataList.get(i);

            for (int j = 0; position > (i + j) && j < 2; ++j) {

                Algorithm algorithm = new Algorithm();
                if (mode.equals("Cool")) {
                    algorithm.setId(SPO_COOL);
                } else if (mode.equals("Heat")) {
                    algorithm.setId(SPO_HEAT);
                }

                PartitionedThermostatEvent thermostatEvent = new PartitionedThermostatEvent();
                thermostatEvent.setAlgorithmId(algorithm.getId());
                thermostatEvent.setThermostatId(thermostatId);
                thermostatEvent.setPhase(0);

                Calendar utc = null;
                if (j == 0) {
                    if (moBlackoutEndUTCTime != null) {
                        utc = currentUTCTime;
                    } else {
                        utc = DateUtil.getUTCCalendar(block.getStart());
                    }
                    thermostatEvent.setDeltaEE(Double.valueOf("" + block.getDelta()));
                } else {
                    utc = DateUtil.getUTCCalendar(block.getEnd());
                    thermostatEvent.setDeltaEE(0.0);
                }

                utc.add(Calendar.SECOND, 45);
                thermostatEvent.getId().setEventSysTime(utc);
                thermostatEvent.setOldSetting(baseTemp);
                if (mode.equals("Cool")) {
                    thermostatEvent.setNewSetting(baseTemp + block.getDelta());
                } else if (mode.equals("Heat")) {
                    thermostatEvent.setNewSetting(baseTemp - block.getDelta());
                }
                thermostatEvent.setStatus(1);
                events.add(thermostatEvent);

                moBlackoutEndUTCTime = null;
            }
        }
    }

    return events;
}

From source file:nl.strohalm.cyclos.services.accountfees.AccountFeeServiceImpl.java

private void insertMissingLogs() {
    final AccountFeeQuery query = new AccountFeeQuery();
    query.setReturnDisabled(false);/*w w w.  jav a 2  s .  co  m*/
    query.setType(RunMode.SCHEDULED);
    Calendar thisHour = DateUtils.truncate(Calendar.getInstance(), Calendar.HOUR_OF_DAY);
    final List<AccountFee> accountFees = accountFeeDao.search(query);
    for (final AccountFee fee : accountFees) {
        final Field recurrenceField = fee.getRecurrence().getField();
        final List<Period> missingPeriods = getMissingPeriods(fee);
        if (!missingPeriods.isEmpty()) {
            for (final Period period : missingPeriods) {
                final Calendar shouldHaveChargedAt = DateHelper.truncate(period.getEnd());
                shouldHaveChargedAt.add(Calendar.DAY_OF_MONTH, 1);
                switch (recurrenceField) {
                case WEEKS:
                    // Go to the day it should have been charged
                    int max = 7;
                    while (max > 0 && shouldHaveChargedAt.get(Calendar.DAY_OF_WEEK) < fee.getDay()) {
                        shouldHaveChargedAt.add(Calendar.DAY_OF_MONTH, 1);
                        max--;
                    }
                    break;
                case MONTHS:
                    shouldHaveChargedAt.set(Calendar.DAY_OF_MONTH, fee.getDay());
                    break;
                }
                shouldHaveChargedAt.set(Calendar.HOUR_OF_DAY, fee.getHour());
                // Only insert the missing log if it should have run before or at this hour
                if (!shouldHaveChargedAt.after(thisHour)) {
                    final AccountFeeLog log = new AccountFeeLog();
                    log.setAccountFee(fee);
                    log.setDate(shouldHaveChargedAt);
                    log.setPeriod(period);
                    log.setAmount(fee.getAmount());
                    log.setFreeBase(fee.getFreeBase());
                    accountFeeLogDao.insert(log);
                }
            }
        }
    }
}