Example usage for java.util Calendar roll

List of usage examples for java.util Calendar roll

Introduction

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

Prototype

public void roll(int field, int amount) 

Source Link

Document

Adds the specified (signed) amount to the specified calendar field without changing larger fields.

Usage

From source file:com.siriusit.spezg.multilib.storage.jpa.JpaLoanRepositoryTest.java

@Test
public void testStoreLoanToLoanDB() {
    Person owner = personRepository.findPersonByUsername("JoFerraro");
    Unit film = unitRepository.findUnitsByTitle("Title2").get(0);
    Date dateOut = new Date();
    Calendar deadline = Calendar.getInstance();
    deadline.roll(Calendar.MONTH, 1);
    Loan result = loanRepository.createLoan(owner, film, null, dateOut, deadline.getTime());
    assertTrue(result instanceof Loan);
    assertEquals(film.getDescription(), result.getLoanObject().getDescription());
    assertEquals(owner.getMail(), result.getLoaner().getMail());
}

From source file:com.redhat.rhn.frontend.graphing.test.GraphGeneratorTest.java

private TimeSeriesData[] getTestTimeSeriesData(String metric, int size) {
    TimeSeriesData[] tsd = new TimeSeriesData[size];
    for (int i = 0; i < tsd.length; i++) {
        Calendar start = Calendar.getInstance();
        start.roll(Calendar.HOUR, -3);
        start.add(Calendar.MINUTE, (i * 5));
        Float rnd = new Float(Math.random() * 10);
        tsd[i] = new TimeSeriesData("1-2-test", rnd, start.getTime(), metric);
    }//from   w w  w  . j  a  v a  2  s. co  m
    return tsd;
}

From source file:com.ewintory.footballscores.ui.adapter.PagerAdapter.java

@Override
public CharSequence getPageTitle(int position) {
    Calendar calendar = Calendar.getInstance(Locale.US);
    calendar.roll(Calendar.DAY_OF_WEEK, position - POSITION_TODAY);
    return getDayName(mContext, calendar.getTimeInMillis());
}

From source file:com.ewintory.footballscores.ui.adapter.PagerAdapter.java

@Override
public Fragment getItem(int position) {
    Calendar calendar = Calendar.getInstance(Locale.US);
    calendar.roll(Calendar.DAY_OF_MONTH, position - POSITION_TODAY);
    ScoresFragment fragment = ScoresFragment.newInstance(DATE_FORMAT.format(calendar.getTime()));

    Log.v(TAG, "getItem: position=" + position + ", date=" + DATE_FORMAT.format(calendar.getTime())
            + ((position == POSITION_TODAY) ? "  <---- TODAY" : ""));

    mPageReferenceMap.put(position, fragment);
    return fragment;
}

From source file:org.sipfoundry.sipxconfig.phone.polycom.PhoneUpdateResource.java

@Override
public Representation represent(Variant variant) throws ResourceException {
    String serialNumber = (String) getRequest().getAttributes().get("mac");
    String version = (String) getRequest().getAttributes().get("version");
    String model = (String) getRequest().getAttributes().get("model");
    if (serialNumber == null || version == null || model == null) {
        getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
        return new StringRepresentation(EMPTY);
    }/*from  www  . j a  va2 s.c om*/
    LOG.info(String.format("Trying to updating phone %s to version %s...", serialNumber, version));
    Phone phone = m_phoneContext.loadPhone((m_phoneContext.getPhoneIdBySerialNumber(serialNumber)));
    if (phone == null) {
        getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
        return new StringRepresentation(EMPTY);
    }
    if (!(phone instanceof PolycomPhone)) {
        getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
        return new StringRepresentation(EMPTY);
    }
    DeviceVersion deviceVersion = PolycomModel.getPhoneDeviceVersion(version);
    if (!phone.getDeviceVersion().equals(deviceVersion) || !StringUtils.equals(phone.getModelId(), model)) {
        phone.setDeviceVersion(deviceVersion);
        phone.setModelId(model);
        m_phoneContext.storePhone(phone);
        Calendar c = Calendar.getInstance();
        c.roll(Calendar.MINUTE, 1);
        m_profileManager.generateProfile(phone.getId(), true, c.getTime());
        LOG.info(String.format("Updated phone ID: %d. It will be rebooted in 1 "
                + "minute from now in order to pick up correct config.", phone.getId()));
    }
    LOG.info("Phone not updated - no change.");
    return new StringRepresentation(EMPTY);
}

