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

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

Introduction

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

Prototype

public static Date addDays(final Date date, final int amount) 

Source Link

Document

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

Usage

From source file:alfio.manager.system.DataMigratorIntegrationTest.java

@Test
public void testUpdateTicketReservation() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            false, null, null, null, null, null));
    Pair<Event, String> eventUsername = initEvent(categories);
    Event event = eventUsername.getKey();
    try {//from w w  w  . j a v  a 2  s.c  o  m
        TicketReservationModification trm = new TicketReservationModification();
        trm.setAmount(1);
        trm.setTicketCategoryId(eventManager.loadTicketCategories(event).get(0).getId());
        TicketReservationWithOptionalCodeModification r = new TicketReservationWithOptionalCodeModification(trm,
                Optional.empty());
        Date expiration = DateUtils.addDays(new Date(), 1);
        String reservationId = ticketReservationManager.createTicketReservation(event,
                Collections.singletonList(r), Collections.emptyList(), expiration, Optional.empty(),
                Optional.empty(), Locale.ENGLISH, false);
        dataMigrator.fillReservationsLanguage();
        TicketReservation ticketReservation = ticketReservationManager.findById(reservationId).get();
        assertEquals("en", ticketReservation.getUserLanguage());
    } finally {
        eventManager.deleteEvent(event.getId(), eventUsername.getValue());
    }
}

From source file:com.omertron.themoviedbapi.methods.TmdbMoviesTest.java

/**
 * Test of getMovieChanges method, of class TmdbMovies.
 *
 * @throws com.omertron.themoviedbapi.MovieDbException
 *//*from   www.j a v a  2 s  . c  o m*/
@Test
public void testGetMovieChanges() throws MovieDbException {
    LOG.info("getMovieChanges");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String startDate = sdf.format(DateUtils.addDays(new Date(), -14));
    String endDate = "";
    int maxCheck = 5;

    TmdbChanges chgs = new TmdbChanges(getApiKey(), getHttpTools());
    ResultList<ChangeListItem> changeList = chgs.getChangeList(MethodBase.MOVIE, null, null, null);
    LOG.info("Found {} changes to check, will check maximum of {}", changeList.getResults().size(), maxCheck);

    int count = 1;
    ResultList<ChangeKeyItem> result;
    for (ChangeListItem item : changeList.getResults()) {
        result = instance.getMovieChanges(item.getId(), startDate, endDate);
        for (ChangeKeyItem ci : result.getResults()) {
            assertNotNull("Null changes", ci);
        }

        if (count++ > maxCheck) {
            break;
        }
    }
}

From source file:alfio.manager.WaitingQueueManagerIntegrationTest.java

