Example usage for org.joda.time LocalDateTime LocalDateTime

List of usage examples for org.joda.time LocalDateTime LocalDateTime

Introduction

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

Prototype

public LocalDateTime(Object instant) 

Source Link

Document

Constructs an instance from an Object that represents a datetime.

Usage

From source file:control.EmprestimoController.java

public static boolean Renovar(int id, int plus_days) {
    dao = new EmprestimoDAO();
    Emprestimo e = dao.get(id);//from ww w .j av a 2 s.  c  o m
    if (e != null) {
        LocalDateTime hoje = new LocalDateTime(System.currentTimeMillis());
        LocalDateTime fim = new LocalDateTime(e.getData_fim());
        int dias = Days.daysBetween(hoje, fim).getDays();
        dias = dias * -1;
        if (dias > 0)
            e.setData_fim(hoje.plusDays(plus_days));
        else
            e.setData_fim(fim.plusDays(plus_days));
        dao = new EmprestimoDAO();
        return dao.update(e);
    }
    return false;
}

From source file:control.EmprestimoController.java

private static TableModel UpdateTablemodel(TableModel tb) {
    LocalDateTime hoje = new LocalDateTime(System.currentTimeMillis());
    for (int i = 0; i < tb.getRowCount(); i++) {
        String in = tb.getValueAt(i, 3).toString();
        String out = tb.getValueAt(i, 4).toString();
        LocalDateTime inicio = new LocalDateTime(in);
        LocalDateTime fim = new LocalDateTime(out);
        tb.setValueAt("" + inicio.getDayOfMonth() + "/" + inicio.getMonthOfYear() + "/" + inicio.getYear() + "",
                i, 3);//  w w  w.  j a v  a 2 s. co  m
        tb.setValueAt("" + fim.getDayOfMonth() + "/" + fim.getMonthOfYear() + "/" + fim.getYear() + "", i, 4);

        Period p = new Period(hoje, fim);
        int dias = p.getDays();
        int horas = p.getHours();
        int month = p.getMonths();
        //System.out.println(dias+":"+horas+" :: ENTRE AS DATAS "+fim.toString()+" :: "+hoje.toString());
        if (dias < 1) {
            if (dias == 0) {
                tb.setValueAt("Atraso " + horas * -1 + "h", i, 5);
                if (horas > 0)
                    tb.setValueAt("Restam " + horas + "h", i, 5);
            } else
                tb.setValueAt("Atraso " + dias * -1 + "d:" + horas * -1 + "h", i, 5);

        }
        /*else 
        if (month >= 0)
            tb.setValueAt("Restam "+dias+"d:"+horas+"h", i, 5); 
        else
            tb.setValueAt("Restam "+month+" meses", i, 5); */
    }
    return tb;
}

From source file:control.LivroController.java

