Example usage for org.joda.time LocalDate plusDays

List of usage examples for org.joda.time LocalDate plusDays

Introduction

In this page you can find the example usage for org.joda.time LocalDate plusDays.

Prototype

public LocalDate plusDays(int days) 

Source Link

Document

Returns a copy of this date plus the specified number of days.

Usage

From source file:pt.ist.expenditureTrackingSystem.domain.acquisitions.RegularAcquisitionProcess.java

License:Open Source License

public void unSkipSupplierFundAllocation() {
    checkSupplierLimit();//  w ww  .  j  a v  a 2 s. co m
    super.setSkipSupplierFundAllocation(Boolean.FALSE);
    if (!getAcquisitionProcessState().isInGenesis()) {
        LocalDate now = new LocalDate();
        setFundAllocationExpirationDate(now.plusDays(90));
    }
}

From source file:pt.ist.expenditureTrackingSystem.domain.acquisitions.simplified.activities.FundAllocationExpirationDate.java

License:Open Source License

@Override
protected void process(CreateAcquisitionPurchaseOrderDocumentInformation activityInformation) {
    RegularAcquisitionProcess process = activityInformation.getProcess();
    if (process.getAcquisitionRequest().isSubmittedForFundsAllocationByAllResponsibles()) {
        if (!process.getShouldSkipSupplierFundAllocation()) {
            checkSupplierLimit(process);
            LocalDate now = new LocalDate();
            process.setFundAllocationExpirationDate(now.plusDays(90));
        } else {/* w  ww . j  a  v  a  2s  . co  m*/
            process.skipFundAllocation();
        }
    }

    process.allocateFundsToSupplier();

    process.createFundAllocationRequest(false);

    if (ExpenditureTrackingSystem.getInstance().processesNeedToBeReverified()) {
        process.setProcessNeedsReverification(Boolean.TRUE);
    }

    AdvancePaymentDocument advancePaymentDocument = process.getAdvancePaymentDocument();
    if (advancePaymentDocument != null && WorkflowConfiguration.getConfiguration().smartsignerIntegration()
            && !advancePaymentDocument.isSigned()) {
        advancePaymentDocument.sendFileForSigning();
    }

}

From source file:ru.codemine.ccms.service.SalesService.java

License:Open Source License

public List<Sales> getAllSalesFromMetaList(List<SalesMeta> smList, LocalDate startDate, LocalDate endDate) {
    List<Sales> result = new ArrayList<>();
    for (SalesMeta sm : smList) {
        for (Sales s : sm.getSales()) {
            if (s.getDate().isAfter(startDate.minusDays(1)) && s.getDate().isBefore(endDate.plusDays(1)))
                result.add(s);/*w ww.ja  v a 2 s .  co m*/
        }
    }

    return result;
}

From source file:ru.codemine.pos.dao.document.ChequeDAOImpl.java

License:Open Source License

@Override
public List<Cheque> getByPeriod(LocalDate startDate, LocalDate endDate) {
    endDate = endDate.plusDays(1); //    

    Query query = getSession().createQuery("FROM Cheque c WHERE c.creationTime BETWEEN :start AND :end");
    query.setDate("start", startDate.toDate());
    query.setDate("end", endDate.toDate());

    return query.list();
}

From source file:ru.codemine.pos.dao.document.ChequeDAOImpl.java

License:Open Source License

@Override
public List<Cheque> getByPeriod(LocalDate startDate, LocalDate endDate, Cheque.PaymentType type) {
    endDate = endDate.plusDays(1);

    Query query = getSession().createQuery(
            "FROM Cheque c WHERE c.paymentType = :type AND c.creationTime BETWEEN :start AND :end");
    query.setDate("start", startDate.toDate());
    query.setDate("end", endDate.toDate());
    query.setInteger("type", type.ordinal());

    return query.list();
}

From source file:se.toxbee.sleepfighter.text.DateTextUtils.java

License:Open Source License

/**
 * Builds and returns text for the "exact" time an alarm occurs as opposed to the period left for it to occur.<br/>
 * In English, 12:00 today would become "Today 12:00", tomorrow would be come "Tomorrow 12:00", and on Monday it would become
 *
 * @param formats the formats to use, e.g: [Today %1$s, Tomorrow %1$s, %2$s %1$s].
 * @param noActive if no alarm was active, this is used.
 * @param now current time in Unix epoch timestamp.
 * @param ats an AlarmTimestamp: the information about the alarm & its timestamp.
 * @param locale the locale to use for weekdays.
 * @return the built time-to string.// ww w .  j  a v a 2 s  .c om
 */
