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:org.motechproject.server.svc.impl.RegistrarBeanImplTest.java

public void testFindPersonPreferredMessageDate() {
    DayOfWeek day = DayOfWeek.MONDAY;
    String timeAsString = "09:00";
    Date messageDate = new Date();
    Person person = createPersonWithDateTimePreferences(day, timeAsString);
    Date preferredDate = registrarBean.findPreferredMessageDate(person, messageDate, messageDate, true);
    Calendar messageCalendar = getCalendar(messageDate);
    Calendar preferenceCalendar = getCalendar(preferredDate);

    assertTrue(preferenceCalendar.after(messageCalendar));
    assertEquals(day.getCalendarValue(), preferenceCalendar.get(Calendar.DAY_OF_WEEK));
    assertEquals(9, preferenceCalendar.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, preferenceCalendar.get(Calendar.MINUTE));
    assertEquals(0, preferenceCalendar.get(Calendar.SECOND));
}

From source file:org.motechproject.server.svc.impl.RegistrarBeanImplTest.java

public void testDetermineDefaultPrefDate() {
    DayOfWeek day = DayOfWeek.MONDAY;
    String timeAsString = "09:00";
    Date messageDate = new Date();

    Person person = new Person(1);

    expect(adminService.getGlobalProperty(MotechConstants.GLOBAL_PROPERTY_DAY_OF_WEEK))
            .andReturn(day.toString());//from   www.  j a v a  2s .  com
    expect(adminService.getGlobalProperty(MotechConstants.GLOBAL_PROPERTY_TIME_OF_DAY)).andReturn(timeAsString);
    replay(contextService, adminService);

    Date prefDate = registrarBean.findPreferredMessageDate(person, messageDate, messageDate, true);

    verify(contextService, adminService);

    Calendar messageCalendar = getCalendar(messageDate);
    Calendar preferredCalendar = getCalendar(prefDate);

    assertTrue(preferredCalendar.after(messageCalendar));
    assertEquals(day.getCalendarValue(), preferredCalendar.get(Calendar.DAY_OF_WEEK));
    assertEquals(9, preferredCalendar.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, preferredCalendar.get(Calendar.MINUTE));
    assertEquals(0, preferredCalendar.get(Calendar.SECOND));
}

From source file:com.denimgroup.threadfix.service.remoteprovider.QualysRemoteProvider.java

public List<String> mostRecentScanForApp(RemoteProviderApplication app) {
    if (app == null || app.getNativeId() == null) {
        return null;
    }/*from w  w w .  j a  v a  2s  .com*/

    // POST with no parameters
    // TODO include filters
    InputStream stream = httpPost(getScansForAppUrl(app.getRemoteProviderType()), new String[] {},
            new String[] {});

    if (stream == null) {
        return null;
    }

    QualysScansForAppParser parser = new QualysScansForAppParser();
    parse(stream, parser);

    List<String> scanIds = new ArrayList<String>();

    // This should be replaced with the filtered code
    for (Map<String, String> map : parser.list) {
        Calendar mapDate = null;

        if (app.getNativeId().equals(map.get("webAppName")) && map.get("date") != null) {
            mapDate = getCalendarFromString("yyyy-MM-DD'T'HH:mm:ss'Z'", map.get("date"));
            if (app.getLastImportTime() == null || mapDate.after(app.getLastImportTime())) {
                scanIds.add(map.get("id"));
            }
        }
    }

    log.info("Returning scan IDs " + scanIds + " for application " + app.getNativeId());

    return scanIds;
}

From source file:com.microsoft.tfs.client.common.ui.commands.search.WorkItemSearchCommand.java

/**
 * Checks that the {@link Date} is within the supported range of dates for
 * work item queries. This method is present because the messages from the
 * client-side WIQL parser and query builder are hard to understand in
 * overflow or underflow cases.//from  w w w.j  a va2  s. c o  m
 *
 * @param date
 *        the date to check
 * @throws WITypeConverterException
 *         for consistency with core validation methods
 */
private void throwIfDateOutOfRange(final Date date) throws WITypeConverterException {
    final Calendar cal = Calendar.getInstance();
    cal.setTime(date);

    if (cal.before(PropertyValidation.MIN_ALLOWED_DATE_TIME)
            || cal.after(PropertyValidation.MAX_ALLOWED_DATE_TIME)) {
        throw new WITypeConverterException(
                MessageFormat.format(Messages.getString("WorkItemSearchCommand.DateOutOfRangeFormat"), //$NON-NLS-1$
                        rangeErrorDateFormatter.format(date),
                        rangeErrorDateFormatter.format(PropertyValidation.MIN_ALLOWED_DATE_TIME.getTime()),
                        rangeErrorDateFormatter.format(PropertyValidation.MAX_ALLOWED_DATE_TIME.getTime())));
    }
}