From source file:org.opencastproject.remotetest.server.FailingPreProcessingWorkflowTest.java

@Test
public void test() throws Exception {
    String workflowId = null;/* w  ww .  j av  a 2 s. c  o m*/
    long TIMEOUT = 1000L;

    // Specify start end end time for capture
    Calendar c = Calendar.getInstance();
    c.roll(Calendar.MINUTE, 2);
    Date start = c.getTime();
    c.roll(Calendar.MINUTE, 1);
    Date end = c.getTime();

    // Schedule and event and make sure the workflow is in "schedule" operation
    workflowId = scheduleEvent(start, end);
    Thread.sleep(1000);
    if (!WorkflowUtils.isWorkflowInOperation(workflowId, "schedule")
            || !WorkflowUtils.isWorkflowInState(workflowId, "PAUSED")) {
        fail("Workflow " + workflowId + " should be on hold in 'schedule'");
    }

    // Pretend to be the capture agent and report a failed capture
    CaptureUtils.setState(workflowId, "capture_error");
    Thread.sleep(TIMEOUT);

    // Make sure both the scheduled operation and the workflow are in "failed" state
    assertTrue(WorkflowUtils.isWorkflowInState(workflowId, "FAILED"));
}

From source file:de.bstreit.java.oscr.business.storage.StorageService.java

@Transactional
public void saveSomeOpenBills() {
    // hard to prevent - we can use fix times here, but the database uses
    // system time.
    // maybe modify query so it gets todays date from outside
    assertTrue("Test does only run during datetime :)",
            new Date().getHours() > 1 && new Date().getHours() < 21);

    final Calendar todayOneHourEarlier = Calendar.getInstance();
    todayOneHourEarlier.roll(Calendar.HOUR_OF_DAY, false);

    final TaxInfo taxInfo = new TaxInfo("19%", null, null);

    final Bill billTodayOneHourEarlier = billTestFactory.create(taxInfo, todayOneHourEarlier.getTime(), null);

    taxInfoRepository.save(taxInfo);//from w ww . j  ava 2 s  . c o m

    billRepository.save(billTodayOneHourEarlier);
}

From source file:org.opencastproject.remotetest.server.FailingPreProcessingWorkflowTest.java

/**
 * Adds a new recording event to the scheduling service and returns the event id.
 * //  w  ww . j av a2 s.  co  m
 * @param start
 *          start date
 * @param end
 *          end date
 * @return the event identifier
 */
private String scheduleEvent(Date start, Date end) throws Exception {
    HttpPut request = new HttpPut(BASE_URL + "/scheduler");

    // Create the request body
    Calendar c = Calendar.getInstance();
    c.roll(Calendar.MINUTE, 1);
    long startTime = c.getTimeInMillis();
    c.roll(Calendar.MINUTE, 1);
    long endTime = c.getTimeInMillis();
    String eventXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><event>"
            + "<contributor>demo contributor</contributor><creator>demo creator</creator>"
            + "<startDate>{start}</startDate><endDate>{stop}</endDate><device>{device}</device>"
            + "<language>en</language><license>creative commons</license><resources>vga, audio</resources>"
            + "<title>demo title</title><additionalMetadata><metadata id=\"0\"><key>location</key>"
            + "<value>demo location</value></metadata><metadata id=\"0\"><key>org.opencastproject.workflow.definition</key>"
            + "<value>" + WORKFLOW_DEFINITION_ID + "</value></metadata></additionalMetadata></event>";
    eventXml = eventXml.replace("{device}", CAPTURE_AGENT_ID).replace("{start}", Long.toString(startTime))
            .replace("{stop}", Long.toString(endTime));

    // Prepare the request
    List<NameValuePair> formParams = new ArrayList<NameValuePair>();
    formParams.add(new BasicNameValuePair("event", eventXml));
    request.setEntity(new UrlEncodedFormEntity(formParams, "UTF-8"));

    // Submit and check the response
    HttpResponse response = client.execute(request);
    assertEquals(HttpStatus.SC_CREATED, response.getStatusLine().getStatusCode());
    String responseBody = StringUtils.trimToNull(EntityUtils.toString(response.getEntity()));
    assertNotNull(responseBody);
    String eventId = StringUtils.trimToNull(
            (String) Utils.xpath(responseBody, "/*[local-name() = 'event']/@id", XPathConstants.STRING));
    assertNotNull("No event id found", eventId);
    return eventId;
}