public static List<String> volumeToString(Volume v) {
    if (v != null) {
        Volume.VolumeInfo volumeInfo = v.getVolumeInfo();
        Volume.SaleInfo saleInfo = v.getSaleInfo();
        LocalDateTime ldt;//from www.ja v a  2s  . c  om
        Volume.VolumeInfo.ImageLinks links = null;
        String smallThumbLink = "";
        String title = "";
        String author = "";
        String genr = "";
        String identifier = "";
        String pageCount = "";
        String price = "";
        String rating = "";
        String publisher = "";
        String description = "";

        /* Link da thumb */
        links = volumeInfo.getImageLinks();
        if (links != null)
            smallThumbLink = links.getSmallThumbnail();

        /* Ttulo */
        title = "" + v.getVolumeInfo().getTitle() + "";
        if (v.getVolumeInfo().getSubtitle() != null)
            title = title.concat(" - " + v.getVolumeInfo().getSubtitle());

        /* Autores */
        java.util.List<String> authors = v.getVolumeInfo().getAuthors();
        if (authors != null && !authors.isEmpty()) {
            for (int i = 0; i < authors.size(); ++i) {
                author = authors.get(i);
                if (i < authors.size() - 1) {
                    author = author.concat(", ");
                }
            }
        }

        /* Editora e Data de publicao */
        if (volumeInfo.getPublisher() != null)
            publisher = volumeInfo.getPublisher();
        if (volumeInfo.getPublishedDate() != null) {
            ldt = new LocalDateTime(volumeInfo.getPublishedDate());
            publisher = publisher
                    .concat(", " + +ldt.getDayOfMonth() + "/" + ldt.getMonthOfYear() + "/" + ldt.getYear());
        }

        /* Descrio */
        if (volumeInfo.getDescription() != null)
            description = "Descrio: " + volumeInfo.getDescription() + "";

        /* Gneros */
        java.util.List<String> genrs = volumeInfo.getCategories();
        if (genrs != null && !genrs.isEmpty()) {
            genr = genr.concat("Genro: ");
            if (volumeInfo.getMainCategory() != null)
                genr = genr.concat(volumeInfo.getMainCategory() + ", ");
            for (int i = 0; i < genrs.size(); ++i) {
                genr = genr.concat(genrs.get(i));
                if (i < genrs.size() - 1) {
                    genr = genr.concat(", ");
                }
            }
        }

        /* Nmero de pginas */
        if (volumeInfo.getPageCount() != null)
            pageCount = "" + volumeInfo.getPageCount() + " pginas";

        /* Identificadores */
        java.util.List<Volume.VolumeInfo.IndustryIdentifiers> isbn = volumeInfo.getIndustryIdentifiers();
        if (isbn != null && !isbn.isEmpty()) {
            for (Volume.VolumeInfo.IndustryIdentifiers ii : isbn) {
                identifier = identifier.concat(ii.getType() + ": " + ii.getIdentifier() + "");
            }
        }

        /* Avaliaes */
        if (volumeInfo.getRatingsCount() != null && volumeInfo.getRatingsCount() > 0) {
            int fullRating = (int) Math.round(volumeInfo.getAverageRating());
            rating = "Avaliao: ";
            for (int i = 0; i < fullRating; ++i) {
                rating = rating.concat(" * ");
            }
            rating = rating.concat(" (" + volumeInfo.getRatingsCount() + " avaliaes) ");
        }

        /* Informaes de Venda */
        if (saleInfo != null && "FOR_SALE".equals(saleInfo.getSaleability())) {
            double save = saleInfo.getListPrice().getAmount() - saleInfo.getRetailPrice().getAmount();
            if (save > 0.0) {
                price = price.concat(
                        "Preo mdio: " + CURRENCY_FORMATTER.format(saleInfo.getListPrice().getAmount()));
            }
            price = price.concat(
                    ", na Google Books: " + CURRENCY_FORMATTER.format(saleInfo.getRetailPrice().getAmount()));
            if (save > 0.0) {
                price = price.concat(", voc ganha: " + CURRENCY_FORMATTER.format(save) + " ("
                        + PERCENT_FORMATTER.format(save / saleInfo.getListPrice().getAmount()) + ")");
            }
        }
        List<String> details = Arrays.asList(identifier, // 0
                title, // 1
                author, // 2
                genr, // 3
                rating, // 4
                price, // 5
                pageCount, // 6
                publisher, // 7
                description, // 8
                smallThumbLink); // 9

        return details;
    }
    return null;
}

From source file:control.TimeInvestmentControl.java

/**
 * Formlet med denne metode er at tlle n op p et rum i en given liste af
 * rum for hver gang dette rum er blevet tildelt en medarbejder ved hjlp af
 * et TimeInvestment-objekt. P en given vagts starttidspunkt. P denne mde
 * kan man stole p at alle rum i den givne liste har et count felt der
 * passer til den rigtige dato, frem for at vre tidslst (feltet angiver
 * kun et count, og er ligeglad med tiden, denne funktionalitet sikrer at
 * tiden stemmer).//  ww  w  .java 2 s  . c om
 *
 * @param rooms
 * @param currentShift
 * @param timeInvestments
 */
