Example usage for org.joda.time LocalDate withFieldAdded

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

Introduction

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

Prototype

public LocalDate withFieldAdded(DurationFieldType fieldType, int amount) 

Source Link

Document

Returns a copy of this date with the value of the specified field increased.

Usage

From source file:com.graph.line.LineGraphData.java

public LineGraphData(String timeIn, String timeOut) {
    java.sql.Connection con = null;
    java.sql.PreparedStatement stmt = null;
    java.sql.ResultSet rs = null;
    try {/*from  w  w  w  .  ja v  a 2  s. co  m*/
        con = ControlPanelPool.getInstance().getConnection();
        DateTimeFormatter format = org.joda.time.format.DateTimeFormat.forPattern("MM/dd/yyyy");
        LocalDate startDate = LocalDate.parse(timeIn, format);
        LocalDate endDate = LocalDate.parse(timeOut, format);
        int days = Days.daysBetween(startDate, endDate).getDays();
        //List<LocalDate> dates = new ArrayList<>(days);
        sessionCount = new ArrayList<>();
        addressCount = new ArrayList<>();
        dateCount = new ArrayList<>();
        for (int i = 0; i < days; i++) {
            LocalDate d2 = startDate.withFieldAdded(DurationFieldType.days(), i + 1);
            //dates.add(d);
            stmt = con.prepareStatement(
                    "SELECT COUNT(DISTINCT remoteAddress) as remoteAdd, COUNT(DISTINCT sessionId) as sess FROM leadSession WHERE timeIn > CONVERT(date, ?) AND timeIn < CONVERT(date, ?)");
            stmt.setString(1, startDate.withFieldAdded(DurationFieldType.days(), i).toString());
            stmt.setString(2, startDate.withFieldAdded(DurationFieldType.days(), i + 1).toString());
            rs = stmt.executeQuery();
            while (rs.next()) {
                sessionCount.add(rs.getString("sess"));
                addressCount.add(rs.getString("remoteAdd"));
            }
            dateCount.add(startDate.withFieldAdded(DurationFieldType.days(), i).toString());
        }
        con.close();
    } catch (IOException | SQLException | PropertyVetoException ex) {
        Logger.getLogger(LineGraphData.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        DbUtils.closeQuietly(con, stmt, rs);
    }
}