public static final String getTime(String[] formats, String noActive, long now, AlarmTimestamp ats,
        Locale locale) {

    if (ats == AlarmTimestamp.INVALID) {
        return noActive;
    } else {
        if (ats.getMillis() < now) {
            throw new RuntimeException("Time given is before now.");
        }

        // Prepare replacements.
        Alarm alarm = ats.getAlarm();
        String timeReplacement = StringUtils.joinTime(alarm.getHour(), alarm.getMinute());

        // Calculate start of tomorrow.
        DateTime nowTime = new DateTime(now);
        DateTime time = new DateTime(ats.getMillis());
        LocalDate tomorrow = new LocalDate(nowTime).plusDays(1);
        DateTime startOfTomorrow = tomorrow.toDateTimeAtStartOfDay(nowTime.getZone());

        if (time.isBefore(startOfTomorrow)) {
            // Alarm is today.
            Log.d(TAG, "today");
            return String.format(formats[0], timeReplacement);
        }

        // Calculate start of the day after tomorrow.
        LocalDate afterTomorrow = tomorrow.plusDays(1);
        DateTime startOfAfterTomorrow = afterTomorrow.toDateTimeAtStartOfDay(nowTime.getZone());

        if (time.isBefore(startOfAfterTomorrow)) {
            Log.d(TAG, "tomorrow");
            // Alarm is tomorrow.
            return String.format(formats[1], timeReplacement);
        }

        // Alarm is after tomorrow.
        Log.d(TAG, "after tomorrow");
        String weekday = new DateTime(ats.getMillis()).dayOfWeek().getAsText(locale);
        return String.format(formats[2], timeReplacement, weekday);
    }
}

From source file:stali.Stali.java

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
    StringBuilder dataDest = new StringBuilder("");

    String randoms[] = randomValues.getText().split(" ");

    if (randoms.length == 4) {
        int numberOfCats = Integer.valueOf(randoms[0]);
        int numberOfTexts = Integer.valueOf(randoms[1]);
        int numberOfDays = Integer.valueOf(randoms[2]);
        int maxPerDay = Integer.valueOf(randoms[3]);

        LocalDate from = LocalDate.now().minusDays(numberOfDays);

        for (int d = 0; d <= numberOfDays; d++) {
            LocalDate date = from.plusDays(d);

            for (int c = 1; c <= numberOfCats; c++) {
                for (int t = 1; t <= numberOfTexts; t++) {
                    dataDest.append(c);//from   ww w. j ava 2s.c  o  m
                    dataDest.append("\t");
                    dataDest.append(t);
                    dataDest.append("\t");
                    dataDest.append(date);
                    dataDest.append("\t");
                    dataDest.append(random(0, maxPerDay));
                    dataDest.append("\n");
                }
            }
        }
    } else {
        dataDest.append("wrong parameters in random TextBox. " + "int = number of category, "
                + "int = number of text, " + "int = number of days, " + "int = text per day");
    }

    textFinal.setText(dataDest.toString());
}

From source file:view.popups.shift.ShiftManualPopup.java

public ArrayList<LocalDate> getCheckBoxLocalDate() {
    ArrayList<LocalDate> chosenDays = new ArrayList<>();
    LocalDateTime dateTimeMon = (LocalDateTime) cWeek.getSelectionModel().getSelectedItem();

    //Checker om checkboxene er checkede, henter dato udfra den valgte mandag
    //i cWeek og ndre det til LocalDate s der senere kan sttes LocalTime
    if (monday.isSelected()) {
        LocalDate mon = dateTimeMon.toLocalDate();
        chosenDays.add(0, mon);//from   ww  w . j  a  va 2  s .c o  m
    } else if (!monday.isSelected()) {
        LocalDate mon = null;
        chosenDays.add(0, mon);
    }

    if (tuesday.isSelected()) {
        LocalDate mon = dateTimeMon.toLocalDate();
        chosenDays.add(1, mon.plusDays(1));
    } else if (!tuesday.isSelected()) {
        LocalDate mon = null;
        chosenDays.add(1, mon);
    }

    if (wednesday.isSelected()) {
        LocalDate mon = dateTimeMon.toLocalDate();
        chosenDays.add(2, mon.plusDays(2));
    } else if (!wednesday.isSelected()) {
        LocalDate mon = null;
        chosenDays.add(2, mon);
    }

    if (thursday.isSelected()) {
        LocalDate mon = dateTimeMon.toLocalDate();
        chosenDays.add(3, mon.plusDays(3));
    } else if (!thursday.isSelected()) {
        LocalDate mon = null;
        chosenDays.add(3, mon);
    }

    if (friday.isSelected()) {
        LocalDate mon = dateTimeMon.toLocalDate();
        chosenDays.add(4, mon.plusDays(4));
    } else if (!friday.isSelected()) {
        LocalDate mon = null;
        chosenDays.add(4, mon);
    }

    if (saturday.isSelected()) {
        LocalDate mon = dateTimeMon.toLocalDate();
        chosenDays.add(5, mon.plusDays(5));
    } else if (!saturday.isSelected()) {
        LocalDate mon = null;
        chosenDays.add(5, mon);
    }

    if (sunday.isSelected()) {
        LocalDate mon = dateTimeMon.toLocalDate();
        chosenDays.add(6, mon.plusDays(6));
        System.out.println(mon + "" + mon.plusDays(6) + "Whatethef");
    } else if (!sunday.isSelected()) {
        LocalDate mon = null;
        chosenDays.add(6, mon);
    }

    return chosenDays;
}