From source file:net.brewspberry.front.JFreeGraphServlet.java

/**
 * This method creates a TimeSeriesCollection from raw String values
 * /*from  ww  w  .j a  v a 2s.  c  o m*/
 * @param data
 * @return
 * @throws NumberFormatException
 * @throws ParseException
 */
public TimeSeriesCollection createDataset(List<String[]> data, boolean timeLimited, boolean fromDB)
        throws NumberFormatException, ParseException {

    TimeSeriesCollection dataSet = new TimeSeriesCollection();

    int compteur = data.size();
    List<TimeSeries> serie = new ArrayList<TimeSeries>();

    logger.fine("Compteur " + compteur + " length :" + data.get(0).length);

    // On cree autant de series qu'il y a de sondes
    for (int k = 0; k <= (data.get(0).length - 5) / 2; k++) {
        serie.add(new TimeSeries("PROBE" + k));
        logger.fine("Added timeSeries PROBE" + k);
    }

    /*
     * For each line like [2015-07-21 12:34:56, 12345, 54321]
     */
    for (int i = 0; i < compteur; i++) {

        /*
         * for each temperature value
         */
        int increment;
        if (fromDB) {
            increment = 1;
        } else {
            increment = 2;
        }
        for (int j = 5; j < data.get(i).length; j += increment) {

            Date dataDate = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(data.get(i)[0]);

            Calendar cal1 = Calendar.getInstance();
            cal1.setTime(dataDate);
            Calendar cal2 = Calendar.getInstance();
            cal2.add(Calendar.MINUTE, graphHorizontalTimeLengthInMinutes);
            logger.fine("Array size : " + data.get(i).length + " & compteur=" + j);

            if (timeLimited) {
                if (cal1.after(cal2)) {
                    if (data.get(i)[j] != null) {
                        // Adds [time, temperature] to the corresponding (i)
                        // serie

                        logger.fine("Adding temperature" + data.get(i)[j] + " to serie nbr" + (j - 5) / 2);
                        serie.get((j - 5) / 2).addOrUpdate(new Second(dataDate),
                                Double.parseDouble(data.get(i)[j]));
                    }
                }
            } else {
                if (data.get(i)[j] != null) {

                    serie.get((j - 5)).addOrUpdate(new Second(dataDate), Double.parseDouble(data.get(i)[j]));
                }
            }
        }
    }

    // Adds each serie to the dataset
    for (int l = 0; l < serie.size(); l++) {
        logger.fine("serie size : " + serie.get(l).getItemCount());

        dataSet.addSeries(serie.get(l));
    }

    logger.fine("dataSet size : " + dataSet.getSeriesCount());

    return dataSet;

}

From source file:org.nuxeo.ecm.core.api.security.ACE.java

/**
 * Constructs an ACE for a given username, permission, specifying whether to grant or deny it, creator user, begin
 * and end date./*  w w w.ja v a 2s . c o m*/
 *
 * @since 7.4
 */
ACE(String username, String permission, boolean isGranted, String creator, Calendar begin, Calendar end,
        Map<String, Serializable> contextData) {
    this.username = username;
    this.permission = permission;
    this.isGranted = isGranted;
    this.creator = creator;
    setBegin(begin);
    setEnd(end);
    if (contextData != null) {
        this.contextData = new HashMap<>(contextData);
    }

    if (begin != null && end != null) {
        if (begin.after(end)) {
            throw new IllegalArgumentException("'begin' date cannot be after 'end' date");
        }
    }
}

From source file:com.drunkendev.confluence.plugins.attachments.PurgeAttachmentsJob.java

private int filterAge(List<Attachment> prior, int maxDaysOld) {
    Calendar dateFrom = Calendar.getInstance();
    dateFrom.add(Calendar.DAY_OF_MONTH, -(maxDaysOld));
    Calendar modDate = Calendar.getInstance();

    for (int i = prior.size() - 1; i >= 0; i--) {
        if (prior.get(i).getLastModificationDate() != null) {
            modDate.setTime(prior.get(i).getLastModificationDate());
            if (dateFrom.after(modDate)) {
                return i;
            }//w w w. ja  v  a 2  s  . c  om
        }
    }

    return -1;
}

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

