Example usage for java.util Calendar DATE

List of usage examples for java.util Calendar DATE

Introduction

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

Prototype

int DATE

To view the source code for java.util Calendar DATE.

Click Source Link

Document

Field number for get and set indicating the day of the month.

Usage

From source file:com.linuxbox.enkive.statistics.gathering.past.PastGatherer.java

protected void setEndDate(int grain) {
    Calendar end = Calendar.getInstance();
    end.set(Calendar.MILLISECOND, 0);
    end.set(Calendar.SECOND, 0);/*from  w ww.  ja  v a2s  . c om*/
    end.set(Calendar.MINUTE, 0);
    if (grain == CONSOLIDATION_HOUR) {
        end.add(Calendar.HOUR_OF_DAY, -hrKeepTime);
    } else if (grain == CONSOLIDATION_DAY) {
        end.set(Calendar.HOUR_OF_DAY, 0);
        end.add(Calendar.DATE, -dayKeepTime);
    } else if (grain == CONSOLIDATION_WEEK) {
        end.set(Calendar.HOUR_OF_DAY, 0);
        while (end.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
            end.add(Calendar.DATE, -1);
        }
        end.add(Calendar.WEEK_OF_YEAR, -weekKeepTime);
    } else if (grain == CONSOLIDATION_MONTH) {
        end.set(Calendar.HOUR_OF_DAY, 0);
        end.set(Calendar.DAY_OF_MONTH, 1);
        end.add(Calendar.MONTH, -monthKeepTime);
    }
    this.endDate = end.getTime();
}

From source file:edu.stanford.muse.index.DatedDocument.java

public String dateString() {
    if (date != null) {
        Calendar c = new GregorianCalendar();
        c.setTime(date);//w  w w.ja  v a  2  s .c om
        return c.get(Calendar.DATE) + " " + CalendarUtil.getDisplayMonth(c) + " " + c.get(Calendar.YEAR);
    } else
        return "????-??-??";
}

From source file:net.duckling.ddl.util.EncodeUtil.java

public static String getNextThreeDay() {
    Calendar c = Calendar.getInstance();
    c.setTime(new Date());
    c.add(Calendar.DATE, 3);
    return AoneTimeUtils.formatToDateTime(c.getTime());
}

From source file:com.linuxbox.enkive.message.search.RetentionPolicyEnforcingMessageSearchService.java

private Map<String, String> addRetentionPolicyToFields(Map<String, String> searchFields) {
    HashMap<String, String> retentionFields = messageRetentionPolicy.getRetentionPolicyCriteria();

    if (retentionFields.get(RETENTION_PERIOD) != null && !retentionFields.get(RETENTION_PERIOD).isEmpty()
            && Integer.parseInt(retentionFields.get(RETENTION_PERIOD)) > 0) {

        String retentionPeriodString = retentionFields.get(RETENTION_PERIOD);
        int retentionPeriod = Integer.parseInt(retentionPeriodString);
        Calendar retentionCal = Calendar.getInstance();
        retentionCal.add(Calendar.DATE, (-1 * retentionPeriod));
        Date retentionDate = retentionCal.getTime();

        if (searchFields.get(DATE_EARLIEST_PARAMETER) != null
                && !searchFields.get(DATE_EARLIEST_PARAMETER).isEmpty()) {
            try {
                Date searchDate = NUMERIC_SEARCH_FORMAT.parse(searchFields.get(DATE_EARLIEST_PARAMETER));
                if (retentionDate.after(searchDate)) {
                    searchFields.put(DATE_EARLIEST_PARAMETER, NUMERIC_SEARCH_FORMAT.format(retentionDate));
                }//from   ww w . j  a v  a 2s .c o  m
            } catch (ParseException e) {
                searchFields.put(DATE_EARLIEST_PARAMETER, NUMERIC_SEARCH_FORMAT.format(retentionDate));
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn("Could not parse earliest date submitted to search - "
                            + searchFields.get(DATE_EARLIEST_PARAMETER));
            }
        } else {
            searchFields.put(DATE_EARLIEST_PARAMETER, NUMERIC_SEARCH_FORMAT.format(retentionDate));
        }
    }

    return searchFields;
}