@Test
public void testAssignTicketToWaitingQueueUnboundedCategory() {
    LocalDateTime start = LocalDateTime.now().minusMinutes(1);
    LocalDateTime end = LocalDateTime.now().plusMinutes(20);
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", AVAILABLE_SEATS, new DateTimeModification(start.toLocalDate(), start.toLocalTime()),
            new DateTimeModification(end.toLocalDate(), end.toLocalTime()), DESCRIPTION, BigDecimal.TEN, false,
            "", false, null, null, null, null, null));

    configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_WAITING_QUEUE, "true");

    Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository)
            .getKey();//from ww w.j a va  2  s.c  o m

    TicketCategory unbounded = ticketCategoryRepository.findByEventId(event.getId()).get(0);

    TicketReservationModification tr = new TicketReservationModification();
    tr.setAmount(AVAILABLE_SEATS - 1);
    tr.setTicketCategoryId(unbounded.getId());

    TicketReservationModification tr2 = new TicketReservationModification();
    tr2.setAmount(1);
    tr2.setTicketCategoryId(unbounded.getId());

    TicketReservationWithOptionalCodeModification multi = new TicketReservationWithOptionalCodeModification(tr,
            Optional.empty());
    TicketReservationWithOptionalCodeModification single = new TicketReservationWithOptionalCodeModification(
            tr2, Optional.empty());

    String reservationId = ticketReservationManager.createTicketReservation(event,
            Collections.singletonList(multi), Collections.emptyList(), DateUtils.addDays(new Date(), 1),
            Optional.empty(), Optional.empty(), Locale.ENGLISH, false);
    TotalPrice reservationCost = ticketReservationManager.totalReservationCostWithVAT(reservationId);
    PaymentResult result = ticketReservationManager.confirm("", null, event, reservationId, "test@test.ch",
            new CustomerName("Full Name", "Full", "Name", event), Locale.ENGLISH, "", reservationCost,
            Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null, null);
    assertTrue(result.isSuccessful());

    String reservationIdSingle = ticketReservationManager.createTicketReservation(event,
            Collections.singletonList(single), Collections.emptyList(), DateUtils.addDays(new Date(), 1),
            Optional.empty(), Optional.empty(), Locale.ENGLISH, false);
    TotalPrice reservationCostSingle = ticketReservationManager
            .totalReservationCostWithVAT(reservationIdSingle);
    PaymentResult resultSingle = ticketReservationManager.confirm("", null, event, reservationIdSingle,
            "test@test.ch", new CustomerName("Full Name", "Full", "Name", event), Locale.ENGLISH, "",
            reservationCostSingle, Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null,
            null);
    assertTrue(resultSingle.isSuccessful());

    assertEquals(0, eventRepository.findStatisticsFor(event.getId()).getDynamicAllocation());

    assertTrue(
            waitingQueueManager.subscribe(event, customerJohnDoe(event), "john@doe.com", null, Locale.ENGLISH));

    ticketReservationManager.deleteOfflinePayment(event, reservationIdSingle, false);

    List<Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime>> subscriptions = waitingQueueManager
            .distributeSeats(event).collect(Collectors.toList());
    assertEquals(1, subscriptions.size());
    Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime> subscriptionDetail = subscriptions
            .get(0);
    assertEquals("john@doe.com", subscriptionDetail.getLeft().getEmailAddress());
    TicketReservationWithOptionalCodeModification reservation = subscriptionDetail.getMiddle();
    assertEquals(Integer.valueOf(unbounded.getId()), reservation.getTicketCategoryId());
    assertEquals(Integer.valueOf(1), reservation.getAmount());
    assertTrue(subscriptionDetail.getRight().isAfter(ZonedDateTime.now()));
}

From source file:de.tor.tribes.util.algo.types.TimeFrame.java

