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:broadwick.BroadwickConstants.java

License:Apache License

/**
 * Convert a date object to an integer (number of days from a fixed start date, here 1/1/1900). All dates in the
 * database are stored as integer values using this method.
 * @param date the date object we are converting.
 * @return the number of days from a fixed 'zero date'.
 *//*from  w  w w. j a  v  a2s.  co  m*/
public static int getDate(final DateTime date) {
    return Days.daysBetween(ZERO_DATE, date).getDays();
}

From source file:bussinessLogic.manageSR.java

public List<WrisSR> getSRsNeedingReview() {
    List<WrisSR> srList;/*from  w  w  w . ja  v a2 s.  co  m*/
    ArrayList<WrisSR> srReviewList = new ArrayList();
    srList = wrisSRFacade.findAll();
    for (int i = 0; i < srList.size(); i++) {
        if (srList.get(i).getReqStatus().equalsIgnoreCase("new") && Days
                .daysBetween(new DateTime(), new DateTime(srList.get(i).getCreateDate())).getDays() >= 3) {
            srReviewList.add(srList.get(i));
        }
    }
    return srReviewList;
}

From source file:ca.farrelltonsolar.classic.CalendarAdapter.java

License:Apache License

public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;/*from   www . j  a v a  2s  .  c  o  m*/

    if (convertView == null) { // if it's not recycled, initialize some attributes
        LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.calendar_item, null);

    }
    v.setEnabled(false);
    v.setClickable(false);
    v.setFocusable(false);
    TextView dayView = (TextView) v.findViewById(R.id.date);
    dayView.setEnabled(false);
    dayView.setClickable(false);
    dayView.setFocusable(false);
    TextView stateView = (TextView) v.findViewById(R.id.state);
    TextView floatView = (TextView) v.findViewById(R.id.isfloat);
    TextView hiPower = (TextView) v.findViewById(R.id.hiPower);
    TextView hiTemp = (TextView) v.findViewById(R.id.hiTemp);
    TextView hiPVVolt = (TextView) v.findViewById(R.id.hiPVVolt);
    TextView hiBatVolt = (TextView) v.findViewById(R.id.hiBatVolt);

    if (position >= firstDayOfFirstWeek && position <= lastDayOfMonth + firstDayOfFirstWeek) {
        try {

            DateTime cellDate = month.withDayOfMonth(position - firstDayOfFirstWeek + 1);
            if (cellDate.compareTo(today) < 0) {
                int dif = Days.daysBetween(cellDate, today).getDays() - 1;
                if (powerDays != null) {
                    if (dif >= 0 && dif < powerDays.length) {
                        String t = String.valueOf(powerDays[dif] / 10.0f) + " kWh";
                        if (floatDays[dif] > 0) {
                            floatView.setText(context.getString(R.string.CalendarFloat));
                        }
                        stateView.setText(t);
                    }
                }
                if (highPowerDays != null) {
                    if (dif >= 0 && dif < highPowerDays.length) {
                        int pd = (int) highPowerDays[dif];
                        String t = String.valueOf(pd) + " w";
                        hiPower.setText(t);
                    }
                }
                if (highTempDays != null) {
                    if (dif >= 0 && dif < highTempDays.length) {
                        float temp = highTempDays[dif] / 10.0f;
                        if (MonitorApplication.chargeControllers().useFahrenheit()) {
                            temp = temp * 1.8f + 32f;
                        }
                        String t = String.format("%.1f", temp) + "\u00b0";
                        hiTemp.setText(t);
                    }
                }
                if (highPVVoltDays != null) {
                    if (dif >= 0 && dif < highPVVoltDays.length) {
                        String t = String.valueOf(highPVVoltDays[dif] / 10.0f) + " v";
                        hiPVVolt.setText(t);
                    }
                }
                if (hiBatVoltDays != null) {
                    if (dif >= 0 && dif < hiBatVoltDays.length) {
                        String t = String.valueOf(hiBatVoltDays[dif] / 10.0f) + " v";
                        hiBatVolt.setText(t);
                    }
                }

                AutofitHelper.create(stateView);
                AutofitHelper.create(floatView);
                AutofitHelper.create(hiPower);
                AutofitHelper.create(hiTemp);
                AutofitHelper.create(hiPVVolt);
                AutofitHelper.create(hiBatVolt);
            } else {
                stateView.setText("");
                floatView.setText("");
                hiPower.setText("");
                hiTemp.setText("");
                hiPVVolt.setText("");
                hiBatVolt.setText("");
            }

            dayView.setText(days[position]);
            AutofitHelper.create(dayView);
            // mark current day as focused
            if (cellDate.compareTo(today) == 0) {
                v.setBackgroundResource(R.drawable.item_background_focused);
            } else {
                v.setBackgroundResource(R.drawable.list_item_background);
            }
        } catch (Exception ex) {
            stateView.setText("");
            floatView.setText("");
            hiPower.setText("");
            hiTemp.setText("");
            hiPVVolt.setText("");
            hiBatVolt.setText("");
            Log.w(getClass().getName(), "getView exception: " + ex);
        }
    } else {
        dayView.setText("");
        stateView.setText("");
        floatView.setText("");
        hiPower.setText("");
        hiTemp.setText("");
        hiPVVolt.setText("");
        hiBatVolt.setText("");
    }
    return v;
}

From source file:ca.farrelltonsolar.classic.PVOutputUploader.java

License:Apache License

