Example usage for org.apache.commons.lang.time DateUtils addDays

List of usage examples for org.apache.commons.lang.time DateUtils addDays

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DateUtils addDays.

Prototype

public static Date addDays(Date date, int amount) 

Source Link

Document

Adds a number of days to a date returning a new object.

Usage

From source file:de.hybris.platform.btg.condition.impl.BtgOrderOperandValueProviderTest.java

@Test
public void testNumberOfOrdersEvaluation() throws Exception {
    userService.setCurrentUser(customerA);
    final BTGNumberOfOrdersOperandModel numberOfOrdersOperand = createNumberOfOrdersOperand(
            BTGNumberOfOrdersOperandModel.class, "Test", DateUtils.addDays(new Date(), -1),
            DateUtils.addDays(new Date(), +1));
    Assert.assertEquals("Test", Integer.valueOf(0),
            operandValueProviderRegistry.getOperandValueProvider(numberOfOrdersOperand.getClass())
                    .getValue(numberOfOrdersOperand, customerA, null));

    placeTestOrder(AUGISTINER);/*from  w  w  w .ja va2  s  . c  o m*/
    Assert.assertEquals("Test2", Integer.valueOf(1),
            operandValueProviderRegistry.getOperandValueProvider(numberOfOrdersOperand.getClass())
                    .getValue(numberOfOrdersOperand, customerA, null));

    placeTestOrder(AUGISTINER);
    Assert.assertEquals("Test3", Integer.valueOf(2),
            operandValueProviderRegistry.getOperandValueProvider(numberOfOrdersOperand.getClass())
                    .getValue(numberOfOrdersOperand, customerA, null));

}

From source file:cn.vlabs.duckling.aone.infrastructure.repository.MessageDAOTest.java

@Test
public void testCreateMessage() {
    Date now = new Date();
    Date today = DateUtils.truncate(now, Calendar.DAY_OF_MONTH);
    Date tommrow = DateUtils.truncate(DateUtils.addDays(now, 1), Calendar.DAY_OF_MONTH);

    MessageBody body = createMessage(now);
    Publisher publisher = createPublisher(Publisher.PAGE_TYPE);

    int messageId = md.createMessage(tid, body, publisher, new String[] { "liji@cnic.cn", "xiejj@cnic.cn" });
    try {// w  ww. j  a v a  2s  .  c  o  m

        List<Message> message = md.getMessage(tid, "xiejj@cnic.cn", today, tommrow);

        assertNotNull("Must be one message", message);
        assertEquals("Only one message", 1, message.size());
        assertEquals("Title expected", "New message from column A", message.get(0).getBody().getTitle());
    } finally {
        md.removeMessage(messageId);
    }
}

From source file:com.haulmont.timesheets.global.ValidationTools.java

public HoursAndMinutes workHoursForPeriod(Date start, Date end, User user) {
    HoursAndMinutes dayHourPlan = HoursAndMinutes
            .fromBigDecimal(workTimeConfigBean.getUserWorkHourForDay(user));
    HoursAndMinutes totalWorkHours = new HoursAndMinutes();

    for (; start.getTime() <= end.getTime(); start = DateUtils.addDays(start, 1)) {
        if (workdaysTools.isWorkday(start)) {
            totalWorkHours.add(dayHourPlan);
        }/*from w  w  w. j  a va 2s .  c  om*/
    }
    return totalWorkHours;
}

From source file:net.big_oh.resourcestats.dao.ResourceDAO.java

public LinkedHashMap<Resource, Number> getMostPopularResources(int maxNumResources, int lastNDays)
        throws IllegalArgumentException {
    Date now = new Date();
    Date nDaysAgo = DateUtils.addDays(now, -1 * Math.abs(lastNDays));
    return getMostPopularResources(maxNumResources, nDaysAgo);
}

From source file:net.audumla.climate.DataSourceTest.java

@Test
public void testHistoricalCall() {
    Date now = new Date();
    ClimateData cd = getData(DateUtils.addDays(now, -30));
    cd.getMaximumTemperature();//from   w w  w .ja v a2s.c  o  m
    Assert.assertEquals(cd.getDataSource().getType(),
            ClimateDataSource.ClimateDataSourceType.DAILY_OBSERVATION);

}