public List<Range<Long>> startTimespansToRanges() {
    List<Range<Long>> ranges = new LinkedList<>();
    Date startDate = DateUtils.truncate(new Date(startNotBefore), Calendar.DATE);

    for (TimeSpan span : sendTimeSpans) {
        if (!span.isValidAtEveryDay()) {
            Range<Long> range;
            //just copy range
            if (span.isValidAtExactTime()) {
                range = Range.between(span.getSpan().getMinimum(),
                        span.getSpan().getMaximum() + fixedStartTimeRangeSize);
            } else {
                range = Range.between(span.getSpan().getMinimum(), span.getSpan().getMaximum());
            }//ww w.j  av a  2 s  . com

            if (range.getMaximum() > System.currentTimeMillis()) {
                if (range.getMinimum() <= System.currentTimeMillis()) {
                    //rebuild Range
                    range = Range.between(System.currentTimeMillis(), range.getMaximum());
                }
                //add range only if it is in future
                ranges.add(range);
            }
        } else {
            //span is valid for every day
            Date thisDate = new Date(startDate.getTime());
            //go through all days from start to end
            while (thisDate.getTime() < startNotAfter) {
                long spanStart = thisDate.getTime() + span.getSpan().getMinimum();
                long spanEnd = thisDate.getTime() + span.getSpan().getMaximum();
                Range<Long> newRange = null;
                //check span location relative to start frame
                if (spanStart >= startNotBefore && spanEnd > startNotBefore && spanStart < startNotAfter
                        && spanEnd <= startNotAfter) {
                    //|----------| (startNotBefore - startNotAfter)
                    //  |----| (SpanStart - SpanEnd)
                    newRange = Range.between(spanStart, spanEnd);
                } else if (spanStart < startNotBefore && spanEnd > startNotBefore && spanStart < startNotAfter
                        && spanEnd <= startNotAfter) {
                    //  |----------| (startNotBefore - startNotAfter)
                    //|----| (SpanStart - SpanEnd)
                    //set span start to 'startNotBefore'
                    newRange = Range.between(startNotBefore, spanEnd);
                } else if (spanStart <= startNotBefore && spanEnd > startNotBefore && spanStart > startNotAfter
                        && spanEnd >= startNotAfter) {
                    //  |----------| (startNotBefore - startNotAfter)
                    //|--------------| (SpanStart - SpanEnd)
                    //set span start to 'startNotBefore'
                    newRange = Range.between(startNotBefore, startNotAfter);
                } else if (spanStart >= startNotBefore && spanEnd > startNotBefore && spanStart < startNotAfter
                        && spanEnd >= startNotAfter) {
                    //|----------| (startNotBefore - startNotAfter)
                    //    |---------| (SpanStart - SpanEnd)
                    //set span start to 'startNotBefore'
                    newRange = Range.between(spanStart, startNotAfter);
                }

                if (newRange != null) {
                    if (newRange.getMinimum() < System.currentTimeMillis()) {
                        //check minimum as current minimum is in past
                        if (newRange.getMaximum() > System.currentTimeMillis()) {
                            newRange = Range.between(System.currentTimeMillis(), newRange.getMaximum());
                            ranges.add(newRange);
                        } //ignore as entire range is in past
                    } else {
                        //add range as it is in future
                        ranges.add(newRange);
                    }
                }
                //increment current date by one day
                thisDate = DateUtils.addDays(thisDate, 1);
            }
        }
    }
    Collections.sort(ranges, new Comparator<Range<Long>>() {
        @Override
        public int compare(Range<Long> o1, Range<Long> o2) {
            return o1.getMinimum().compareTo(o2.getMinimum());
        }
    });
    return ranges;
}

From source file:alfio.manager.TicketReservationManagerIntegrationTest.java

@Test
public void testTicketWithDiscount() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            false, null, null, null, null, null));
    Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository)
            .getKey();/* www .j a  v a 2  s.  c o m*/

    TicketCategory unbounded = ticketCategoryRepository.findByEventId(event.getId()).stream()
            .filter(t -> !t.isBounded()).findFirst().orElseThrow(IllegalStateException::new);

    //promo code at event level
    eventManager.addPromoCode("MYPROMOCODE", event.getId(), null, event.getBegin(), event.getEnd(), 10,
            PromoCodeDiscount.DiscountType.PERCENTAGE, null);

    //promo code at organization level
    eventManager.addPromoCode("MYFIXEDPROMO", null, event.getOrganizationId(), event.getBegin(), event.getEnd(),
            5, PromoCodeDiscount.DiscountType.FIXED_AMOUNT, null);

    TicketReservationModification tr = new TicketReservationModification();
    tr.setAmount(3);
    tr.setTicketCategoryId(unbounded.getId());
    TicketReservationWithOptionalCodeModification mod = new TicketReservationWithOptionalCodeModification(tr,
            Optional.empty());

    String reservationId = ticketReservationManager.createTicketReservation(event,
            Collections.singletonList(mod), Collections.emptyList(), DateUtils.addDays(new Date(), 1),
            Optional.empty(), Optional.of("MYPROMOCODE"), Locale.ENGLISH, false);

    TotalPrice totalPrice = ticketReservationManager.totalReservationCostWithVAT(reservationId);

    // 3 * 10 chf is the normal price, 10% discount -> 300 discount
    Assert.assertEquals(2700, totalPrice.getPriceWithVAT());
    Assert.assertEquals(27, totalPrice.getVAT());
    Assert.assertEquals(-300, totalPrice.getDiscount());
    Assert.assertEquals(1, totalPrice.getDiscountAppliedCount());

    OrderSummary orderSummary = ticketReservationManager.orderSummaryForReservationId(reservationId, event,
            Locale.ENGLISH);
    Assert.assertEquals("27.00", orderSummary.getTotalPrice());
    Assert.assertEquals("0.27", orderSummary.getTotalVAT());
    Assert.assertEquals(3, orderSummary.getTicketAmount());

    TicketReservationModification trFixed = new TicketReservationModification();
    trFixed.setAmount(3);
    trFixed.setTicketCategoryId(unbounded.getId());
    TicketReservationWithOptionalCodeModification modFixed = new TicketReservationWithOptionalCodeModification(
            trFixed, Optional.empty());

    String reservationIdFixed = ticketReservationManager.createTicketReservation(event,
            Collections.singletonList(modFixed), Collections.emptyList(), DateUtils.addDays(new Date(), 1),
            Optional.empty(), Optional.of("MYFIXEDPROMO"), Locale.ENGLISH, false);

    TotalPrice totalPriceFixed = ticketReservationManager.totalReservationCostWithVAT(reservationIdFixed);

    // 3 * 10 chf is the normal price, 3 * 5 is the discount
    Assert.assertEquals(2985, totalPriceFixed.getPriceWithVAT());
    Assert.assertEquals(30, totalPriceFixed.getVAT());
    Assert.assertEquals(-15, totalPriceFixed.getDiscount());
    Assert.assertEquals(3, totalPriceFixed.getDiscountAppliedCount());

    OrderSummary orderSummaryFixed = ticketReservationManager.orderSummaryForReservationId(reservationIdFixed,
            event, Locale.ENGLISH);
    Assert.assertEquals("29.85", orderSummaryFixed.getTotalPrice());
    Assert.assertEquals("0.30", orderSummaryFixed.getTotalVAT());
    Assert.assertEquals(3, orderSummaryFixed.getTicketAmount());

}

