Java Code Examples for org.joda.time.LocalDate.plusDays()

The following are Jave code examples for showing how to use plusDays() of the org.joda.time.LocalDate class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: yum   File: DailyMenuService.java   Source Code and License Vote up 6 votes
/**
 * @return a list to the chef, of Daily Menus of the current month
 */
@PreAuthorize("hasAuthority('chef')")
public List<DailyMenuChef> dailyMenusMonthlyGet()
{

    LocalDate today = LocalDate.now();
    LocalDate startOfMonth = today.dayOfMonth().withMinimumValue();
    int daysOfMonth = today.dayOfMonth().withMaximumValue().getDayOfMonth();
    List<DailyMenuChef> monthlyMenu = new ArrayList<>();
    for (int i = 0; i < daysOfMonth; i++)
    {
        if (getDailyMenuChef(startOfMonth).getDate() != null)
            monthlyMenu.add(getDailyMenuChef(startOfMonth));
        startOfMonth = startOfMonth.plusDays(1);
    }
    return monthlyMenu;
}
 
Example 2
Project: yum   File: DailyMenuService.java   Source Code and License Vote up 6 votes
/**
 * @return a list to the chef, of Daily Menus of month & year he wants
 */
@PreAuthorize("hasAuthority('chef')")
public List<DailyMenuChef> dailyMenusMonthlyMonthyearGet(String monthyear) throws ApiException
{
    String patternString = "^\\d{2}-\\d{4}$";
    java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(patternString);
    Matcher matcher = pattern.matcher(monthyear);
    if (matcher.matches())
    {
        LocalDate monthYearDate = new LocalDate().withYear(Integer.parseInt(monthyear.substring(3, 7))).withMonthOfYear(Integer.parseInt(monthyear.substring(0, 2)));
        LocalDate startOfMonth = monthYearDate.dayOfMonth().withMinimumValue();
        int daysOfMonth = monthYearDate.dayOfMonth().withMaximumValue().getDayOfMonth();
        List<DailyMenuChef> monthlyMenu = new ArrayList<>();
        for (int i = 0; i < daysOfMonth; i++)
        {
            if (getDailyMenuChef(startOfMonth).getDate() != null)
                monthlyMenu.add(getDailyMenuChef(startOfMonth));
            startOfMonth = startOfMonth.plusDays(1);
        }
        return monthlyMenu;
    }
    else
        throw new ApiException(400, "Invalid date");
}
 
Example 3
Project: moneytracking   File: MoneyReminder.java   Source Code and License Vote up 6 votes
private Date createPlannedDate(String type, Date d) {
    LocalDate lo = LocalDate.fromDateFields(d);
    switch (type) {
        case "Daily":
            lo = lo.plusDays(1);
            break;
        case "Weekly":
            lo = lo.plusWeeks(1);
            break;
        case "Monthly":
            lo = lo.plusMonths(1);
            break;
        case "Yearly":
            lo = lo.plusYears(1);
            break;
    }
    return lo.toDate();
}
 
Example 4
Project: yum   File: ReportEmail.java   Source Code and License Vote up 5 votes
private void sendAutoOrderSummary(){
        
        System.out.println("RUN TASK SCHEDULE: " + LocalDateTime.now());
        
        //Get deadline days
        Settings settings = settingsRepo.findById(1);
        
        int deadlinedays = settings.getDeadlineDays();
        LocalDate day = new LocalDate();
        
        if(this.holidaysRepo.findByIdHoliday(day) != null){
            return;
        }
                 
        LocalDate initDate = (day).plusDays(deadlinedays);
//        while (this.holidaysRepo.findByIdHoliday(initDate) != null) {
//            initDate = initDate.plusDays(1);
//        }
        
        LocalDate maxCheckdate = (initDate).plusDays(deadlinedays);
        while (this.holidaysRepo.findByIdHoliday(maxCheckdate) != null) {
            maxCheckdate = maxCheckdate.plusDays(1);
        }

        int checkDays = Days.daysBetween((new LocalDate()), maxCheckdate).getDays() + deadlinedays;
        
        for (int i = 0; i <= checkDays; i++) { //newDeadlineDays
            LocalDate dailyMenuDate = initDate.plusDays(i);
            // if old deadline not passed and new deadline passed and dailyMenu not null, send report email
            if (menusService.deadlinePassed(dailyMenuDate) && dailyMenuRepo.findByDate(dailyMenuDate) != null) { //
                //System.out.println(">>>>>>>>>>>>>sending email, date: " + dailyMenuDate); 
                eService.sendOrderSummary(dailyMenuDate);
            }
        }

    }
 