public void countDateAssignmentsOfRoom(ArrayList<Room> rooms, TimeInvestment currentShift,
        ArrayList<TimeInvestment> timeInvestments) {

    //Nulstil roomObjekternes count felt.
    for (Room room : rooms) {
        room.setCount(0);
    }

    if (timeInvestments.size() > 0) {
        for (int i = 0; i < timeInvestments.size(); i++) {
            String roomName = timeInvestments.get(i).getRoom().getRoomName();
            //Liner sgning. Hvis det givne rum findes s skal dets tller,
            //tlle n op.
            for (int j = 0; j < rooms.size(); j++) {
                if (roomName.equals(rooms.get(j).getRoomName())) {
                    TimeInvestment currentTI = timeInvestments.get(i);

                    LocalDateTime date = currentShift.getStartTime();
                    LocalDateTime periodStart = currentTI.getStartTime();
                    LocalDateTime periodEnd = new LocalDateTime(periodStart);
                    periodEnd = periodEnd.plus(currentTI.getHours());
                    periodEnd = periodEnd.plus(currentTI.getMinutes());
                    if (Xray.getInstance().isDateInPeriod(date, periodStart, periodEnd)) {
                        rooms.get(j).increment();
                        break; //break OK i sgning for optimering.
                    }
                    break;
                }
            }
        }

    }
}

From source file:control.Xray.java

public ArrayList<LocalDateTime> getDatesInPeriod(LocalDateTime startTime, LocalDateTime endTime) {
    ArrayList<LocalDateTime> dates = new ArrayList<>();
    LocalDateTime currentDate = new LocalDateTime(startTime);
    currentDate = currentDate.withHourOfDay(0);
    currentDate = currentDate.withMinuteOfHour(0);

    while (currentDate.isBefore(endTime)) {
        dates.add(currentDate);/*w  ww . j av a2 s  .c o  m*/
        currentDate = currentDate.plusDays(1);
    }

    return dates;
}

From source file:control.Xray.java

public void fillDatesInEndDate(ComboBox cEnd, ComboBox cStart, int monthsforward) {
    //Fyld datoer ind i comboboks til start og slutdato:
    LocalDateTime now = new LocalDateTime(cStart.getValue());
    LocalDateTime oneMonthForward = now.plusMonths(monthsforward);
    ArrayList<LocalDateTime> startDates = Xray.getInstance().getDatesInPeriod(now.plusDays(1), oneMonthForward);
    cEnd.getItems().clear();//from w  ww.  jav  a  2  s . c  o m
    for (int i = 0; i < startDates.size(); i++) {
        cEnd.getItems().add(startDates.get(i));
    }
    cEnd.getSelectionModel().selectFirst();
}

From source file:cz.zcu.kiv.formgen.core.SimpleObjectBuilder.java

License:Apache License

protected Object toProperDateType(Object obj, Class<?> type) throws ObjectBuilderException {
    if (obj == null)
        return null;

    if (Date.class.equals(type)) {
        if (obj instanceof Date)
            return obj;
        else if (obj instanceof LocalDate)
            return ((LocalDate) obj).toDate();
    }/* w  ww .  j  a  v a  2s  . c om*/

    else if (java.sql.Date.class.equals(type)) {
        if (obj instanceof java.sql.Date)
            return obj;
        else if (obj instanceof Date)
            return new java.sql.Date(((Date) obj).getTime());
        else if (obj instanceof LocalDate)
            return new java.sql.Date(((LocalDate) obj).toDate().getTime());
    }

    else if (java.sql.Time.class.equals(type)) {
        if (obj instanceof java.sql.Time)
            return obj;
        else if (obj instanceof LocalTime)
            return java.sql.Time.valueOf(((LocalTime) obj).toString());
    }

    else if (java.sql.Timestamp.class.equals(type)) {
        if (obj instanceof java.sql.Timestamp)
            return obj;
        else if (obj instanceof Date)
            return new java.sql.Timestamp(((Date) obj).getTime());
        else if (obj instanceof LocalDate)
            return new java.sql.Timestamp(((LocalDate) obj).toDate().getTime());
    }

    else if (LocalDate.class.equals(type)) {
        if (obj instanceof LocalDate)
            return obj;
        else if (obj instanceof Date)
            return new LocalDate(obj);
    }

    else if (LocalTime.class.equals(type)) {
        if (obj instanceof LocalTime)
            return obj;
    }

    else if (LocalDateTime.class.equals(type)) {
        if (obj instanceof LocalDateTime)
            return obj;
        else if (obj instanceof Date)
            return new LocalDateTime(obj);
    }

    throw new ObjectBuilderException(
            "Unsupported date/time conversion from " + obj.getClass().getName() + " to " + type.getName());
}