From source file:de.bstreit.java.oscr.business.storage.StorageService.java

@Transactional
public void saveSomeBills() {
    // hard to prevent - we can use fix times here, but the database uses
    // system time.
    // maybe modify query so it gets todays date from outside
    assertTrue("Test does only run during datetime :)",
            new Date().getHours() > 1 && new Date().getHours() < 21);

    final Calendar yesterdayOneHourEarlier = Calendar.getInstance();
    yesterdayOneHourEarlier.roll(Calendar.DAY_OF_MONTH, false);
    yesterdayOneHourEarlier.roll(Calendar.HOUR_OF_DAY, false);

    final Calendar yesterdayOneHourLater = Calendar.getInstance();
    yesterdayOneHourLater.roll(Calendar.DAY_OF_MONTH, false);
    yesterdayOneHourLater.roll(Calendar.HOUR_OF_DAY, true);

    final Calendar todayOneHourEarlier = Calendar.getInstance();
    todayOneHourEarlier.roll(Calendar.HOUR_OF_DAY, false);

    final Calendar todayOneHourLater = Calendar.getInstance();
    todayOneHourLater.roll(Calendar.HOUR_OF_DAY, true);

    final TaxInfo taxInfo = new TaxInfo("19%", null, null);
    final Bill billYesterdayOneHourEarlier = billTestFactory.create(taxInfo, yesterdayOneHourEarlier.getTime(),
            yesterdayOneHourEarlier.getTime());

    final Bill billYesterdayOneHourLater = billTestFactory.create(taxInfo, yesterdayOneHourLater.getTime(),
            yesterdayOneHourLater.getTime());

    final Bill billTodayOneHourEarlier = billTestFactory.create(taxInfo, todayOneHourEarlier.getTime(),
            todayOneHourEarlier.getTime());

    final Bill billTodayOneHourLater = billTestFactory.create(taxInfo, todayOneHourLater.getTime(),
            todayOneHourLater.getTime());

    taxInfoRepository.save(taxInfo);//from ww  w . j a v  a  2  s.  co m

    billRepository.save(billYesterdayOneHourEarlier);
    billRepository.save(billYesterdayOneHourLater);
    billRepository.save(billTodayOneHourEarlier);
    billRepository.save(billTodayOneHourLater);
}

From source file:nl.surfnet.coin.selfservice.control.StatisticsController.java

@RequestMapping("/stats.shtml")
public String stats(ModelMap model,
        @RequestParam(value = "spEntityId", required = false) final String selectedSp,
        HttpServletRequest request) {//from  ww  w  .ja v  a  2s.  com
    InstitutionIdentityProvider selectedIdp = getSelectedIdp(request);
    model.put(SELECTED_IDP, selectedIdp);
    model.put(SELECTED_SP, selectedSp);

    // default return all statistics for the last two years
    Calendar twoYearsBack = Calendar.getInstance();
    twoYearsBack.roll(YEAR, -2);
    try {
        if (StringUtils.isNotBlank(selectedSp)) {
            model.put("login_stats", cruncher.getLoginsByIdpAndSp(twoYearsBack.getTime(), new Date(),
                    selectedIdp.getId(), selectedSp));
        } else {
            model.put("login_stats",
                    cruncher.getLoginsByIdp(twoYearsBack.getTime(), new Date(), selectedIdp.getId()));
        }
    } catch (RuntimeException e) {
        LOG.warn("exception while contacting cruncher", e);
        return "stats/nostats";
    }
    return "stats/statistics";
}