From source file:vn.webapp.controller.cp.ExamController.java

@RequestMapping(value = "saveExamFromSIS", method = RequestMethod.POST)
public String saveExamFromSIS(HttpServletRequest request,
        @Valid @ModelAttribute("examAdd") ExamValidationFromSIS examValidation, BindingResult result, Map model,
        HttpSession session) {/*from w  w  w  . j  a v a2 s . c o m*/
    /*
     * Get list of paper category and journalList
     */

    /*
     * Put data back to view
     */

    if (result.hasErrors()) {
        return "cp.addExam";
    } else {
        String StatusMessages = "";
        try {

            List<ExamStatus> EXS_List = examStatusService.loadEXSList();
            boolean isToAdd = true;
            for (ExamStatus EXS : EXS_List) {
                if ((EXS.getEXS_AcaYear_Code().equals(examValidation.getAcademicYear()))
                        && (EXS.getEXS_Semester() == examValidation.getSemester())) {
                    isToAdd = false;
                    break;
                }
            }

            if (isToAdd)
                examStatusService.save(examValidation.getAcademicYear(), examValidation.getSemester(), 1);

            ReadExamInfos examData = new ReadExamInfos();

            List<ExamInfo> examinfos = new ArrayList<ExamInfo>();
            String classCode = "";
            String courseCode = "";
            String courseName = "";
            String week = "";
            String day = "";
            String date = "";
            String turn = "";
            String slots = "";
            String group = "";
            String room = "";
            String[] tks = examValidation.getAcademicYear().split("-");

            Connector cn = new Connector();
            String jsonPath = "http://127.0.0.1:9876/getExam?term=" + tks[0] + examValidation.getSemester();
            String json = cn.getJson(jsonPath);

            List<AcademicYear> academicYearList = academicYearService.list();
            String firstdateStr = "";
            String enddateStr = "";
            for (AcademicYear aY : academicYearList) {
                if (aY.getACAYEAR_Code().equals(examValidation.getAcademicYear())) {
                    firstdateStr = aY.getACAYEAR_FromDate();
                    enddateStr = aY.getACAYEAR_ToDate();
                    break;
                }
            }

            DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy");
            LocalDate firstdate = fmt.parseLocalDate(firstdateStr);
            LocalDate enddate = fmt.parseLocalDate(enddateStr);

            if (json != "") {
                json = "{ exams : " + json + "}";
                //System.out.println(json);
                try {
                    JSONObject obj = new JSONObject(json);
                    JSONArray exams = obj.getJSONArray("exams");

                    for (int i = 0; i < exams.length(); ++i) {
                        JSONObject exam = exams.getJSONObject(i);
                        classCode = Integer.toString(exam.getInt("Classid"));
                        courseCode = exam.isNull("CourseID") ? "" : exam.getString("CourseID");
                        RegularCourse rc = regularCourseService.loadByCode(courseCode);
                        courseName = rc == null ? "" : rc.getRC_Name();
                        week = exam.getString("WeekName");
                        day = exam.getString("WeekDayName");
                        turn = exam.getString("TimeTable");
                        //date = exam.isNull("DateExam")?"":exam.getString("DateExam");

                        group = exam.getString("ClassGroup");
                        room = exam.getString("RoomID");
                        if (week.contains("T"))
                            week = week.substring(1, week.length());

                        switch (day.toLowerCase()) {
                        case "th hai":
                            day = "2";
                            break;
                        case "th ba":
                            day = "3";
                            break;
                        case "th t":
                            day = "4";
                            break;
                        case "th nm":
                            day = "5";
                            break;
                        case "th su":
                            day = "6";
                            break;
                        case "th by":
                            day = "7";
                            break;
                        case "ch nht":
                            day = "8";
                            break;
                        }
                        int weekNum = Integer.parseInt(week);
                        int dayNum = Integer.parseInt(day);
                        date = firstdate.plusDays((weekNum - 1) * 7 + dayNum - 2).toString(fmt);
                        room = room.replace(",", "-");
                        String[] tokens = turn.split(" ");
                        //kp 1:7h  1,2,3
                        //kp 2: 9h30 4,5,6
                        //kp 3: 12h30 7,8,9
                        //kp 4: 15h 10,11,12
                        //StartTime = {0645, 0735, 0830, 0920, 1015, 1105, 1230, 1320, 1415, 1505, 1600, 1650, 2130};
                        //EndTime   = {0730, 0820, 0915, 1005, 1100, 1150, 1345, 1405, 1500, 1550, 1645, 1735, 2130};
                        try {
                            String[] subtokens = tokens[tokens.length - 1].split("-");
                            int startSlot = Integer.parseInt(subtokens[0]) * 3 - 2;
                            int endSlot = Integer.parseInt(subtokens[subtokens.length - 1]) * 3;
                            slots = Integer.toString(startSlot);
                            for (int i1 = startSlot + 1; i1 <= endSlot; i1++)
                                slots += "," + Integer.toString(i1);
                        } catch (Exception e) {
                            slots = "";
                        }

                        ExamInfo objExam = new ExamInfo(classCode, courseCode, courseName, week, day, date,
                                turn, slots, group, room);
                        examinfos.add(objExam);
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                    examinfos.clear();
                }
            }

            int cnt = 0;
            for (ExamInfo ei : examinfos) {
                //if(cnt++==10) break;

                if (ei != null) {
                    String RCE_Code = examValidation.getAcademicYear() + "-" + examValidation.getSemester()
                            + "-" + ei.getClassCode() + "-" + ei.getGroup() + "-" + ei.getTurn() + "-"
                            + ei.getRoom();
                    Exam ex = examService.loadByCode(RCE_Code);
                    if (ex == null) {
                        examService.save(RCE_Code, examValidation.getAcademicYear(),
                                examValidation.getSemester(), ei.getClassCode(), ei.getCourseCode(),
                                ei.getCourseName(), Integer.parseInt(ei.getWeek()),
                                Integer.parseInt(ei.getDay()), ei.getDate(), ei.getTurn(), ei.getSlots(),
                                ei.getGroup(), ei.getRoom());
                        cnt++;
                    } else {
                        if (!((ex.getRCE_Date().equals(ei.getDate()))
                                && (ex.getRCE_Day() == Integer.parseInt(ei.getDay()))
                                && (ex.getRCE_Week() == Integer.parseInt(ei.getWeek()))
                                && (ex.getRCE_Room_Code().equals(ei.getRoom())))) {
                            examService.edit(RCE_Code, examValidation.getAcademicYear(),
                                    examValidation.getSemester(), ei.getClassCode(), ei.getCourseCode(),
                                    ei.getCourseName(), Integer.parseInt(ei.getWeek()),
                                    Integer.parseInt(ei.getDay()), ei.getDate(), ei.getTurn(), ei.getSlots(),
                                    ei.getGroup(), ei.getRoom());
                            StatusMessages += "Cp nht thnh cng lp " + ex.getClass() + " nhm "
                                    + ex.getRCE_Group() + " thi\n";
                        }
                    }
                }

            }
            StatusMessages += "Thm mi thnh cng " + cnt + " lp thi\n";
            model.put("status", StatusMessages);
            /**
             * Preparing data for adding into DB
             */

            //if(i_InsertAPaper > 0){
            //model.put("status", "Successfully saved a paper: ");
            //model.put("status",StatusMessages);
            System.out.println(StatusMessages);
            return "redirect:" + this.baseUrl + "/cp/Exams.html";
            //}
        } catch (Exception e) {
            model.put("status", "Failed to update from SIS => " + e.getMessage());
        }
        return "cp.addExamFromSIS";
    }
}

From source file:vn.webapp.controller.cp.RoomsController.java

@RequestMapping(value = "add-a-room-loan", method = RequestMethod.POST)
public String addARoomLoan(HttpServletRequest request,
        @Valid @ModelAttribute("roomLoanFormAdd") RoomLoanValidation roomLoanValidation, BindingResult result,
        Map model, HttpSession session) {

    if (result.hasErrors()) {
        List<AcademicYear> academicYearList = academicYearService.list();
        AcademicYear curAcadYear = academicYearService.getCurAcadYear();
        List<AcademicYear> otherAcadYearList = new ArrayList<AcademicYear>();
        for (AcademicYear aY : academicYearList) {
            if (!aY.getACAYEAR_Code().equals(curAcadYear.getACAYEAR_Code()))
                otherAcadYearList.add(aY);
        }//from   w  w w. j  av a 2  s  .c  o  m
        model.put("academicYearList", otherAcadYearList);
        model.put("curAcadYear", curAcadYear);
        return "cp.addRoomLoan";
    } else {
        String academicYear = roomLoanValidation.getAcademicYear();
        String dateString = roomLoanValidation.getDayMonthYearInput_day();
        String dayString = roomLoanValidation.getDayWeekInput_day();
        String weekString = roomLoanValidation.getDayWeekInput_week();
        String room = roomLoanValidation.getRoomCode();
        String slotStart = roomLoanValidation.getSlotStart();
        String slotEnd = roomLoanValidation.getSlotEnd();

        /* Convert date to day and week */
        List<AcademicYear> academicYearList = academicYearService.list();
        String firstdateStr = "";
        String enddateStr = "";
        for (AcademicYear aY : academicYearList) {
            if (aY.getACAYEAR_Code().equals(academicYear)) {
                firstdateStr = aY.getACAYEAR_FromDate();
                enddateStr = aY.getACAYEAR_ToDate();
                break;
            }
        }

        DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy");
        LocalDate firstdate = fmt.parseLocalDate(firstdateStr);
        LocalDate enddate = fmt.parseLocalDate(enddateStr);

        if (!dateString.equals("")) {
            LocalDate querydate = fmt.parseLocalDate(dateString);
            int dayNum = Days.daysBetween(firstdate, querydate).getDays();
            if ((dayNum <= 0) || (Days.daysBetween(querydate, enddate).getDays() < 0)) {
                session.setAttribute("errorAddRoomLoanFwd",
                        "Ngy bn nhp khng c trong nm h?c. Hy ch?n ngy hp l!");
                return "cp.addRoomLoan";
            }
            dayString = Integer.toString(querydate.getDayOfWeek() + 1);
            if (dayString.equals("8"))
                dayString = "Ch nht";
            weekString = Integer.toString(dayNum / 7 + 1);
            roomLoanValidation.setDayWeekInput_day(dayString);
            roomLoanValidation.setDayWeekInput_week(weekString);
        } else if (!(dayString.equals("") || weekString.equals(""))) {
            try {
                if (dayString.equals("Ch nht"))
                    dayString = "8";
                LocalDate querydate = firstdate
                        .plusDays(7 * (Integer.parseInt(weekString) - 1) + Integer.parseInt(dayString) - 2);
                roomLoanValidation.setDayMonthYearInput_day(querydate.toString());
            } catch (Exception e) {
                roomLoanValidation.setDayMonthYearInput_day("Nhi?u ngy");
            }
        } else {
            session.setAttribute("errorAddRoomLoanFwd", "Khng th thm thng tin mn phng "
                    + roomLoanValidation.getRoomCode() + " v thiu thng tin ngy thng mn phng");
            return "redirect:" + this.baseUrl + "/cp/AddRoomLoan.html";
        }

        if (roomsService.loadByCode(room) == null) {
            session.setAttribute("errorAddRoomLoanFwd", "M phng " + room
                    + " khng c trong c s d liu phng. Hy kim tra li!");
            return "redirect:" + this.baseUrl + "/cp/AddRoomLoan.html";
        }

        try {
            String RL_Code = roomLoanValidation.getRoomCode() + "-" + roomLoanValidation.getAcademicYear() + "-"
                    + roomLoanValidation.getDayWeekInput_week() + "-"
                    + roomLoanValidation.getDayWeekInput_day();
            RoomLoan roomLoan = roomLoanService.loadByCode(RL_Code);
            if (roomLoan == null)
                roomLoanService.save(roomLoanValidation.getRoomCode(), roomLoanValidation.getDayWeekInput_day(),
                        roomLoanValidation.getDayWeekInput_week(), roomLoanValidation.getAcademicYear(),
                        roomLoanValidation.getDayMonthYearInput_day(),
                        roomLoanValidation.getSlotStart() + "-" + roomLoanValidation.getSlotEnd(),
                        roomLoanValidation.getNote());
            return "redirect:" + this.baseUrl + "/cp/RoomLoans.html";
        } catch (Exception e) {
            model.put("status", "You failed to edit room loan for" + roomLoanValidation.getRoomCode());
        }
    }
    return "cp.addRoomLoan";
}