Example usage for org.joda.time Days daysBetween

List of usage examples for org.joda.time Days daysBetween

Introduction

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

Prototype

public static Days daysBetween(ReadablePartial start, ReadablePartial end) 

Source Link

Document

Creates a Days representing the number of whole days between the two specified partial datetimes.

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  .  j a va 2  s .  co  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:UpdateTransaction.java

private int getDaysDiff(java.util.Date startdate, java.util.Date enddate) {
    DateTime start = new DateTime(startdate);
    DateTime end = new DateTime(enddate);

    int days = Days.daysBetween(start, end).getDays();
    return days;// w w w.  j a  v a  2  s.  c o m

}

From source file:DataConverter.java

public static Invoice[] readInvoice(Person[] persons, Customer[] customers, Product[] products) {
    try {//from  w ww. j av  a  2 s . c  o m
        Scanner s = new Scanner(new FileReader("data/Invoices.dat"));
        int count = s.nextInt(); //Number of entries. 
        Invoice[] invoices = new Invoice[count]; //Array to hold invoices
        int iterator = 0;
        s.nextLine(); //Advance scanner to nextline
        while (s.hasNext()) {
            String inLine = s.nextLine(); //Make a string out of the next line
            String[] info;
            String[] invProducts; //Use this to handle product situation
            info = inLine.split(";"); //Create array of strings from each line, ; delimited
            //First, instantiate new invoice object
            invoices[iterator] = new Invoice(info[0]);
            for (Customer c : customers) {
                if (c.getCustomerCode().equalsIgnoreCase(info[1])) {
                    invoices[iterator].setCustomer(c);
                }
            } //End customers for each
            for (Person p : persons) {
                if (p.getPersonCode().equals(info[2])) {
                    invoices[iterator].setSalesPerson(p);
                }
            } // End persons for each

            //This is a String array of product information
            invProducts = info[3].split(",");
            for (String x : invProducts) {
                int index = x.indexOf(":"); //Get index of occurence of ":"
                String code = x.substring(0, index); //This is the product code
                for (Product p : products) { //Iterate over each product in product array
                    if (p.getCode().equals(code)) {
                        if (p.getClass().getSimpleName().equals("Equipment")) {
                            invoices[iterator].addProduct(p, Integer.parseInt(x.substring(index + 1)));
                        } else if (p.getClass().getSimpleName().equals("Consultation")) {
                            invoices[iterator].addProduct(p, Integer.parseInt(x.substring(index + 1)));
                        } else if (p.getClass().getSimpleName().equals("License")) {
                            //First we need to get the number of days
                            int index2; //PLacekeeper for substring formation
                            DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd");

                            index2 = x.indexOf(":", index + 1); //Move index to next ":"

                            String start = x.substring(index + 1, index2);
                            String end = x.substring(index2 + 1);

                            DateTime begin = new DateTime(DateTime.parse(start, fmt));
                            DateTime finish = new DateTime(DateTime.parse(end, fmt));
                            int period = Days.daysBetween(begin, finish).getDays();
                            invoices[iterator].addProduct(p, period);
                        }
                    }
                } //End for each product loop
            } //End for stringx:invProducts 

            iterator++;
        } //End while
        s.close();
        return invoices;
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }

}

From source file:AdminLogCreator.java