/**
 * Takes two offset times and returns a list of multiples of the frequency offset from the effective nominal time that occur
 * between them.  The caller should make sure that startCal is earlier than endCal.
 * <p>/*from   www .ja  v  a2  s  .  c o m*/
 * As a simple example, assume its the same day: startCal is 1:00, endCal is 2:00, frequency is 20min, and effective nominal
 * time is 1:20 -- then this method would return a list containing: -20, 0, 20, 40, 60
 *
 * @param startCal The earlier offset time
 * @param endCal The later offset time
 * @param eval The ELEvaluator to use; cannot be null
 * @return A list of multiple of the frequency offset from the effective nominal time that occur between the startCal and endCal
 */
public static List<Integer> expandOffsetTimes(Calendar startCal, Calendar endCal, ELEvaluator eval) {
    List<Integer> expandedFreqs = new ArrayList<Integer>();
    // Use eval because the "current" eval isn't set
    int freq = getDSFrequency(eval);
    TimeUnit freqUnit = getDSTimeUnit(eval);
    Calendar cal = getCurrentInstance(getActionCreationtime(eval), null, eval);
    int totalFreq = 0;
    if (startCal.before(cal)) {
        while (cal.after(startCal)) {
            cal.add(freqUnit.getCalendarUnit(), -freq);
            totalFreq += -freq;
        }
        if (cal.before(startCal)) {
            cal.add(freqUnit.getCalendarUnit(), freq);
            totalFreq += freq;
        }
    } else if (startCal.after(cal)) {
        while (cal.before(startCal)) {
            cal.add(freqUnit.getCalendarUnit(), freq);
            totalFreq += freq;
        }
    }
    // At this point, cal is the smallest multiple of the dataset frequency that is >= to the startCal and offset from the
    // effective nominal time.  Now we can find all of the instances that occur between startCal and endCal, inclusive.
    while (cal.before(endCal) || cal.equals(endCal)) {
        expandedFreqs.add(totalFreq);
        cal.add(freqUnit.getCalendarUnit(), freq);
        totalFreq += freq;
    }
    return expandedFreqs;
}

From source file:com.intuit.wasabi.tests.service.IntegrationExperiment.java

/**
 * Checks if an experiment is created in a 15 second time window and yields all the correct data.
 *
 * @throws java.text.ParseException if the dates are not correctly formatted.
 *///w  w w  .  j av  a 2s  .  com
@Test(dependsOnGroups = { "ping" })
public void t_createAndValidateExperiment() throws java.text.ParseException {
    Calendar now = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    now.add(Calendar.SECOND, -2); // adjust: drops milliseconds. -2 to avoid all problems with that
    Calendar latest = (Calendar) now.clone();
    latest.add(Calendar.SECOND, 15);
    Experiment created = postExperiment(completeExperiment);
    completeExperiment.setState(Constants.EXPERIMENT_STATE_DRAFT);
    assertEqualModelItems(created, completeExperiment, new DefaultNameExclusionStrategy("id", "creationTime",
            "modificationTime", "results", "ruleJson", "hypothesisIsCorrect"));

    String nowStr = TestUtils.getTimeString(now);
    String latestStr = TestUtils.getTimeString(latest);
    Calendar creationTime = TestUtils.parseTime(created.creationTime);
    Assert.assertTrue(creationTime.after(now) && creationTime.before(latest),
            "Creation time is not in the correct interval.\nEarly:   " + nowStr + "\nCreated: "
                    + created.creationTime + "\nLate:    " + latestStr);

    Calendar modificationTime = TestUtils.parseTime(created.modificationTime);
    Assert.assertTrue(modificationTime.after(now) && modificationTime.before(latest),
            "Modification time is not in the correct interval.\nEarly:   " + nowStr + "\nCreated: "
                    + created.modificationTime + "\nLate:    " + latestStr);

    Assert.assertEquals(created.creationTime, created.modificationTime,
            "Creation and Modification are not equal.");

    completeExperiment.update(created);
}

From source file:org.squale.squalecommon.enterpriselayer.businessobject.component.ApplicationBO.java

/**
 * Verify if the audit given in argument is obsolete. The audit should be an audit of the current application
 * //from w w w .  j av a  2  s  . com
 * @param audit The audit to verify
 * @return true if the audit is obsolete
 */
public boolean isAuditObsolete(AuditBO audit) {
    boolean obsolete = true;
    Calendar cal = GregorianCalendar.getInstance();
    Calendar calAuditDate = GregorianCalendar.getInstance();
    calAuditDate.setTime(audit.getRealBeginningDate());
    calAuditDate.add(Calendar.DATE, mResultsStorageOptions);
    if (calAuditDate.after(cal)) {
        obsolete = false;
    }
    return obsolete;
}