From source file:dao.EmprestimoDAO.java

public Emprestimo get(int id) {
    String query = "SELECT * FROM emprestimo e "
            + "INNER JOIN emprestimo_livro el ON el.id_emprestimo = e.id_emprestimo "
            + "INNER JOIN exemplar ex ON ex.id_exemplar = el.id_exemplar "
            + "INNER JOIN pessoa p ON p.id_pessoa = e.id_pessoa " + "WHERE e.id_emprestimo=" + id + "; ";
    Emprestimo e = null;//from  w w  w.  java2  s. co m
    ArrayList<Integer> ids = new ArrayList<>();
    int id_emprestimo = 0;
    int id_pessoa = 0;
    LocalDateTime data_inicio = null;
    LocalDateTime data_fim = null;
    try {
        stmt = helper.prepareStatement(query);
        ResultSet rs = stmt.executeQuery();
        if (rs.isBeforeFirst()) {
            while (rs.next()) {
                id_emprestimo = rs.getInt("id_emprestimo");
                id_pessoa = rs.getInt("id_pessoa");
                data_inicio = new LocalDateTime(rs.getString("data_inicio"));
                data_fim = new LocalDateTime(rs.getString("data_fim"));
                ids.add(rs.getInt("id_exemplar"));
            }
            e = new Emprestimo(id_emprestimo, id_pessoa, ids, data_inicio, data_fim);
        }
        if (e != null)
            System.out.println("Return " + e.toString() + " from query " + query);
        stmt.close();
        helper.close();
    } catch (SQLException ex) {
        Logger.getLogger(EmprestimoDAO.class.getName()).log(Level.SEVERE, null, ex);
    }
    return e;
}

From source file:de.appsolve.padelcampus.controller.bookings.BookingsController.java

private void validateBookingCancellation(Booking booking) throws Exception {
    if (booking == null) {
        throw new Exception(msg.get("InvalidBooking"));
    }/*w w  w.  j  ava  2 s .com*/
    if (booking.getCancelled()) {
        throw new Exception(msg.get("BookingAlreadyCancelled"));
    }
    if (booking.getOffer() == null) {
        throw new Exception(msg.get("BookingCannotBeCancelled"));
    }
    LocalDateTime now = new LocalDateTime(DEFAULT_TIMEZONE);
    LocalDateTime bookingTime = new LocalDateTime().withDate(booking.getBookingDate().getYear(),
            booking.getBookingDate().getMonthOfYear(), booking.getBookingDate().getDayOfMonth()).withTime(
                    booking.getBookingTime().getHourOfDay(), booking.getBookingTime().getMinuteOfHour(), 0, 0);
    if (now.isAfter(bookingTime)) {
        throw new Exception(msg.get("BookingCancellationDeadlineMissed"));
    }

    Duration duration = new Duration(now.toDateTime(DateTimeZone.UTC),
            bookingTime.toDateTime(DateTimeZone.UTC));
    if (duration.getStandardHours() < CANCELLATION_POLICY_DEADLINE) {
        throw new Exception(msg.get("BookingCancellationDeadlineMissed"));
    }
}