From source file:net.seratch.taskun.util.CalendarUtil.java

 public static Calendar addDays(Calendar src, int days) {
   Calendar dest = deepCopy(src);
   dest.add(Calendar.DATE, days);
   return dest;//  ww w  . java 2s . c  om
}

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

/**
 * Initializes a default experiment.// w w w  .j  av  a  2  s  . c o  m
 */
public EventsIntegrationTest() {
    setResponseLogLengthLimit(1000);

    dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -1);
    yesterday = dateFormat.format(cal.getTime());
    yesterday += "T00:00:00+0000";

    cal = Calendar.getInstance();
    cal.add(Calendar.DATE, 0);
    today = dateFormat.format(cal.getTime());
    today += "T00:00:00+0000";

    cal = Calendar.getInstance();
    cal.add(Calendar.DATE, 1);
    tomorrow = dateFormat.format(cal.getTime());
    tomorrow += "T00:00:00+0000";

    cal = Calendar.getInstance();
    cal.add(Calendar.DATE, 3);
    tomorrowPlus3 = dateFormat.format(cal.getTime());
    tomorrowPlus3 += "T00:00:00+0000";

    cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -3);
    yesterdayMinus3 = dateFormat.format(cal.getTime());
    yesterdayMinus3 += "T00:00:00+0000";

    cal = Calendar.getInstance();
    cal.add(Calendar.DATE, 5);
    tomorrowPlus5 = dateFormat.format(cal.getTime());
    tomorrowPlus5 += "T00:00:00+0000";

    cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -5);
    yesterdayMinus5 = dateFormat.format(cal.getTime());
    yesterdayMinus5 += "T00:00:00+0000";

    experiment = ExperimentFactory.createExperiment();
    experiment.startTime = yesterdayMinus3;
    experiment.endTime = tomorrowPlus3;
    experiment.samplingPercent = 1.0;
    experiment.label = "experiment";
    experiment.applicationName = QBO + UUID.randomUUID();

    DefaultNameExclusionStrategy experimentComparisonStrategy = new DefaultNameExclusionStrategy("creationTime",
            "modificationTime", "ruleJson");
    experiment.setSerializationStrategy(experimentComparisonStrategy);

}

From source file:org.motechproject.server.event.MessageProgramDateStateChangeTest.java

@Override
protected void setUp() throws Exception {
    Calendar calendar = Calendar.getInstance();
    calendar.set(2010, 5, 23, 14, 49, 19); // Wed Jun 23 14:49:19 2010
    referenceDate = calendar.getTime();/*  w w  w.  ja  v a  2 s.  c om*/

    calendar.set(2010, 6, 27, 19, 49, 19); // Wed Jul 27 19:49:19 2010
    week5 = calendar.getTime();

    calendar.set(2010, 7, 2, 19, 49, 19); // Mon Aug 2 19:49:19 2010
    week6Monday = calendar.getTime();
    calendar.set(2010, 7, 6, 19, 49, 19); // Fri Aug 6 19:49:19 2010
    week6Friday = calendar.getTime();
    calendar.set(2010, 7, 7, 19, 49, 19); // Fri Aug 7 19:49:19 2010
    week7Saturday = calendar.getTime();

    calendar.setTime(referenceDate);
    calendar.add(Calendar.DATE, 46 * 7 + 1); // over 46 weeks
    week46 = calendar.getTime();

    patientId = 1;
    obsId = 2;

    enrollment = new MessageProgramEnrollment();
    enrollment.setPersonId(patientId);
    enrollment.setObsId(obsId);

    ctx = new ClassPathXmlApplicationContext(
            new String[] { "test-common-program-beans.xml", "programs/weekly-info-pregnancy-program.xml" });
    pregnancyProgram = (MessageProgram) ctx.getBean("weeklyInfoPregnancyProgram");

    pregnancyState5 = (MessageProgramState) ctx.getBean("weeklyInfoPregnancyState5");
    pregnancyState6 = (MessageProgramState) ctx.getBean("weeklyInfoPregnancyState6");
    pregnancyState45 = (MessageProgramState) ctx.getBean("weeklyInfoPregnancyState45");

    // EasyMock setup in Spring config
    registrarBean = (RegistrarBean) ctx.getBean("registrarBean");
}