Example 5
Project: mock-interceptor   File: AbstractMockedApiInterceptor.java   Source Code and License Vote up 5 votes
@Override
public String replaceOneString(String body, Request request) {
    Matcher dateMatcher = DATE.matcher(body);
    dateMatcher.find();
    String match = dateMatcher.group();
    Map<String, String> query = getQueryFromUri(match);
    LocalDate date = new LocalDate();
    if(query.containsKey(OFFSET_PARAMETER)) {
        date = date.plusDays(Integer.parseInt(query.get(OFFSET_PARAMETER)));
    }
    body = dateMatcher.replaceFirst(date.toString());
    return body;
}
 
Example 6
Project: exam   File: CalendarController.java   Source Code and License Vote up 5 votes
@Restrict({@Group("ADMIN"), @Group("STUDENT")})
public Result getSlots(Long examId, Long roomId, String day, Collection<Integer> aids) {
    User user = getLoggedUser();
    Exam exam = getEnrolledExam(examId, user);
    if (exam == null) {
        return forbidden("sitnet_error_enrolment_not_found");
    }
    ExamRoom room = Ebean.find(ExamRoom.class, roomId);
    if (room == null) {
        return forbidden(String.format("No room with id: (%d)", roomId));
    }
    Collection<TimeSlot> slots = new ArrayList<>();
    if (!room.getOutOfService() && !room.getState().equals(ExamRoom.State.INACTIVE.toString()) &&
            isRoomAccessibilitySatisfied(room, aids) && exam.getDuration() != null) {
        LocalDate searchDate;
        try {
            searchDate = parseSearchDate(day, exam, room);
        } catch (NotFoundException e) {
            return notFound();
        }
        // users reservations starting from now
        List<Reservation> reservations = Ebean.find(Reservation.class)
                .fetch("enrolment.exam")
                .where()
                .eq("user", user)
                .gt("startAt", searchDate.toDate())
                .findList();
        // Resolve eligible machines based on software and accessibility requirements
        List<ExamMachine> machines = getEligibleMachines(room, aids, exam);
        LocalDate endOfSearch = getEndSearchDate(exam, searchDate);
        while (!searchDate.isAfter(endOfSearch)) {
            Set<TimeSlot> timeSlots = getExamSlots(user, room, exam, searchDate, reservations, machines);
            if (!timeSlots.isEmpty()) {
                slots.addAll(timeSlots);
            }
            searchDate = searchDate.plusDays(1);
        }
    }
    return ok(Json.toJson(slots));
}
 