From source file:de.appsolve.padelcampus.utils.BookingUtil.java

public List<TimeSlot> getTimeSlotsForDate(LocalDate selectedDate, List<CalendarConfig> allCalendarConfigs,
        List<Booking> existingBookings, Boolean onlyFutureTimeSlots, Boolean preventOverlapping)
        throws CalendarConfigException {

    List<CalendarConfig> calendarConfigs = calendarConfigUtil.getCalendarConfigsMatchingDate(allCalendarConfigs,
            selectedDate);// www  .  ja v  a  2 s. c om
    Iterator<CalendarConfig> iterator = calendarConfigs.iterator();
    while (iterator.hasNext()) {
        CalendarConfig calendarConfig = iterator.next();
        if (isHoliday(selectedDate, calendarConfig)) {
            iterator.remove();
        }
    }

    List<TimeSlot> timeSlots = new ArrayList<>();
    if (calendarConfigs.size() > 0) {
        LocalDate today = new LocalDate(DEFAULT_TIMEZONE);

        //sort all calendar configurations for selected date by start time
        Collections.sort(calendarConfigs);

        CalendarConfig previousConfig = null;
        LocalDateTime time = null;
        LocalDateTime now = new LocalDateTime(DEFAULT_TIMEZONE);

        //generate list of bookable time slots
        int i = 0;
        for (CalendarConfig config : calendarConfigs) {
            i++;
            LocalDateTime startDateTime = getLocalDateTime(selectedDate, config.getStartTime());
            if (time == null) {
                //on first iteration
                time = startDateTime;
            } else if (!time.plusMinutes(previousConfig.getMinInterval()).equals(startDateTime)) {
                //reset basePriceLastConfig as this is a non contiguous offer
                previousConfig = null;
                time = startDateTime;
            }
            LocalDateTime endDateTime = getLocalDateTime(selectedDate, config.getEndTime());
            while (time.plusMinutes(config.getMinDuration()).compareTo(endDateTime) <= 0) {
                BigDecimal pricePerMinDuration;
                if (previousConfig == null) {
                    pricePerMinDuration = config.getBasePrice();
                } else {
                    BigDecimal previousConfigBasePricePerMinute = getPricePerMinute(previousConfig);
                    pricePerMinDuration = previousConfigBasePricePerMinute
                            .multiply(new BigDecimal(previousConfig.getMinInterval()), MathContext.DECIMAL128);
                    BigDecimal basePricePerMinute = getPricePerMinute(config);
                    pricePerMinDuration = pricePerMinDuration.add(basePricePerMinute.multiply(
                            new BigDecimal(config.getMinDuration() - previousConfig.getMinInterval()),
                            MathContext.DECIMAL128));
                    previousConfig = null;
                }
                pricePerMinDuration = pricePerMinDuration.setScale(2, RoundingMode.HALF_EVEN);
                if (onlyFutureTimeSlots) {
                    if (selectedDate.isAfter(today) || time.isAfter(now)) {
                        addTimeSlot(timeSlots, time, config, pricePerMinDuration);
                    }
                } else {
                    addTimeSlot(timeSlots, time, config, pricePerMinDuration);
                }
                time = time.plusMinutes(config.getMinInterval());
            }
            //make sure to display the last min interval of the day
            if (config.getMinInterval() < config.getMinDuration() && i == calendarConfigs.size()) {
                if (time.plusMinutes(config.getMinInterval()).compareTo(endDateTime) <= 0) {
                    addTimeSlot(timeSlots, time, config, null);
                }
            }
            previousConfig = config;
        }
        //sort time slots by time
        Collections.sort(timeSlots);

        //decrease court count for every blocking booking
        for (TimeSlot timeSlot : timeSlots) {
            checkForBookedCourts(timeSlot, existingBookings, preventOverlapping);
        }
    }
    return timeSlots;
}