From source file:com.hs.mail.imap.schedule.MessageCompressor.java

public void compress(String prop, long timeLimit) {
    Date base = ScheduleUtils.getDateBefore(prop);
    if (base != null) {
        Date start = getStartDate(base);
        if (start != null) {
            Date date = start;//from   w  ww . j a v a  2s. co  m
            if (logger.isDebugEnabled()) {
                logger.debug("Compressing directories from " + DateFormatUtils.ISO_DATE_FORMAT.format(start)
                        + " to " + DateFormatUtils.ISO_DATE_FORMAT.format(base));
            }
            while (date.before(base) && System.currentTimeMillis() < timeLimit) {
                compressDirectories(date, timeLimit);
                date = DateUtils.addDays(date, 1);
            }
        }
    }
}

From source file:hudson.plugins.simpleupdatesite.model.RssEntry.java

/**
 * Check if the entry is new//from   w w w. j a  va 2s.  c  om
 * 
 * @return Return true if the news is updated after 2 week ago.
 */
public boolean isNew() {
    Date previousDate = DateUtils.addDays(new Date(), -14);
    return previousDate.before(getUpdatedDate());
}

From source file:net.audumla.climate.MockObserverTest.java

@Test
public void testMock() {
    Date now = new Date();
    now = DateUtils.setMonths(now, 9);/*from   w w  w .ja  v  a 2 s  . c  o m*/
    now = DateUtils.setDays(now, 1);

    ClimateObserver observer = new MockObserverClassDefinition();
    ClimateObserverCollectionHandler aggregateObserver = new ClimateObserverCollectionHandler(
            observer.getSource());
    aggregateObserver.addClimateObserverTop(observer);
    aggregateObserver.addClimateObserverTail(new DerivedClimateObserver(observer.getSource()));
    observer = aggregateObserver.buildClimateObserver();
    ClimateData data = observer.getClimateData(now);
    while (data != null && DateUtils.getFragmentInDays(now, Calendar.MONTH) < 29) {
        //            logger.debug(data.getTime()+" - " +data.getEvapotranspiration());

        now = DateUtils.addDays(now, 1);
        data = observer.getClimateData(now);
    }
}

From source file:ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceGroupEntityTest.java

@Test
public void testGetNewestRelease() {
    //given //from   w  w  w .j av a  2  s.co  m
    Date now = new Date();
    ResourceEntity newestResource = createResourceForRelease(DateUtils.addDays(now, 1));
    ResourceEntity currentResource = createResourceForRelease(now);
    ResourceEntity earlyResource = createResourceForRelease(DateUtils.addDays(now, -1));
    resourceGroup.setResources(
            new HashSet<ResourceEntity>(Arrays.asList(newestResource, currentResource, earlyResource)));

    //when
    ReleaseEntity rel = resourceGroup.getNewestRelease();

    //then
    Assert.assertEquals(newestResource.getRelease(), rel);
}

From source file:com.lhy.commons.encrypt.service.EncryptService.java

@Override
public File createLicenseFile(License license, String licenseFilePath) {
    License licObj = new License();
    licObj.setIpAddress(DigestUtils.sha512Hex(license.getIpAddress()));
    licObj.setLicenseID(license.getLicenseID());
    licObj.setLicenseType(license.getLicenseType());
    licObj.setStopTime(//from   ww  w.  j  av  a2  s .  c om
            license.getStopTime() == null ? DateUtils.addDays(new Date(), 30) : license.getStopTime());
    File licenseFile = null;
    try {
        licenseFile = new File(licenseFilePath + File.separator + LicenseFileName);
        ObjectOutput out = new ObjectOutputStream(new FileOutputStream(licenseFile));
        out.writeObject(licObj);
        out.close();
    } catch (FileNotFoundException e) {
        log.error(e.getMessage());
    } catch (IOException e) {
        log.error(e.getMessage());
    }
    return licenseFile;
}