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:com.comcast.cats.monitor.reboot.BarcelonaRebootMonitor.java

/**
 * Calculates the uptime of the box.//from ww w  . j  a  va 2  s  .c  om
 */
private long calculateUptime(String upTimeDays, String upTimehours)
        throws ParseException, NumberFormatException {
    Date actualUptime = DateUtils.parseDate(upTimehours, EXPECTED_DATE_FORMATS);

    if (upTimeDays != null) {
        actualUptime = DateUtils.addDays(actualUptime, Integer.parseInt(upTimeDays));
    }

    Calendar cal = Calendar.getInstance();
    cal.setTime(actualUptime);
    cal.getTimeInMillis();

    long upTimemillis = (cal.get(Calendar.HOUR_OF_DAY) * 60 * 60 * 1000)
            + (cal.get(Calendar.MINUTE) * 60 * 1000) + (cal.get(Calendar.SECOND) * 1000)
            + (cal.get(Calendar.MILLISECOND));

    return upTimemillis;
}

From source file:de.knowwe.defi.time.TimeTableUtilities.java

/**
 * Generate timetable content for user./*from  www  .ja v a2 s . c  o  m*/
 */
private static String generatePersonalTimeTableContent(UserProfile user) {
    // TODO: Zeitzone englisch deutsch: CET <> MEZ, eventuell
    // Userdatabase anpassen, Server: CET, Lokal: MEZ
    Date created = UserUtilities.getCreated(user);
    if (created == null)
        throw new NullPointerException("Create date is null or couldn't be read");

    String content = "%%Zeitplan" + System.getProperty("line.separator");
    created = DateUtils.truncate(created, Calendar.DAY_OF_MONTH);
    for (Integer days : getTimeTableTemplate()) {
        Date d = DateUtils.addDays(created, days);
        content += DateT.dateFormat.format(d) + System.getProperty("line.separator");
    }
    content += "%";
    content += System.getProperty("line.separator");

    return content;
}

From source file:com.qcloud.project.macaovehicle.web.handler.impl.ProfilesSuccessHandlerImpl.java

@Override
public List<ProfilesSuccessVO> toVehicleVOList(List<ProfilesSuccess> list) {

    List<ProfilesSuccessVO> voList = new ArrayList<ProfilesSuccessVO>();
    if (list == null)
        return new ArrayList<ProfilesSuccessVO>();
    for (ProfilesSuccess p : list) {
        String json = Json.toJson(p);
        ProfilesSuccessVO vo = Json.toObject(json, ProfilesSuccessVO.class, true);
        stateHelper.handlerToBusiness(p.getVehicleId(), vo.getTypeList(), vo.getAvailTypeList());
        // ==============================================================================================
        Long vehicleId = p.getVehicleId();
        ProfilesSuccessQuery query = new ProfilesSuccessQuery();
        query.setVehicleId(vehicleId);/* w ww .  j  ava2  s . c  o  m*/
        query.setGroupByStr("driverId");
        query.setvEnable(EnableType.ENABLE.getKey());
        // 
        List<ProfilesSuccess> profilesSuccesses = profilesSuccessService.listByQuery(query);
        String vehicleInfo = "";
        String driverInfo = "";
        String ownName = "";
        String validDateStr = null;
        int dayCount = 0;
        Vehicle vehicle = vehicleService.get(p.getVehicleId());
        for (ProfilesSuccess profilesSuccess : profilesSuccesses) {
            Driver driver = driverService.get(profilesSuccess.getDriverId());
            AssertUtil.assertNotNull(vehicle, "?." + vehicle.getId());
            AssertUtil.assertNotNull(driver, "??." + driver.getId());
            vehicleInfo = vehicle.getPlateNumber() + "," + vehicle.getColor() + "," + vehicle.getBrand() + ","
                    + vehicle.getSpecification();
            driverInfo = driver.getDriverName() + ",";
            if (StringUtils.isEmpty(ownName)) {
                ownName = vehicle.getOwnerName();
            }
            // 180
            if (validDateStr == null) {
                AssertUtil.assertNotNull(vehicle.getApproveTime(), "?.");
                Date validDate = DateUtils.addDays(vehicle.getApproveTime(), Constant.VEHICLE_VALID_TIME);
                validDateStr = DateUtil.date2String(validDate, "yyyy-MM-dd");
                dayCount = DateUtil.getDayCount(validDate, new Date());
            }
        }
        if (driverInfo.length() > 0) {
            driverInfo = driverInfo.substring(0, driverInfo.length() - 1);
        }
        Map<String, Object> returnMap = new HashMap<String, Object>();
        returnMap.put("vehicleInfo", vehicleInfo);
        returnMap.put("ownName", ownName);
        returnMap.put("validDateStr", validDateStr);
        returnMap.put("dayCount", dayCount);
        returnMap.put("driverInfo", driverInfo);
        returnMap.put("type", 1);
        returnMap.put("vehicleId", list.get(0).getVehicleId());
        vo.setReturnMap(returnMap);
        voList.add(vo);
    }
    return voList;
}

