Example usage for org.joda.time DateTime plusDays

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

Introduction

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

Prototype

public DateTime plusDays(int days) 

Source Link

Document

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

Usage

From source file:DataRequestParser.java

public void inflateDataRequests(Set<DataRequest> dataRequestSet) {

    Iterator<DataRequest> iter = dataRequestSet.iterator();

    // the goal here is to expand substitutions 
    // so if start data and stop data are found 
    // then each data request template needs to be expanded 
    // to cover these dates

    String absoluteLocalPath;//from w ww  .ja  va 2 s .c  o  m

    DateTime startDate = this.getStartDate();
    DateTime stopDate = this.getStopDate();

    // the base case is that either start date or stop date is null
    // in this instance, inflated data set is equal to the original 
    // dataRequest set
    if (startDate == null || stopDate == null) {
        // nothing to inflate
        while (iter.hasNext()) {
            this.routingServer.submitDataRequest(iter.next());
        }
        return;
    }

    // calculate the number of days between start and stop date
    int numDays = Days.daysBetween(startDate, stopDate).getDays();

    DataRequest tmpDataRequest;

    int i = 0;
    // loop 
    while (iter.hasNext()) {

        tmpDataRequest = iter.next();

        // loop between start and stop dates
        for (int j = 0; j <= numDays; j += 1) {

            // make new data request from template that has effective date set;
            DataRequest newDataRequest = tmpDataRequest.copy();

            // set new date
            newDataRequest.setEffectiveDate(startDate.plusDays(j));

            // update local path with date info
            //newDataRequest.applyDateToLocalPath();
            absoluteLocalPath = this.dateKeyPathParser.replaceWithLiterals(
                    newDataRequest.getLocalPathTemplate(), startDate.plusDays(j), newDataRequest.getKey());

            newDataRequest.setLocalPathTemplate(absoluteLocalPath);

            //newDataRequest.print();

            i += 1;

            // hand off to the routing server
            if (this.routingServer != null) {
                //newDataRequest.print();
                this.routingServer.submitDataRequest(newDataRequest);
            } else {
                //System.out.println(i);
            }
        }
    }

    DateTimeFormatter fmt = DateTimeFormat.forPattern("y::D");
    System.out.println("Start date: " + fmt.print(this.getStartDate()) + ", Stop date: "
            + fmt.print(this.getStopDate()) + ", Number of days: " + numDays);
    System.out.println("From templates " + dataRequestSet.size() + ", inflated " + i + " data requests ...");
}

From source file:DataRequestStringParser.java

public String inflateDataRequests(Set<DataRequest> dataRequestSet) {

    Iterator<DataRequest> iter = dataRequestSet.iterator();

    // the goal here is to expand substitutions 
    // so if start data and stop data are found 
    // then each data request template needs to be expanded 
    // to cover these dates

    String absoluteLocalPath;/*from   www. j a v a 2s  . c  o m*/

    DateTime startDate = this.getStartDate();
    DateTime stopDate = this.getStopDate();

    try {
        this.xmlParser.reset();
    } catch (IPWorksException e) {
        e.printStackTrace();
    }

    // the base case is that either start date or stop date is null
    // in this instance, inflated data set is equal to the original 
    // dataRequest set
    if (this.routingServer != null && (startDate == null || stopDate == null)) {
        // nothing to inflate
        while (iter.hasNext()) {
            this.routingServer.submitDataRequest(iter.next());
        }
        return null;
    }

    // calculate the number of days between start and stop date
    int numDays = Days.daysBetween(startDate, stopDate).getDays();

    DataRequest tmpDataRequest;

    int i = 0;
    // loop 
    while (iter.hasNext()) {

        tmpDataRequest = iter.next();

        // loop between start and stop dates
        for (int j = 0; j <= numDays; j += 1) {

            // make new data request from template that has effective date set;
            DataRequest newDataRequest = tmpDataRequest.copy();

            // set new date
            newDataRequest.setEffectiveDate(startDate.plusDays(j));

            // update local path with date info
            //newDataRequest.applyDateToLocalPath();
            absoluteLocalPath = this.dateKeyPathParser.replaceWithLiterals(
                    newDataRequest.getLocalPathTemplate(), startDate.plusDays(j), newDataRequest.getKey());

            newDataRequest.setLocalPathTemplate(absoluteLocalPath);

            //newDataRequest.print();

            i += 1;

            // hand off to the routing server
            if (this.routingServer != null) {
                //newDataRequest.print();
                this.routingServer.submitDataRequest(newDataRequest);
            } else {
                //System.out.println(i);
            }
        }
    }

    DateTimeFormatter fmt = DateTimeFormat.forPattern("y::D");
    return "Start date: " + fmt.print(startDate) + ", Stop date: " + fmt.print(stopDate) + ", Number of days: "
            + numDays + "\n" + "From templates " + dataRequestSet.size() + ", inflated " + i
            + " data requests ...";
}