public void processForExecutions(String testName, File logDir)
        throws SAXException, ParserConfigurationException, IOException {
    setTestName(testName);//www  .j  av  a 2  s.c o m
    String[] rootDirs = logDir.list();
    if (null != rootDirs && 0 < rootDirs.length) {
        Arrays.sort(rootDirs);
        for (int i = 0; i < rootDirs.length; i++) {
            String[] dirs = new File(logDir, rootDirs[i]).list();
            if (null != dirs && 0 < dirs.length) {
                Arrays.sort(dirs);
                for (int j = 0; j < dirs.length; j++) {
                    if (new File(new File(new File(logDir, rootDirs[i]), dirs[j]), "session.xml").exists()) {
                        File sessionFile = new File(new File(new File(logDir, rootDirs[i]), dirs[j]),
                                "session.xml");
                        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                        dbf.setNamespaceAware(true);
                        DocumentBuilder db = dbf.newDocumentBuilder();
                        Document doc = db.parse(sessionFile);
                        Element session = (Element) (doc.getElementsByTagName("session").item(0));
                        if ((session.getAttribute("sourcesId")).contains(testName)) {
                            Path file = sessionFile.toPath();
                            BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);
                            DateTime fileCreationTime = new DateTime(attr.creationTime().toString());
                            DateTime currentTime = DateTime.now();
                            int countDay = Days.daysBetween(fileCreationTime, currentTime).getDays();
                            if (countDay <= 30) {
                                setCountLastMonth();
                                setCountLast3Month();
                                setCountLastYear();
                                setCountAllTime();
                            } else if (countDay > 30 && countDay <= 90) {
                                setCountLast3Month();
                                setCountLastYear();
                                setCountAllTime();
                            } else if (countDay > 90 && countDay <= 365) {
                                setCountLastYear();
                                setCountAllTime();
                            } else {
                                setCountAllTime();
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:AdminLogCreator.java

public void processForUsers(String testName, File logDir)
        throws SAXException, ParserConfigurationException, IOException {
    setTestName(testName);//from   w  ww.j  a  v  a 2s  .  c om
    String[] rootDirs = logDir.list();
    if (null != rootDirs && 0 < rootDirs.length) {
        Arrays.sort(rootDirs);
        for (int i = 0; i < rootDirs.length; i++) {
            innercountLastMonth = 0;
            innercountLast3Month = 0;
            innercountLastYear = 0;
            innercountAllTime = 0;
            String[] dirs = new File(logDir, rootDirs[i]).list();
            if (null != dirs && 0 < dirs.length) {
                Arrays.sort(dirs);
                for (int j = 0; j < dirs.length; j++) {
                    if (new File(new File(new File(logDir, rootDirs[i]), dirs[j]), "session.xml").exists()) {
                        File sessionFile = new File(new File(new File(logDir, rootDirs[i]), dirs[j]),
                                "session.xml");
                        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                        dbf.setNamespaceAware(true);
                        DocumentBuilder db = dbf.newDocumentBuilder();
                        Document doc = db.parse(sessionFile);
                        Element session = (Element) (doc.getElementsByTagName("session").item(0));
                        if ((session.getAttribute("sourcesId")).contains(testName)) {
                            Path file = sessionFile.toPath();
                            BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);
                            DateTime fileCreationTime = new DateTime(attr.creationTime().toString());
                            DateTime currentTime = DateTime.now();
                            int countDay = Days.daysBetween(fileCreationTime, currentTime).getDays();
                            if (countDay <= 30) {
                                innercountLastMonth = 1;
                            } else if (countDay > 30 && countDay <= 90) {
                                innercountLast3Month = 1;
                            } else if (countDay > 90 && countDay <= 365) {
                                innercountLastYear = 1;
                            } else {
                                innercountAllTime = 1;
                            }
                        }
                    }
                }
            }
            if (innercountLastMonth == 1) {
                setCountLastMonth();
                setCountLast3Month();
                setCountLastYear();
                setCountAllTime();
            } else if (innercountLast3Month == 1) {
                setCountLast3Month();
                setCountLastYear();
                setCountAllTime();
            } else if (innercountLastYear == 1) {
                setCountLastYear();
                setCountAllTime();
            } else if (innercountAllTime == 1) {
                setCountAllTime();
            }
        }
    }
}

From source file:UpdateCustomer.java

private int getDaysDiff(java.util.Date startdate, java.util.Date enddate) {
    DateTime start = new DateTime(startdate.getYear(), startdate.getMonth(), startdate.getDay(), 0, 0, 0, 0);
    DateTime end = new DateTime(enddate.getYear(), enddate.getMonth(), enddate.getDay(), 0, 0, 0, 0);

    int days = Days.daysBetween(start, end).getDays();
    return days;// w ww .  j a v  a 2s  . c om
}

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;// w w w .  ja  v  a2 s .  c  om

    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:AddCustomer.java

private int getDaysDiff(java.util.Date startdate, java.util.Date enddate) {
    DateTime start = new DateTime(startdate.getYear(), startdate.getMonth(), startdate.getDay(), 0, 0, 0, 0);
    DateTime end = new DateTime(enddate.getYear(), enddate.getMonth(), enddate.getDay(), 0, 0, 0, 0);

    int days = Days.daysBetween(start, end).getDays();
    return days;//from   w w  w  .ja  v  a2  s.  com

}

From source file:account.logic.AccountController.java

@FXML
public void paymentDays(String username) throws ParseException, SQLException {
    this.username = username;
    Boolean b = false;/*from  ww w .  ja  v a 2 s  .  com*/
    String paymentDate = "";
    Database db = new Database();
    b = db.checkSub(username);
    if (b) {
        int daysLeft = 0;

        SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
        Date date = new Date();

        Date d1 = null;
        Date d2 = null;

        int customerID = db.getCustomerID(username);
        String dlp = db.getLastPayment(customerID);

        String de = format.format(date);

        try {
            d1 = format.parse(dlp);
            d2 = format.parse(de);

            DateTime dt1 = new DateTime(d1);
            DateTime dt2 = new DateTime(d2);

            Calendar day = Calendar.getInstance();
            int days = day.getActualMaximum(Calendar.DAY_OF_MONTH);
            int daysBetween = Days.daysBetween(dt1, dt2).getDays();
            daysLeft = days - daysBetween;
            payment.setText(Integer.toString(daysLeft) + " days");
            lastPayment.setText(dlp);

        } catch (Exception e) {
            e.printStackTrace();
        }
        if (daysLeft != 0) {
            pay.setDisable(true);
        } else if (daysLeft < 0) {
            db.deleteSubRecord(customerID);
            db.paymentMissed(customerID);
        }
    } else {
        paymentlabel.setVisible(false);
        payDue.setVisible(false);
        subscribelabel.setVisible(true);
        todaylabel.setVisible(true);
        lplabel.setVisible(false);
        pay.setVisible(false);
        payment.setVisible(false);
        lastPayment.setVisible(false);
        changesub.setVisible(true);

    }

}

From source file:account.logic.AccountController.java

public boolean checkDeviceDate(int deviceID) {
    Boolean isOneMonth = false;//from   w  w w  .j a va 2s.co  m
    Database db = new Database();
    String id = db.dateDeviceAdded(deviceID);

    SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
    Date date = new Date();

    Date d1 = null;
    Date d2 = null;

    String da = id;
    String de = format.format(date);
    try {
        d1 = format.parse(da);
        d2 = format.parse(de);

        DateTime dt1 = new DateTime(d1);
        DateTime dt2 = new DateTime(d1);

        int daysBetween = Days.daysBetween(dt1, dt2).getDays();
        System.out.println(daysBetween + "daysbetween");
        if (daysBetween > 30) {
            isOneMonth = true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return isOneMonth;
}