From source file:gsn.vsensor.AbstractScheduledVirtualSensor.java

/**
 * Called once while initializing an instance of the virtual sensor
 * Gets schedule parameters from VSD, calculates timer parameters and instantiates timer instance.
 * /*from   w ww.j  a  va  2 s.c  om*/
 * @return True if the initialization is done successfully.
 */
public boolean initialize() {
    TreeMap<String, String> params = getVirtualSensorConfiguration().getMainClassInitialParams();
    String rate_value = params.get(RATE_PARAM);

    if (rate_value == null) {
        logger.warn("Parameter \"" + RATE_PARAM + "\" not provider in Virtual Sensor file");
        return false;
    }

    clock_rate = Integer.parseInt(rate_value);

    String start_value = params.get(START_PARAM);

    if (start_value != null) { //start value set in VSD
        try {
            startTime = Helpers.convertTimeFromIsoToLong(start_value);
        } catch (Exception e) {
            logger.error(
                    "Failed to parse the start-time parameter of the remote wrapper, a sample time could be:"
                            + (CURRENT_TIME));
            throw new RuntimeException(e);
        }
    }
    // If the scheduled start is not in the future
    // then start at the next whole time interval
    if (System.currentTimeMillis() >= startTime) {
        startTime = System.currentTimeMillis(); // current time
        // Calculate from midnight   
        long midnight = DateUtils.truncate(new Date(), Calendar.DATE).getTime();
        long current_time = System.currentTimeMillis();
        // Start
        startTime = midnight + (((current_time - midnight) / clock_rate) + 1) * clock_rate;
    } //otherwise use the time retrieved from the VSD

    logger.warn(getVirtualSensorConfiguration().getName() + " scheduled to start at "
            + new Date(startTime).toString());

    // startTime is used in the virtual sensor class to start a timer
    timer0 = new Timer();
    // timer task is started in the sub class
    return true;
}

From source file:com.adobe.acs.commons.wcm.impl.FileImporterTest.java

@Test
public void testImportToFolderHavingFileWhichIsNewer() throws Exception {
    final Calendar latest = Calendar.getInstance();
    latest.add(Calendar.DATE, 2);
    final Node file = JcrUtils.putFile(folder, testFile.getName(), "x-text/test",
            new ByteArrayInputStream("".getBytes()), latest);

    session.save();//from   w  ww. j  av a 2  s. c  o  m

    Resource resource = mock(Resource.class);
    when(resource.adaptTo(Node.class)).thenReturn(folder);
    importer.importData("file", testFile.getAbsolutePath(), resource);

    assertFalse(session.hasPendingChanges());
    assertTrue(folder.hasNode(testFile.getName()));

    // this verifies the the file wasn't imported
    assertEquals("x-text/test", JcrUtils.getStringProperty(file, "jcr:content/jcr:mimeType", ""));
}

From source file:com.vmware.appfactory.common.runner.LicenseStatus.java

/**
 * Find out whether license is expired or not using yesterday midnight.
 * Calculate the number of days until expiration.
 *///  w ww .  j  a va  2  s  . co  m
private final void calculateNumDaysToExpiration() {
    final GregorianCalendar gCal = new GregorianCalendar(AfCalendar.LOCAL_TZONE);
    gCal.add(Calendar.DATE, -1);
    final Date yesterdayMidnight = DateUtils.round(gCal.getTime(), Calendar.HOUR);
    setNumDaysToExpiration(
            (_expirationDate.getTime() - yesterdayMidnight.getTime()) / DateUtils.MILLIS_PER_DAY);

    if (getNumDaysToExpiration() <= 0) {
        _isExpired = true;
    } else {
        _isExpired = false;
    }
}