From source file:ch.puzzle.itc.mobiliar.business.releasing.control.ReleaseMgmtPersistenceServiceTest.java

@Test
public void test_getDefaultRelease() throws GeneralDBException {
    releaseEntity.setInstallationInProductionAt(DateUtils.addDays(new Date(), -2));
    ReleaseEntity secondEntity = new ReleaseEntity();
    secondEntity.setInstallationInProductionAt(DateUtils.addDays(new Date(), 2));

    service.saveReleaseEntity(secondEntity);
    service.saveReleaseEntity(releaseEntity);

    // when/*  w  w  w  . j  a  v  a 2 s  .c om*/
    ReleaseEntity release = service.getDefaultRelease();

    // then
    assertEquals(releaseEntity, release);
}

From source file:com.silverpeas.admin.UsersAndGroupsTest.java

@Test
public void shouldAddNewUser() {
    Date now = new Date();
    Date tosAcceptanceDate = DateUtils.addDays(now, 1);
    Date lastLoginDate = DateUtils.addDays(now, 2);
    Date lastLoginCredentialUpdateDate = DateUtils.addDays(now, 3);
    Date expirationDate = DateUtils.addDays(now, 4);
    Date stateSaveDate = DateUtils.addDays(now, 5);

    UserDetail user = new UserDetail();
    user.setAccessLevel(UserAccessLevel.ADMINISTRATOR);
    user.setDomainId("0");
    user.seteMail("nicolas.eysseric@silverpeas.com");
    user.setFirstName("Nicolas");
    user.setLastName("EYSSERIC");
    user.setLogin("neysseri");
    user.setTosAcceptanceDate(tosAcceptanceDate);
    user.setLastLoginDate(lastLoginDate);
    user.setNbSuccessfulLoginAttempts(7);
    user.setLastLoginCredentialUpdateDate(lastLoginCredentialUpdateDate);
    user.setExpirationDate(expirationDate);
    user.setState(UserState.EXPIRED);/*from   w w w.j a  va 2s .  com*/
    user.setStateSaveDate(stateSaveDate);

    String newUserId = "5";
    AdminController ac = getAdminController();
    String userId = ac.addUser(user);
    assertThat(userId, is(newUserId));

    user = ac.getUserDetail(newUserId);
    assertThat(user.getAccessLevel(), is(UserAccessLevel.ADMINISTRATOR));
    assertThat(user.getSaveDate(), greaterThan(now));
    assertThat(user.getVersion(), is(0));
    assertThat(user.getTosAcceptanceDate().getTime(), is(tosAcceptanceDate.getTime()));
    assertThat(user.getLastLoginDate().getTime(), is(lastLoginDate.getTime()));
    assertThat(user.getNbSuccessfulLoginAttempts(), is(7));
    assertThat(user.getLastLoginCredentialUpdateDate().getTime(), is(lastLoginCredentialUpdateDate.getTime()));
    assertThat(user.getExpirationDate().getTime(), is(expirationDate.getTime()));
    assertThat(user.getState(), is(UserState.EXPIRED));
    assertThat(user.getStateSaveDate(), greaterThan(now));
}

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

@Test
public void testYesterdaysRainfall() throws Exception {
    Date now = new Date();
    ClimateData cd = getData(DateUtils.addDays(now, -1));
    cd.getRainfall();/*from w w w.j  av  a 2s. c o m*/
    Assert.assertEquals(cd.getDataSource().getType(),
            ClimateDataSource.ClimateDataSourceType.DAILY_OBSERVATION);

}

From source file:net.sf.sze.service.impl.common.AnonymisierungsServiceImpl.java

/**
 * {@inheritDoc}/*from w w  w  .j av  a 2  s. co m*/
 */