From source file:alfio.manager.system.DataMigratorIntegrationTest.java

@Test
public void testUpdateGender() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            false, null, null, null, null, null));
    Pair<Event, String> eventUsername = initEvent(categories);
    Event event = eventUsername.getKey();
    try {/*from  www  .ja  v a  2s .  c om*/
        TicketReservationModification trm = new TicketReservationModification();
        trm.setAmount(2);
        trm.setTicketCategoryId(eventManager.loadTicketCategories(event).get(0).getId());
        TicketReservationWithOptionalCodeModification r = new TicketReservationWithOptionalCodeModification(trm,
                Optional.empty());
        Date expiration = DateUtils.addDays(new Date(), 1);
        String reservationId = ticketReservationManager.createTicketReservation(event,
                Collections.singletonList(r), Collections.emptyList(), expiration, Optional.empty(),
                Optional.empty(), Locale.ENGLISH, false);
        ticketReservationManager.confirm("TOKEN", null, event, reservationId, "email@email.ch",
                new CustomerName("Full Name", "Full", "Name", event), Locale.ENGLISH, null,
                new TotalPrice(1000, 10, 0, 0), Optional.empty(), Optional.of(PaymentProxy.ON_SITE), false,
                null, null, null);
        List<Ticket> tickets = ticketRepository.findTicketsInReservation(reservationId);
        UpdateTicketOwnerForm first = new UpdateTicketOwnerForm();
        first.setEmail("email@email.ch");
        //first.setTShirtSize("SMALL");
        //first.setGender("F");
        first.setFirstName("Full");
        first.setLastName("Name");
        UpdateTicketOwnerForm second = new UpdateTicketOwnerForm();
        //second.setTShirtSize("SMALL-F");
        second.setEmail("email@email.ch");
        second.setFirstName("Full");
        second.setLastName("Name");
        PartialTicketPDFGenerator generator = TemplateProcessor.buildPartialPDFTicket(Locale.ITALIAN, event,
                ticketReservationManager.findById(reservationId).get(),
                ticketCategoryRepository.getByIdAndActive(tickets.get(0).getCategoryId(), event.getId()),
                organizationRepository.getById(event.getOrganizationId()), templateManager, fileUploadManager,
                "");
        ticketReservationManager.updateTicketOwner(tickets.get(0), Locale.ITALIAN, event, first, (t) -> "",
                (t) -> "", Optional.empty());
        ticketReservationManager.updateTicketOwner(tickets.get(1), Locale.ITALIAN, event, second, (t) -> "",
                (t) -> "", Optional.empty());
        //FIXME
        //dataMigrator.fillTicketsGender();
        //ticketRepository.findTicketsInReservation(reservationId).forEach(t -> assertEquals("F", t.getGender()));
    } finally {
        eventManager.deleteEvent(event.getId(), eventUsername.getValue());
    }
}

