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:frontEnd.userLogadoGUI.java

private void jbtnAlugarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAlugarActionPerformed
    this.setEnabled(false);
    User user = new User(jtxtfTipo.getText(), jtxtfMatricula.getText(), jtxtfNome.getText(), null);
    Livro livro = new Livro();
    alugarLivroGUI alugarLivro = new alugarLivroGUI(this);

    int row = jtbProcuraLivro.getSelectedRow();
    if (row >= 0) {
        String[] code = { jtbProcuraLivro.getValueAt(row, 0).toString(),
                jtbProcuraLivro.getValueAt(row, 1).toString(), jtbProcuraLivro.getValueAt(row, 2).toString(),
                jtbProcuraLivro.getValueAt(row, 5).toString() };

        alugarLivro.setUser(user);//from  w  w  w  . j  a  v  a  2  s  .  c  om
        alugarLivro.setLivro(livro);

        LocalDate now = LocalDate.now(), next = now.plusDays(7);
        String currentDate = now.toString(), nextDate = next.toString();

        livro.setTitulo(code[0]);
        livro.setEditora(code[1]);
        livro.setAutor(code[2]);
        livro.setId(code[3]);
        livro.setEntrega(nextDate);
        livro.setAluguel(currentDate);

        alugarLivro.setVisible(true);
    } else {
        JOptionPane.showMessageDialog(rootPane, "Nenhum livro selecionado.", "Erro", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:gg.db.datamodel.Period.java

License:Open Source License

/**
 * Is the specified period valid?//w  w w .  j  av  a 2s.c  o m
 * @param startDate Start date of the period
 * @param endDate End date of the period
 * @param periodType Type of the period
 * @return <B>true</B> if the period is valid (or if startDate=endDate=periodType=null), <B>false</B> otherwise<BR/>
 * To be valid, a period has to be a "full" period:
 * <UL>
 * <LI> For each type of period: Start date > End date</LI>
 * <LI> For DAY period: number of days between Start date and End date = 0<BR/>
 * Example: <I>From 12/30/2005 to 12/30/2005</I></LI>
 * <LI> For WEEK period: number of days between Start date and End date = 6<BR/>
 * The period has to start on MONDAY<BR/>
 * The period has to end on SUNDAY<BR/>
 * Example: <I>From 12/01/2005 to 12/18/2005</I></LI>
 * <LI> For MONTH period: number of month between Start date and End date = 0<BR/>
 * The period has to start on the first day of the month (05/01/2006)<BR/>
 * The period has to end on the last day of the month (05/31/2006)<BR/>
 * Number of months between Start date - 1 day and End date = 1<BR/>
 * Number of months between Start date and End date + 1 day = 1<BR/>
 * Example: <I>From 03/01/2005 to 03/31/2005</I></LI>
 * <LI> For YEAR period: number of years between Start date and End date = 0<BR/>
 * The period has to start on the first day of the first month (01/01/2006)<BR/>
 * The period has to end in December<BR/>
 * The period has to end on the last day of the last month (12/31/2006)<BR/>
 * Number of years between Start date - 1 day and End date = 1<BR/>
 * Number of years between Start date and End date + 1 day = 1<BR/>
 * Example: <I>From 01/01/2006 to 12/31/2006</I></LI>
 * </UL>
 */
private boolean isPeriodValid(LocalDate startDate, LocalDate endDate, PeriodType periodType) {
    boolean periodValid = true; // Is the period valid

    // Check if Start date < End date
    if (startDate != null && endDate != null && startDate.compareTo(endDate) > 0) {
        periodValid = false;
    }

    // Check if the period is a "full" period
    if (periodValid && startDate != null && endDate != null && periodType != null) {
        switch (periodType) {
        case DAY:
            // i.e. a DAY period: from 05/12/2006 to 05/12/2006
            if ((getNumberOfDays(startDate.minusDays(1), endDate) != 1) || // 12-11 = 1  (Nb of days = 1)
                    (getNumberOfDays(startDate, endDate) != 0) || // // 12-12 = 0 (Nb of days = 0)
                    (getNumberOfDays(startDate, endDate.plusDays(1)) != 1)) { // 13-12 = 1 (Nb of days = 1)
                periodValid = false;
            }
            break;
        case WEEK:
            // i.e. a WEEK period: from 05/12/2006 to 05/18/2006
            if ((startDate.toDateTimeAtStartOfDay().getDayOfWeek() != DateTimeConstants.MONDAY) || // the week has to begin on MONDAY
                    (getNumberOfWeeks(startDate.minusDays(1), endDate) != 1) || // 18-11 = 7 (Nb of weeks = 1)
                    (getNumberOfWeeks(startDate, endDate) != 0) || // 18-12 = 6 (Nb of weeks = 0)
                    (getNumberOfWeeks(startDate, endDate.plusDays(1)) != 1)) { // 19-12 = 7 (Nb of weeks = 1)
                periodValid = false;
            }
            break;
        case MONTH:
            // i.e. a MONTH period: from 05/01/2006 to 05/30/2006
            if ((startDate.getDayOfMonth() != 1) || // the first day of the period has to be the first day of the month
                    (getNumberOfMonths(startDate.minusDays(1), endDate) != 1) || // 5-4 = 1 (Nb of months = 1)
                    (getNumberOfMonths(startDate, endDate) != 0) || // 5-5 = 0 (Nb of months = 0)
                    (getNumberOfMonths(startDate, endDate.plusDays(1)) != 1)) { // 6-5 = 1 (Nb of months = 1)
                periodValid = false;
            }
            break;
        case YEAR:
            // i.e. a YEAR period: from 01/01/2006 to 12/31/2006
            if ((startDate.getMonthOfYear() != 1 || startDate.getDayOfMonth() != 1) || // the first day of the period has to be the first day of the first month
                    (endDate.getMonthOfYear() != 12) || // the month of the end date of the period has to be December
                    (getNumberOfYears(startDate.minusDays(1), endDate) != 1) || // 2006-2005 = 1 (Nb of years = 1)
                    (getNumberOfYears(startDate, endDate) != 0) || // 2006-2006 = 0 (Nb of years = 0)
                    (getNumberOfYears(startDate, endDate.plusDays(1)) != 1)) { // 2007-2006 = 1 (Nb of years = 1)
                periodValid = false;
            }
            break;
        case FREE:
            // There is no constraint on the number of units for FREE type of period
            break;
        default:
            // Should never happen
            throw new AssertionError("The PeriodType is unknown");
        }
    }

    return periodValid;
}

From source file:gg.db.datamodel.Periods.java

License:Open Source License

/**
 * Gets the list of Period between a start date and an end date<BR/><BR/>
 * Example:<BR/>/*from ww  w.ja va  2s.  c  o m*/
 * getListOfPeriod(new LocalDate(2006, 5, 20), new LocalDate(2006, 7, 2), PeriodType.MONTH) should create the following Period objects:
 * <UL>
 * <LI> From 05/01/2006 to 05/31/2006 (MONTH)</LI>
 * <LI> From 06/01/2006 to 06/30/2006 (MONTH)</LI>
 * <LI> From 07/01/2006 to 07/31/2006 (MONTH)</LI>
 * </UL>
 * @param start Start date of the whole period
 * @param end End date of the whole period
 * @param periodType Type of the Period to create
 * @return The list of computed Period
 */
private List<Period> getListOfPeriod(LocalDate start, LocalDate end, PeriodType periodType) {
    if (start == null || end == null || periodType == null) {
        throw new IllegalArgumentException(
                "One of the following parameters is null: 'start', 'end', 'periodType'");
    }

    // Adjust the start date to the start of the period's type (first day of the week, first day of the month, first day of the year depending on the type of the period to create)
    LocalDate startPeriods = getAdjustedStartDate(start, periodType);

    // Adjust the end date to the end of the period's type (last day of the week, last day of the month, last day of the year depending on the type of the period to create)
    LocalDate endPeriods = getAdjustedEndDate(end, periodType);

    assert (startPeriods != null && endPeriods != null);

    // Create the list of Period objects
    List<Period> listOfPeriod = new ArrayList<Period>(); // List of created Period (returned object)
    Period newPeriod;
    if (periodType == PeriodType.FREE) {
        // Create the Period object and add it to the list of Period
        newPeriod = new Period(start, end, PeriodType.FREE);
        listOfPeriod.add(newPeriod);
    } else {
        // Create all Period objects and add them to the list of Period
        while (startPeriods.compareTo(endPeriods) <= 0) {
            switch (periodType) {
            case DAY:
                // Create the DAY period
                newPeriod = new Period(startPeriods, startPeriods, PeriodType.DAY); // i.e. Day from 05/02/2006 to 05/02/2006
                startPeriods = startPeriods.plusDays(1); // Move to the next day
                break;
            case WEEK:
                // Create the WEEK period
                newPeriod = new Period(startPeriods, startPeriods.plusDays(6), PeriodType.WEEK); // i.e. Week from 05/01/2006 (MONDAY) to 05/07/2006 (SUNDAY)
                startPeriods = startPeriods.plusDays(7); // Move to the next week
                break;
            case MONTH:
                // Create the MONTH period
                newPeriod = new Period(startPeriods, startPeriods.plusMonths(1).minusDays(1), PeriodType.MONTH); // i.e. Month from 05/01/2006 to 05/31/2006
                startPeriods = startPeriods.plusMonths(1); // Move to the next month
                break;
            case YEAR:
                // Create the YEAR period
                newPeriod = new Period(startPeriods, startPeriods.plusYears(1).minusDays(1), PeriodType.YEAR); // i.e. Year from 01/01/2006 to 12/31/2006
                startPeriods = startPeriods.plusYears(1); // Move to the next year
                break;
            case FREE: // should never happen
                throw new AssertionError("The FREE PeriodType should not be handled in this switch statement");
            default: // should never happen
                throw new AssertionError("Unknown PeriodType");
            }
            assert (newPeriod != null);

            // Add the created period to the list of Period
            listOfPeriod.add(newPeriod);
        }
    }

    return listOfPeriod;
}

From source file:io.renren.common.utils.DateUtils.java

License:Apache License

/**
 * ????//from   w w  w  .  ja  v  a 2s  . c o  m
 * @param week    0-1-212
 * @return  date[0]?date[1]?
 */
public static Date[] getWeekStartAndEnd(int week) {
    DateTime dateTime = new DateTime();
    LocalDate date = new LocalDate(dateTime.plusWeeks(week));

    date = date.dayOfWeek().withMinimumValue();
    Date beginDate = date.toDate();
    Date endDate = date.plusDays(6).toDate();
    return new Date[] { beginDate, endDate };
}

From source file:jp.co.ntt.atrs.domain.service.b0.TicketSharedServiceImpl.java

License:Apache License

/**
 * {@inheritDoc}/*from   w  ww.  j  av a 2s. c  om*/
 */
@Override
public LocalDate getSearchLimitDate() {
    // ?? = ??
    LocalDate sysDate = dateFactory.newDateTime().toLocalDate();
    LocalDate limitDate = sysDate.plusDays(limitDay);
    return limitDate;
}

From source file:julian.lylly.model.TaskOrganizerImpl.java

@Override
public Duration getTodaysInvTime(Tag tag) {
    LocalDate today = LocalDate.now();
    return getInvestedTime(today, today.plusDays(1), tag);
}

From source file:liteshiftwindow.LSForm.java

public String getTabName() {

    // When using the JCalendar widget, its "selected day" output is in MMM dd, yyyy format.
    // This funciton takes that information, finds the first day of the week that selected day is in
    //   and names the tab after it.
    // e.g. if the user selected Feb 2, a Monday. The following steps are executed:
    //  1. Find that the first day of that week is Sunday, Feb 1.
    //  2. Find that the last day of that week is Saturday, Feb 7.
    //  3. Return the following string: "02/01 - 02/07"
    // This returned information is later used in the program to "name" the schedule.
    org.joda.time.format.DateTimeFormatter MdYFormat = DateTimeFormat.forPattern("MMM dd, yyyy");
    Date selectedDay = jDateChooser1.getDate();

    if (selectedDay == null)
        return null;

    String strDay = DateFormat.getDateInstance().format(selectedDay);
    LocalDate jodaDate = LocalDate.parse(strDay, MdYFormat);
    LocalDate Sunday = getSunday(jodaDate);
    org.joda.time.format.DateTimeFormatter MdFormat = DateTimeFormat.forPattern("MM/dd");
    String tabName = Sunday.toString(MdFormat) + " - " + Sunday.plusDays(6).toString(MdFormat);

    return tabName;
}

From source file:liteshiftwindow.LSForm.java

public String getNumberDate(String inputDay) {

    org.joda.time.format.DateTimeFormatter MdYFormat = DateTimeFormat.forPattern("MM/dd/yyyy");
    org.joda.time.format.DateTimeFormatter MdFormat = DateTimeFormat.forPattern("MM/dd");
    String tabName = jTabbedSchedulePane.getTitleAt(jTabbedSchedulePane.getSelectedIndex());
    //                                                    TODO: year 
    LocalDate jodaDate = LocalDate.parse(tabName.split(" ")[0] + "/2015", MdYFormat);
    LocalDate Sunday = getSunday(jodaDate);
    String[] days = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };

    for (int i = 0; i < 7; i++) {
        if (inputDay.compareTo(days[i]) == 0)
            return Sunday.plusDays(i).toString(MdFormat);
    }/*from w ww .j  a va 2 s.c o  m*/

    return "0/0";

}

From source file:me.vertretungsplan.parser.UntisInfoParser.java

License:Mozilla Public License

private void parseTimetable(SubstitutionSchedule v, String lastChange, Document doc, String klasse,
        String weekName) throws JSONException {
    v.setLastChange(ParserUtils.parseDateTime(lastChange));
    LocalDate weekStart = DateTimeFormat.forPattern("d.M.yyyy").parseLocalDate(weekName);

    Element table = doc.select("table").first();

    List<SubstitutionScheduleDay> days = new ArrayList<>();
    for (int i = 0; i < table.select("tr").first().select("td:gt(0)").size(); i++) {
        LocalDate date = weekStart.plusDays(i);

        SubstitutionScheduleDay day = null;
        for (SubstitutionScheduleDay d : v.getDays()) {
            if (d.getDate().equals(date)) {
                day = d;//from www  .  j  a v  a  2 s .co m
                break;
            }
        }
        if (day == null) {
            day = new SubstitutionScheduleDay();
            day.setDate(date);
            v.addDay(day);
        }
        days.add(day);
    }

    Elements rows = table.select("> tbody > tr:gt(0)");
    Map<Integer, String> lessons = new HashMap<>();

    int i = 0;
    int lessonCounter = 1;
    while (i < rows.size()) {
        Element cell = rows.get(i).select("td").first();
        String lessonName = cell.text().trim();
        if (lessonName.length() > 3) {
            lessonName = String.valueOf(lessonCounter);
        }
        lessons.put(i, lessonName);
        i += getRowspan(cell);
        lessonCounter += 1;
    }

    // counts the number of columns that will be missing from each row due to a cell with colspan
    Map<Integer, Integer> columnsToSkip = new HashMap<>();
    for (int j = 0; j < rows.size(); j++) {
        columnsToSkip.put(j, 0);
    }

    for (int col = 1; col < days.size(); col++) {
        int row = 0;
        while (row < rows.size()) {
            Element cell = rows.get(row).select("> td").get(col - columnsToSkip.get(row));
            String lesson = getTimetableLesson(cell, row, lessons);

            days.get(col - 1).addAllSubstitutions(
                    parseTimetableCell(cell, lesson, klasse, data.getJSONArray("cellFormat"), colorProvider));

            for (int skippedRow = row + 1; skippedRow < row + getRowspan(cell); skippedRow++) {
                columnsToSkip.put(skippedRow, columnsToSkip.get(skippedRow) + 1);
            }

            row += getRowspan(cell);
        }
    }
}

From source file:me.vertretungsplan.parser.WebUntisParser.java

License:Mozilla Public License

@Override
public SubstitutionSchedule getSubstitutionSchedule()
        throws IOException, JSONException, CredentialInvalidException {
    try {/*from w  ww  . ja  v a2s.  c  o  m*/
        login();
        SubstitutionSchedule schedule = SubstitutionSchedule.fromData(scheduleData);
        schedule.setLastChange(getLastImport());

        TimeGrid timegrid = new TimeGrid(getTimeGrid());
        final LocalDate today = LocalDate.now();
        int daysToAdd = getDaysToAdd();

        final LocalDate endDate = today.plusDays(6 + daysToAdd);

        try {
            schedule = parseScheduleUsingSubstitutions(schedule, timegrid, today, endDate);
        } catch (UnauthorizedException e) {
            schedule = parseScheduleUsingTimetable(schedule, timegrid, today, endDate);
        }

        schedule.setClasses(toNamesList(getClasses()));
        final String protocol = data.optString(PARAM_PROTOCOL, "https") + "://";
        schedule.setWebsite(protocol + data.getString(PARAM_HOST) + "/WebUntis");

        try {
            addMessagesOfDay(schedule);
        } catch (UnauthorizedException ignored) {

        }

        logout();
        return schedule;
    } catch (UnauthorizedException e) {
        throw new IOException(e);
    }
}