From source file:Jarvis.java

void alarmAtTime(int hour, int min, int sec) {
    hour = hour % 24;/*from w ww. ja  v a 2 s  .  c  o  m*/
    min = min % 60;
    try {
        System.out.println("activate alarm");

        String fullTime = "";
        if (hour < 10) {
            fullTime += "0";
        }
        fullTime += hour + ":";
        if (min < 10) {
            fullTime += "0";
        }
        fullTime += min + ":00";

        Calendar cal = Calendar.getInstance();
        int curentHour = cal.get(cal.HOUR_OF_DAY);
        int curentMin = cal.get(cal.MINUTE);
        int curentDayOfMonth = cal.get(Calendar.DAY_OF_MONTH);

        //          Calendar c = Calendar.getInstance(); 
        //            DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        //     //get current date time with Date()
        //     Date date = new Date();
        //     System.out.println(dateFormat.format(date));
        //    
        //     //get current date time with Calendar()
        //    dateFormat.format(cal.getTime());
        //c.setTime(date); 
        //c.add(Calendar.DATE, 1);
        //date = c.getTime();
        Date targetDateAlarm;
        DateTime usingTimeDate;
        String extraInfo = "today";
        if (curentHour > hour || curentHour == hour && curentMin >= min) {
            System.out.println("tomorrow date");
            extraInfo = "tomorrow";
            //                org.joda.time.DateTimeZone timeZone = org.joda.time.DateTimeZone.forID("America/Los_Angeles");
            DateTime now = new DateTime();
            usingTimeDate = now.plusDays(1);

            //                int year = tomorrowAsJUDate.getYear();
            //                int month = tomorrowAsJUDate.getMonth();
            //                int day = tomorrowAsJUDate.getDate();
            //                System.out.println(year + "/" + month + "/" + day);
            //                targetDateAlarm = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(year + "/" + month + "/" + day + " " + fullTime);
            //                System.out.println(targetDateAlarm);
        } else {
            usingTimeDate = new DateTime();
            //                targetDateAlarm = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(fullTime);
        }

        targetDateAlarm = usingTimeDate.toDate();
        targetDateAlarm.setHours(hour);
        targetDateAlarm.setMinutes(min);
        targetDateAlarm.setSeconds(sec);
        System.out.println(targetDateAlarm);
        DateTime now = new DateTime();

        long diffInMillis = (targetDateAlarm.getTime() - now.toDate().getTime()) / 1000;
        System.out.println(diffInMillis + " seconds");
        result = dospeak("alarm will ring at " + hour + " and " + min + " o'clock " + extraInfo + " sir.");

        alarmInNTime((int) diffInMillis, "seconds", false);

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Jarvis.java

void alarmAtTime(int hour, int min) {
    hour = hour % 24;/*from   w  w  w  .ja va 2  s. c  o m*/
    min = min % 60;
    try {
        System.out.println("activate alarm");

        String fullTime = "";
        if (hour < 10) {
            fullTime += "0";
        }
        fullTime += hour + ":";
        if (min < 10) {
            fullTime += "0";
        }
        fullTime += min + ":00";

        Calendar cal = Calendar.getInstance();
        int curentHour = cal.get(cal.HOUR_OF_DAY);
        int curentMin = cal.get(cal.MINUTE);
        int curentDayOfMonth = cal.get(Calendar.DAY_OF_MONTH);

        //          Calendar c = Calendar.getInstance(); 
        //            DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        //     //get current date time with Date()
        //     Date date = new Date();
        //     System.out.println(dateFormat.format(date));
        //    
        //     //get current date time with Calendar()
        //    dateFormat.format(cal.getTime());
        //c.setTime(date); 
        //c.add(Calendar.DATE, 1);
        //date = c.getTime();
        Date targetDateAlarm;
        DateTime usingTimeDate;
        String extraInfo = "today";
        if (curentHour > hour || curentHour == hour && curentMin >= min) {
            System.out.println("tomorrow date");
            extraInfo = "tomorrow";
            //                org.joda.time.DateTimeZone timeZone = org.joda.time.DateTimeZone.forID("America/Los_Angeles");
            DateTime now = new DateTime();
            usingTimeDate = now.plusDays(1);

            //                int year = tomorrowAsJUDate.getYear();
            //                int month = tomorrowAsJUDate.getMonth();
            //                int day = tomorrowAsJUDate.getDate();
            //                System.out.println(year + "/" + month + "/" + day);
            //                targetDateAlarm = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(year + "/" + month + "/" + day + " " + fullTime);
            //                System.out.println(targetDateAlarm);
        } else {
            usingTimeDate = new DateTime();
            //                targetDateAlarm = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(fullTime);
        }

        targetDateAlarm = usingTimeDate.toDate();
        targetDateAlarm.setHours(hour);
        targetDateAlarm.setMinutes(min);
        targetDateAlarm.setSeconds(0);
        System.out.println(targetDateAlarm);
        DateTime now = new DateTime();

        long diffInMillis = (targetDateAlarm.getTime() - now.toDate().getTime()) / 1000;
        System.out.println(diffInMillis + " seconds");
        result = dospeak("alarm will ring at " + hour + " and " + min + " o'clock " + extraInfo + " sir.");

        alarmInNTime((int) diffInMillis, "seconds", false);

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:aplicacion.control.AsignarHorasExtrasController.java

public void createArrayControles(Integer diasDelRango) {
    int cantidad = diasDelRango;

    ArrayList<ControlExtras> controlesCrear = new ArrayList<>(); // control diarios que salen de turnosTableView (no tienen fecha)
    for (ControlExtras ce : dataTurnos) {
        Integer dias = Integer.valueOf(ce.getDias());
        while (dias > 0) {
            controlesCrear.add(ce.clone());
            dias--;/*from  w  w  w .jav  a 2  s.  co  m*/
        }
    }

    DateTime fecha = new DateTime(inicio.getTime());
    rangoControls = new ArrayList<>();
    int count = 0;
    while (cantidad > 0) { // se agregan los controles limitados por el rango de fecha
        for (ControlExtras ce : controlesCrear) { // y se le agrega la fecha correspondiente 
            ControlExtras control = ce.clone();
            control.setFecha(new Date(fecha.plusDays(count).getMillis()));
            rangoControls.add(control);
            cantidad--;
            count++;
            if (cantidad == 0) {
                break;
            }
        }
    }
}

From source file:aplicacion.control.AsignarHorasExtrasController.java

void addDaysColumns(int count) {
    DateTime fecha = new DateTime(inicio.getTime());
    fecha = fecha.plusDays(count);
    String day = fecha.toCalendar(Locale.getDefault()).getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG,
            Locale.getDefault());
    TableColumn columna = new TableColumn(day + " " + fecha.getDayOfMonth() + "/" + fecha.getMonthOfYear());
    columna.setPrefWidth(120);/*  w ww. j av  a 2  s . c  o  m*/
    columna.setStyle("-fx-alignment: center;");
    columna.setCellValueFactory(
            new Callback<TableColumn.CellDataFeatures<EmpleadoTable, String>, ObservableValue<String>>() {
                @Override
                public ObservableValue<String> call(TableColumn.CellDataFeatures<EmpleadoTable, String> data) {

                    if (data.getValue().getExtras() == null)
                        return null;

                    return new ReadOnlyStringWrapper(getTextHorario(data.getValue().getExtras().get(count)));
                }
            });
    empleadosTableView.getColumns().add(columna);
}

From source file:aplicacion.control.HorarioEmpleadoController.java

public void buscarRoles(Timestamp fecha, int dias) {
    DateTime tiempo = new DateTime(fecha.getTime());
    if (dias > 1) {
        int comienzoMes = empresa.getComienzoMes();
        tiempo.plusDays(1);
    }//w  w w  .j  ava  2s.  c o m
}

From source file:aplicacion.control.RolDePagoClienteController.java

public void setControlEmpleadoInfo(Usuario empleado, Fecha inicio, Fecha fin) {

    ControlDiarioDAO controlDAO = new ControlDiarioDAO();
    ControlExtrasDAO extrasDAO = new ControlExtrasDAO();

    Fecha fechaInicial = new Fecha(inicio.getFecha()); // dias anteriores de horas extras 
    Fecha fechaFinal = new Fecha(fin.getFecha());

    int days = (int) fechaInicial.daysDifference(fechaFinal);

    controlesDiarios = new ArrayList<>();

    for (int i = 0; i <= days; i++) {
        ControlTable controlTable = new ControlTable();
        controlTable.setFecha(fechaInicial.plusDays(i));
        controlTable.setFechaString(controlTable.getFecha().toStringInverse());
        controlTable.setDia(controlTable.getFecha().getMonthName());
        controlesDiarios.add(controlTable);
    }//from  w w w . jav  a2s .  com

    System.out.println("dias " + controlesDiarios.size());
    controlesEmpleado = new ArrayList<>();
    controlesEmpleado.addAll(controlDAO.findAllByEmpleadoIdInDeterminateTime(empleado.getId(),
            fechaInicial.getFecha(), fechaFinal.getFecha()));

    ////////////////////////////////////////////////////////////////////////////////////////
    Date fechaInicialExtra = fechaInicial.minusDays(7).getDate(); // dias anteriores de horas extras 
    Date fechaFinalExtra = fechaFinal.minusDays(7).getDate();
    System.out.println("fecha inicio a mostrar para horas extras " + fechaInicialExtra.toString());
    System.out.println("fecha final a mostrar para horas extras " + fechaFinalExtra.toString());
    DateTime dateA = new DateTime(fechaInicialExtra.getTime());
    DateTime dateB = new DateTime(fechaFinalExtra.getTime());

    int daysE = Days.daysBetween(dateA.withTimeAtStartOfDay(), dateB.withTimeAtStartOfDay()).getDays();

    controlesExtras = new ArrayList<>();

    for (int i = 0; i <= daysE; i++) {
        ControlTable controlTable = new ControlTable();
        controlTable.setFechaExtra(dateA.plusDays(i));
        controlTable.setFechaString(dateA.plusDays(i).toString("dd-MM-yyyy")); // QUITADO extrano problema en java.sql.date que lo deja con un mes mas del real, se deberia optimizar y acomodar el error, de momento se solvento diminuyendo un mes antes de pasar a string
        controlesExtras.add(controlTable);
    }

    controlesHoras = new ArrayList<>();
    controlesHoras.addAll(extrasDAO.findAllByEmpleadoIdInDeterminateTime(empleado.getId(), fechaInicialExtra,
            fechaFinalExtra));
    System.out.println("cantidad de controles de horas extras " + controlesHoras.size());
    setToTable(true);
}

From source file:app.service.AuthService.java

License:Apache License

protected int refreshAccessResponse(String userId, AccessResponse accessResponse) {
    DateTime now = DateTime.now();
    final long expireTime = now.plusHours(EXPIRE_TIME).getMillis();
    final long refreshTime = now.plusDays(REFRESH_TIME).getMillis();

    AccountSession session = new AccountSession();
    session.setUserId(userId);/*from   w w w  . j  a  va2 s  . c o m*/
    session.setExpireTime(expireTime);
    session.setRefreshTime(refreshTime);

    CryptoToken expireToken = newSessionToken(session, true);
    if (expireToken == null) {
        return ResultCode.ENCRYPT_TOKEN_FAILED;
    }

    CryptoToken refreshToken = newSessionToken(session, false);
    if (refreshToken == null) {
        return ResultCode.ENCRYPT_TOKEN_FAILED;
    }

    accessResponse.setExpireTime(expireTime);
    accessResponse.setExpireToken(expireToken);
    accessResponse.setRefreshTime(refreshTime);
    accessResponse.setRefreshToken(refreshToken);
    return BaseResponse.COMMON_SUCCESS;
}

From source file:app.ToDoItemsByDateRangeViewModel.java

License:Apache License

private DateRange dateRangeFor(final ToDoItem t) {
    if(t.getDueBy() == null) {
        return DateRange.Unknown;
    }/*from  ww  w.  ja v a 2  s .co  m*/
    final DateTime dueBy = t.getDueBy().toDateTimeAtStartOfDay();
    final DateTime today = clockService.now().toDateTimeAtStartOfDay();
        
    if(dueBy.isBefore(today)) {
        return DateRange.OverDue;
    }
    if(dueBy.isBefore(today.plusDays(1))) {
        return DateRange.Today;
    }
    if(dueBy.isBefore(today.plusDays(2))) {
        return DateRange.Tomorrow;
    }
    if(dueBy.isBefore(today.plusDays(7))) {
        return DateRange.ThisWeek;
    }
    return DateRange.Later;
}