@Override
public void anonymisierSchueler() {
    final Iterable<Schueler> allSchueler = schuelerDao.findAll();
    int i = 0;
    for (Schueler schueler : allSchueler) {
        if (Geschlecht.WEIBLICH.equals(schueler.getGeschlecht())) {
            schueler.setVorname(MAEDCHEN_NAMEN[i % MAEDCHEN_NAMEN.length]);
        } else {
            schueler.setVorname(JUNGS_NAMEN[i % JUNGS_NAMEN.length]);
        }
        schueler.setName(NACHNAMEN[i % NACHNAMEN.length]);
        schueler.setRufname(null);
        int dayDiff = RandomUtils.nextInt(360) - 180;
        if (dayDiff == 0) {
            dayDiff = 1;
        }
        if (schueler.getAufnahmeDatum() != null) {
            schueler.setAufnahmeDatum(DateUtils.addDays(schueler.getAufnahmeDatum(), dayDiff));
        }
        schueler.setGeburtstag(DateUtils.addDays(schueler.getGeburtstag(), dayDiff));
        schueler.setGeburtsort("Erde " + schueler.getId());
        schuelerDao.save(schueler);
        i++;
    }

}

From source file:action.OnlineBookingAction.java

@Actions({ @Action(value = "/goOnlineBookingRooms", results = {
        @Result(name = "success", location = "/WEB-INF/jsp/online/widget2.jsp"),
        @Result(name = "input", location = "/WEB-INF/jsp/online/validationError.jsp") }) })
public String goOnlineBookingRooms() {
    Structure structure = null;// ww  w  .  ja va2  s  . c  o m
    List<Room> rooms = null;
    List<Image> images = null;
    Booking booking = null;
    Date dateOut = null;
    Convention defaultConvention = null;

    structure = (Structure) this.getSession().get("structure");
    this.setStructure(structure);
    this.setIdStructure(structure.getId());

    booking = (Booking) this.getSession().get("onlineBooking");

    booking.setNrGuests(this.getBooking().getNrGuests());
    booking.setDateIn(this.getBooking().getDateIn());

    dateOut = DateUtils.addDays(booking.getDateIn(), this.getNumNights());
    booking.setDateOut(dateOut);

    for (Convention each : this.getConventionService().findConventionsByIdStructure(structure.getId())) {
        if (each.getActivationCode().equals("thisconventionshouldntneverberemoved")) {
            defaultConvention = each;
        }
    }
    booking.setConvention(defaultConvention);
    booking.setId_convention(defaultConvention.getId());

    this.setRooms(new ArrayList<Room>());

    rooms = new ArrayList<Room>();
    for (Room each : this.getRoomService().findRoomsByIdStructure(structure.getId())) {
        if ((each.getRoomType().getMaxGuests() >= booking.getNrGuests())
                && this.getStructureService().hasRoomFreeInPeriod(structure.getId(), each.getId(),
                        booking.getDateIn(), booking.getDateOut())) {
            booking.setRoom(each);
            each.setPrice(this.calculateTotalForBooking(structure.getId(), booking));
            images = new ArrayList<Image>();
            images = this.getImageService().findCheckedByIdRoom(each.getId(), 0, 10);
            each.setImages(images);
            rooms.add(each);
        }
    }
    booking.setRoom(null);
    this.setRooms(rooms);
    this.setBooking(booking);
    return SUCCESS;
}

From source file:info.magnolia.cms.core.MetaDataTest.java

@Test
public void testGetActivationStatusReturnsActivatedWhenActivatedAndThenModified() throws RepositoryException {
    Calendar today = Calendar.getInstance();
    Calendar yesterday = Calendar.getInstance();
    yesterday.setTime(DateUtils.addDays(new Date(), -1));

    root.setProperty(NodeTypes.Activatable.ACTIVATION_STATUS, true);
    root.setProperty(NodeTypes.Activatable.LAST_ACTIVATED, yesterday);
    root.setProperty(NodeTypes.LastModified.LAST_MODIFIED, today);
    assertEquals(NodeTypes.Activatable.ACTIVATION_STATUS_MODIFIED, new MetaData(root).getActivationStatus());
}

From source file:model.Booking.java

public List<Date> calculateBookingDates() { //Creates an array of dates, related with the stay
    List<Date> bookingDates = null;
    Date current = null;/*from ww w. ja  v  a  2 s  . c  om*/
    Integer i = 0;

    bookingDates = new ArrayList<Date>();
    if (this.getDateIn() != null && this.getDateOut() != null) {
        current = DateUtils.addDays(this.getDateIn(), i);
        while (DateUtils.truncatedCompareTo(current, this.getDateOut(), Calendar.DAY_OF_MONTH) < 0) {
            bookingDates.add(current);
            i = i + 1;
            current = DateUtils.addDays(this.getDateIn(), i);
        }
    }

    return bookingDates;
}