From source file:io.lavagna.service.StatisticsServiceTest.java

@Test
public void getTomorrowMostActiveCardByBoardTest() {
    Card resultCard = statisticsService.getMostActiveCardByBoard(board.getId(), DateUtils.addDays(today, 1));
    Assert.assertNull(resultCard);
}

From source file:com.inkubator.hrm.service.impl.WtScheduleShiftServiceImpl.java

@Override
@Transactional(readOnly = true, isolation = Isolation.REPEATABLE_READ, propagation = Propagation.SUPPORTS, timeout = 50)
public List<Date> getAllWorkingDaysBetween(Long empDataId, Date startDate, Date endDate) throws Exception {
    EmpData empData = empDataDao.getEntiyByPK(empDataId);
    List<Date> workingDays = new ArrayList<Date>();
    List<TempJadwalKaryawan> tempJadwalKaryawans = new ArrayList<TempJadwalKaryawan>();

    //loop date-nya, check jadwal berdasarkan kelompok kerja      
    for (Date loop = startDate; loop.before(endDate)
            || DateUtils.isSameDay(loop, endDate); loop = DateUtils.addDays(loop, 1)) {
        TempJadwalKaryawan jadwal = Lambda.selectFirst(tempJadwalKaryawans,
                Lambda.having(Lambda.on(TempJadwalKaryawan.class).getTanggalWaktuKerja().getTime(),
                        Matchers.equalTo(loop.getTime())));
        if (jadwal == null) {
            //jika tidak terdapat jadwal kerja di date tersebut, maka generate jadwal kerja temporary-nya, lalu check kembali jadwal kerja-nya
            List<TempJadwalKaryawan> jadwalKaryawans = this
                    .getAllScheduleForView(empData.getWtGroupWorking().getId(), loop, null);
            tempJadwalKaryawans.addAll(jadwalKaryawans);
            jadwal = Lambda.selectFirst(tempJadwalKaryawans,
                    Lambda.having(Lambda.on(TempJadwalKaryawan.class).getTanggalWaktuKerja().getTime(),
                            Matchers.equalTo(loop.getTime())));
        }//from ww  w.  j a va  2s .  c om

        //selain "OFF"(hari libur) berarti termasuk jam kerja
        if (jadwal != null) {
            if (!StringUtils.equals(jadwal.getWtWorkingHour().getCode(), "OFF")) {
                workingDays.add(jadwal.getTanggalWaktuKerja());
            }
        }

    }
    return workingDays;
}

From source file:gov.nih.nci.firebird.service.annual.registration.AnnualRegistrationServiceBean.java

@SuppressWarnings("unchecked")
// Hibernate list() method is untyped
private List<AnnualRegistration> getRegistrationsRequiringRenewal() {
    Date renewalDate = DateUtils.addDays(new Date(), daysBeforeDueDateToSendFirstNotification);
    Query query = getSession().createQuery(REGISTRATIONS_REQUIRING_RENEWAL_HQL);
    query.setDate("renewalDate", renewalDate);
    return query.list();
}

From source file:io.lavagna.service.StatisticsServiceTest.java

@Test
public void getTomorrowMostActiveCardByProjectTest() {
    Card resultCard = statisticsService.getMostActiveCardByProject(board.getProjectId(),
            DateUtils.addDays(today, 1));
    Assert.assertNull(resultCard);/*w  w w.  j av a  2 s. c om*/
}