private boolean doUpload(ChargeController controller) throws InterruptedException, IOException {
    String uploadDateString = controller.uploadDate();
    String SID = controller.getSID();
    String fName = controller.getPVOutputLogFilename();
    if (fName != null && fName.length() > 0 && SID != null && SID.length() > 0) {
        DateTime logDate = PVOutputService.LogDate();
        int numberOfDays = Constants.PVOUTPUT_RECORD_LIMIT;
        if (uploadDateString.length() > 0) {
            DateTime uploadDate = DateTime.parse(uploadDateString, DateTimeFormat.forPattern("yyyy-MM-dd"));
            numberOfDays = Days.daysBetween(uploadDate, logDate).getDays();
        }/*www  .j  a  v a2s  .  co m*/
        numberOfDays = numberOfDays > Constants.PVOUTPUT_RECORD_LIMIT ? Constants.PVOUTPUT_RECORD_LIMIT
                : numberOfDays; // limit to 20 days as per pvOutput limits
        if (numberOfDays > 0) {
            Log.d(getClass().getName(), String.format("PVOutput uploading: %s for %d days on thread: %s", fName,
                    numberOfDays, Thread.currentThread().getName()));
            DateTime now = DateTime.now();
            String UploadDate = DateTimeFormat.forPattern("yyyy-MM-dd").print(now);
            Bundle logs = load(fName);
            float[] mData = logs.getFloatArray(String.valueOf(Constants.CLASSIC_KWHOUR_DAILY_CATEGORY)); // kWh/day
            boolean uploadDateRecorded = false;
            for (int i = 0; i < numberOfDays; i++) {
                logDate = logDate.minusDays(1); // latest log entry is for yesterday
                Socket pvOutputSocket = Connect(pvOutput);
                DataOutputStream outputStream = new DataOutputStream(
                        new BufferedOutputStream(pvOutputSocket.getOutputStream()));
                String dateStamp = DateTimeFormat.forPattern("yyyyMMdd").print(logDate);
                StringBuilder feed = new StringBuilder("GET /service/r2/addoutput.jsp");
                feed.append("?key=");
                feed.append(APIKey);
                feed.append("&sid=");
                feed.append(SID);
                feed.append("&d=");
                feed.append(dateStamp);
                feed.append("&g=");
                String wh = String.valueOf(mData[i] * 100);
                feed.append(wh);
                feed.append("\r\n");
                feed.append("Host: ");
                feed.append(pvOutput);
                feed.append("\r\n");
                feed.append("\r\n");
                String resp = feed.toString();
                outputStream.writeBytes(resp);
                outputStream.flush();
                pvOutputSocket.close();
                if (uploadDateRecorded == false) {
                    controller.setUploadDate(UploadDate);
                    uploadDateRecorded = true;
                }
                Thread.sleep(Constants.PVOUTPUT_RATE_LIMIT); // rate limit
            }
            return true;
        }
    }
    return false;
}

From source file:carrental.beans.billing.BillingBean.java

private int simulateDaysUsed(ReturnProtocol returnProtocol) {
    DateTime newReturnDate = new DateTime(simulateReturnDate(returnProtocol));
    DateTime reservationDate = new DateTime(returnProtocol.getReservationDate().getTime());
    return Days.daysBetween(reservationDate.withTimeAtStartOfDay(), newReturnDate.withTimeAtStartOfDay())
            .getDays();//from w  w w.ja  va  2 s . c  o  m
}

From source file:ch.piratenpartei.pivote.serialize.DataOutput.java

License:Apache License

public void writeDateTime(LocalDateTime value) throws IOException {
    buffer.rewind();/*from  www  .  jav  a  2  s. co  m*/
    long millis = Days.daysBetween(DataIO.BASE_DATETIME, value).getDays() * DataIO.DAY_MILLIS;
    millis += value.millisOfDay().get();
    buffer.putLong(DataIO.millisToNano100(millis));
    writebuf(8);
}

From source file:cherry.common.foundation.impl.WorkdayStoreImpl.java

License:Apache License

@Transactional
@Override/*from w w  w.  ja v a  2 s .c  om*/
public int getNumberOfWorkday(String name, LocalDate from, LocalDate to) {
    SQLQuery query = queryFactory.from(h0);
    query.where(h0.name.eq(name), h0.dt.between(constant(from), constant(to)),
            h0.deletedFlg.eq(NOT_DELETED.code()));
    long count = query.uniqueResult(h0.dt.count());
    return Days.daysBetween(from, to).getDays() + 1 - (int) count;
}

From source file:cherry.example.common.foundation.impl.WorkdayStoreImpl.java

License:Apache License

@Transactional
@Override/* ww w.j a  v  a  2  s . co  m*/
public int getNumberOfWorkday(String name, LocalDate from, LocalDate to) {
    SQLQuery query = queryFactory.from(h0);
    query.where(h0.name.eq(name), h0.dt.between(from, to));
    long count = query.singleResult(h0.dt.count());
    return Days.daysBetween(from, to).getDays() + 1 - (int) count;
}

From source file:cherry.foundation.bizcal.BizYearManagerImpl.java

License:Apache License

@Override
public int getNthDayOfBizYear(LocalDate dt) {
    Range<LocalDate> range = bizYearByDate(dt).getRight();
    return Days.daysBetween(range.getMinimum(), dt).getDays() + 1;
}

From source file:cherry.foundation.bizcal.BizYearManagerImpl.java

License:Apache License

@Override
public int getNumberOfDaysOfBizYear(int bizYear) {
    Range<LocalDate> range = bizYearStrategy.rangeOfBizYear(bizYear);
    return Days.daysBetween(range.getMinimum(), range.getMaximum()).getDays() + 1;
}