Example 7
Project: exam   File: ExternalCalendarController.java   Source Code and License Vote up 5 votes
@SubjectNotPresent
public Result provideSlots(Optional<String> roomId, Optional<String> date, Optional<String> start, Optional<String> end,
                           Optional<Integer> duration) {
    if (roomId.isPresent() && date.isPresent() && start.isPresent() && end.isPresent() && duration.isPresent()) {
        ExamRoom room = Ebean.find(ExamRoom.class).where().eq("externalRef", roomId.get()).findUnique();
        if (room == null) {
            return forbidden(String.format("No room with ref: (%s)", roomId.get()));
        }
        Collection<TimeSlot> slots = new ArrayList<>();
        if (!room.getOutOfService() && !room.getState().equals(ExamRoom.State.INACTIVE.toString())) {
            LocalDate searchDate;
            try {
                searchDate = parseSearchDate(date.get(), start.get(), end.get(), room);
            } catch (NotFoundException e) {
                return notFound();
            }
            List<ExamMachine> machines = Ebean.find(ExamMachine.class)
                    .where()
                    .eq("room.id", room.getId())
                    .ne("outOfService", true)
                    .ne("archived", true)
                    .findList();
            LocalDate endOfSearch = getEndSearchDate(end.get(), searchDate);
            while (!searchDate.isAfter(endOfSearch)) {
                Set<TimeSlot> timeSlots = getExamSlots(room, duration.get(), searchDate, machines);
                if (!timeSlots.isEmpty()) {
                    slots.addAll(timeSlots);
                }
                searchDate = searchDate.plusDays(1);
            }
        }
        return ok(Json.toJson(slots));
    } else {
        return badRequest();
    }
}
 
Example 8
Project: mobile-app-dev-book   File: MonthlyFragment.java   Source Code and License Vote up 5 votes
@Override
public void onJournalUpdated(List<Trip> trips) {
    tripDays.clear();
    for (Trip t : trips) {
        LocalDate d = DateTime.parse(t.getStartDate()).toLocalDate();
        LocalDate endDate = DateTime.parse(t.getEndDate()).toLocalDate();
        while (!d.isAfter(endDate)) {
            tripDays.add(d);
            d = d.plusDays(1);
        }
    }
    monthly.invalidateDecorators();
}
 
Example 9
Project: yum   File: ChefOrdersService.java   Source Code and License Vote up 4 votes
public List<DailyMenuOrder> ordersMonthlyMonthyearGet(String monthyear) throws ApiException {
   
    //Decode & Validate month request
    String patternString = "^(\\d{2})-(\\d{4})$";
    Pattern pattern =  Pattern.compile(patternString);
    Matcher matcher = pattern.matcher(monthyear);
    if (!matcher.matches()) { 
        throw new ApiException(400, "Bad request of month-year format");
    }
    
    //Build list
    List<DailyMenuOrder> dailyMenuOrders = new ArrayList<>();
    
    //LocalDate monthYearDate = new LocalDate().withYear(Integer.parseInt(monthyear.substring(3, 7))).withMonthOfYear(Integer.parseInt(monthyear.substring(0, 2)));
    LocalDate monthYearDate = new LocalDate().withYear(Integer.parseInt(matcher.group(2))).withMonthOfYear(Integer.parseInt(matcher.group(1)));
    LocalDate startOfMonth = monthYearDate.dayOfMonth().withMinimumValue();
    int daysOfMonth = monthYearDate.dayOfMonth().withMaximumValue().getDayOfMonth();
    
    // for each day of month
    for (int i=0; i<daysOfMonth; i++) {
        
        com.jrtechnologies.yum.data.entity.DailyMenu dailyMenuEntity = dailyMenuRep.findByDate(startOfMonth);
 
        if(dailyMenuEntity!=null && dailyMenuEntity.hasOrders()){
            
            // DailymenuOrder-->OrderItems
            List<OrderItem> orderItemList = new ArrayList<OrderItem>(); 
            DailyMenuOrder dailyOrder = new DailyMenuOrder();
            
            dailyOrder.setDailyMenuDate(dailyMenuEntity.getDate());
            dailyOrder.setDailyMenuId(dailyMenuEntity.getId());
            
            //get summary of daily orders in a list of orders,  food id + quantity
            orderItemList = getOrderItemList(dailyMenuEntity, ALL_USERS);
            
            dailyOrder.setOrderItems(orderItemList);
            dailyMenuOrders.add(dailyOrder);
        }
     
        startOfMonth = startOfMonth.plusDays(1);
    }
    
        
    return dailyMenuOrders;
    
}