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:com.quinsoft.epamms.ZGlobal1_Operation.java

License:Open Source License

public MutableInt GetDateAttributeDifferenceInDays(MutableInt lDays, View srcView, String srcEntityName,
        String srcAttributeName, View tgtView, String tgtEntityName, String tgtAttributeName) {
    DateTimeRecord SourceDate = null;//from w w  w.  j av  a  2  s  . c  o m
    DateTimeRecord TargetDate = null;
    String stringSourceDate = null;
    String stringTargetDate = null;
    int lDaysTmp;

    // read the attributes
    //stringSourceDate = GetStringFromAttribute( stringSourceDate, srcView, srcEntityName, srcAttributeName );
    //stringTargetDate = GetStringFromAttribute( stringTargetDate, tgtView, tgtEntityName, tgtAttributeName );

    DateTime BeginDate = srcView.cursor(srcEntityName).getAttribute(srcAttributeName).getDateTime();
    DateTime EndDate = tgtView.cursor(tgtEntityName).getAttribute(tgtAttributeName).getDateTime();

    //DateTime BeginDate = new DateTime(stringSourceDate);
    //DateTime EndDate = new DateTime(stringTargetDate);

    //int days = Days.daysBetween( BeginDate, EndDate).getDays();
    int days = Days.daysBetween(EndDate, BeginDate).getDays();
    /*
    UfStringToDateTime( stringSourceDate, SourceDate );
    UfStringToDateTime( stringTargetDate, TargetDate );
            
    // subtract the values
    lDaysTmp = lDays.intValue();
    lDaysTmp = UfDateTimeDiff( lDaysTmp, TargetDate, SourceDate, zDT_DAY );
            
    lDays.setValue(lDaysTmp);
    */

    lDays.setValue(days);

    return lDays;
}

From source file:com.quinsoft.swauopencuas.ZGLOBAL1_Operation.java

License:Open Source License

public MutableInt GetDateAttributeDifferenceInDays(MutableInt lDays, View srcView, String srcEntityName,
        String srcAttributeName, View tgtView, String tgtEntityName, String tgtAttributeName) {
    DateTimeRecord SourceDate = null;/*from   www  .j  av a2 s  .c o m*/
    DateTimeRecord TargetDate = null;
    String stringSourceDate = null;
    String stringTargetDate = null;
    int lDaysTmp;

    DateTime BeginDate = srcView.cursor(srcEntityName).getAttribute(srcAttributeName).getDateTime();
    DateTime EndDate = tgtView.cursor(tgtEntityName).getAttribute(tgtAttributeName).getDateTime();

    //int days = Days.daysBetween( BeginDate, EndDate).getDays();
    int days = Days.daysBetween(EndDate, BeginDate).getDays();

    lDays.setValue(days);

    return lDays;
}

From source file:com.r1soft.backup.server.web.dashboard.LicenseStatusPortlet.java

protected void updateLicenseInfo() {

    binder.bindBean("expanded", expanded);

    binder.bindBean("titleLabel", ELFunctions.getLabel(getPanelTitleI18NKey()));

    if (licenseInfo.getTrial()) {
        DateTime expiry = new DateTime(licenseInfo.getExpireDate());
        DateTime now = new DateTime();
        binder.bindBean("daysLeft", Days.daysBetween(new DateTime(now), new DateTime(expiry)).getDays());
    }/*from   w  w w. j  a va2  s  .  co  m*/

    int physicalServersRemainingCount = licenseInfo.getLicenseAgentCount() - licenseInfo.getCurrentAgentCount();
    double physicalServerRatio = physicalServersRemainingCount > 0
            ? (((double) licenseInfo.getCurrentAgentCount())) / ((double) licenseInfo.getLicenseAgentCount())
                    * 100D
            : 100D;

    binder.bindBean("physicalServersCount", licenseInfo.getCurrentAgentCount());
    binder.bindBean("physicalServersSclass",
            (licenseInfo.getCurrentAgentCount() > licenseInfo.getLicenseAgentCount() ? ERROR_SCLASS
                    : NEUTRAL_SCLASS));
    binder.bindBean("physicalServersRemainingCount", physicalServersRemainingCount);
    binder.bindBean("physicalServersRemainingSclass",
            physicalServersRemainingCount < 0 ? "r1-bold-red" : "r1-bold");
    binder.bindBean("physicalServersRemainingLabelSclass",
            physicalServersRemainingCount < 0 ? "r1-bold-red" : "");
    binder.bindBean("physicalServerRatio", physicalServerRatio);
    binder.bindBean("physicalServerRatioZclass",
            physicalServersRemainingCount < 0 ? "r1-dual-progressmeter-solid-red"
                    : "r1-dual-progressmeter-green-blue");

    int virtualServersRemainingCount = licenseInfo.getLicenseVirtualAgentCount()
            - licenseInfo.getCurrentVirtualAgentCount();
    double virtualServerRatio = virtualServersRemainingCount > 0
            ? (((double) licenseInfo.getCurrentVirtualAgentCount()))
                    / ((double) licenseInfo.getLicenseVirtualAgentCount()) * 100D
            : 100D;

    binder.bindBean("virtualServersCount", licenseInfo.getCurrentVirtualAgentCount());
    binder.bindBean("virtualServersSclass",
            (licenseInfo.getCurrentVirtualAgentCount() > licenseInfo.getLicenseVirtualAgentCount()
                    ? ERROR_SCLASS
                    : NEUTRAL_SCLASS));
    binder.bindBean("virtualServersRemainingCount", virtualServersRemainingCount);
    binder.bindBean("virtualServersRemainingSclass",
            virtualServersRemainingCount < 0 ? "r1-bold-red" : "r1-bold");
    binder.bindBean("virtualServersRemainingLabelSclass",
            virtualServersRemainingCount < 0 ? "r1-bold-red" : "");
    binder.bindBean("virtualServerRatio", virtualServerRatio);
    binder.bindBean("virtualServerRatioZclass",
            virtualServersRemainingCount < 0 ? "r1-dual-progressmeter-solid-red"
                    : "r1-dual-progressmeter-green-blue");

    binder.bindBean("spec", licenseInfo);

    binder.loadAll();
}

From source file:com.rapidminer.operator.GenerateDateSeries.java

License:Open Source License

private long calculateNumberOfExample(DateTime startTime, DateTime endTime) {
    // TODO Auto-generated method stub
    long valuetoReturn = 0;
    try {/*  www.j  a  v a2s  .c om*/

        //getParameterAsString(key)

        switch (getParameterAsString(PARAMETER_INTERVALTYPE)) {

        case "YEAR":
            Years year = Years.yearsBetween(startTime, endTime);
            valuetoReturn = year.getYears() / getParameterAsInt(INTERVAL);
            break;
        case "MONTH":
            Months month = Months.monthsBetween(startTime, endTime);
            valuetoReturn = month.getMonths() / getParameterAsInt(INTERVAL);
            break;

        case "DAY":
            Days days = Days.daysBetween(startTime, endTime);
            valuetoReturn = days.getDays() / getParameterAsInt(INTERVAL);

            break;

        case "HOUR":
            Hours hours = Hours.hoursBetween(startTime, endTime);
            valuetoReturn = hours.getHours() / getParameterAsInt(INTERVAL);
            break;

        case "MINUTE":
            Minutes minute = Minutes.minutesBetween(startTime, endTime);
            valuetoReturn = minute.getMinutes() / getParameterAsInt(INTERVAL);
            break;
        case "SECOND":
            Seconds second = Seconds.secondsBetween(startTime, endTime);
            valuetoReturn = second.getSeconds() / getParameterAsInt(INTERVAL);
            break;
        case "MILLISECOND":
            // Milliseconds millisecond = milli
            long milli = endTime.getMillis() - startTime.getMillis();
            valuetoReturn = milli / getParameterAsInt(INTERVAL);

            break;
        default:
            valuetoReturn = 0;
        }

    } catch (Exception e) {
        valuetoReturn = 0;
    }

    return valuetoReturn;
}

From source file:com.reclabs.recomendar.common.helpers.types.DateHelper.java

License:Open Source License

/**
 * Compare the dates given and return the difference in days
 * @param date1 first date//from   w ww.j a  v  a  2  s. co  m
 * @param date2 second date
 * @return number of difference days
 */
public static int getDateDiff(Date date1, Date date2) {
    ParameterHelper.assertAnyNull(date1, date2);
    DateTime jodaDate1 = new DateTime(date1.getTime());
    DateTime jodaDate2 = new DateTime(date2.getTime());
    return Days.daysBetween(jodaDate1, jodaDate2).getDays();
}

From source file:com.sam.moca.server.expression.operators.arith.MinusExpression.java

License:Open Source License

protected MocaValue doOper(MocaValue left, MocaValue right) {
    if (left.getType() == MocaType.DATETIME) {
        if (right.getType() == MocaType.DOUBLE || right.getType() == MocaType.INTEGER) {
            Date d = left.asDate();

            // If the left side is null, return a null result.
            if (d == null) {
                return new MocaValue(MocaType.DATETIME, null);
            }/*  w  w w .  j  a  v a 2s .co  m*/

            LocalDateTime dt = new LocalDateTime(d);

            int wholeDays = right.asInt();
            double dayPart = right.asDouble() - wholeDays;
            int msDiff = (int) (dayPart * 1000.0 * 3600.0 * 24.0);

            dt = dt.minusDays(wholeDays).minusMillis(msDiff);

            return new MocaValue(MocaType.DATETIME, dt.toDateTime().toDate());
        } else if (right.getType() == MocaType.DATETIME) {
            Date leftDate = left.asDate();
            Date rightDate = right.asDate();

            // If either the left side or the right side is null, return null
            if (leftDate == null || rightDate == null) {
                return new MocaValue(MocaType.DOUBLE, null);
            }

            DateTime leftDt = new DateTime(leftDate);
            DateTime rightDt = new DateTime(rightDate);

            int fullDays = Days.daysBetween(rightDt, leftDt).getDays();

            LocalTime leftTime = new LocalTime(leftDt);
            LocalTime rightTime = new LocalTime(rightDt);

            int ms = leftTime.getMillisOfDay() - rightTime.getMillisOfDay();
            double partial = ((double) ms / (1000.0 * 3600.0 * 24.0));

            if (partial < 0.0 && leftDate.after(rightDate)) {
                partial += 1.0;
            } else if (partial > 0.0 && rightDate.after(leftDate)) {
                partial -= 1.0;
            }

            double daysDiff = (double) fullDays + partial;

            return new MocaValue(MocaType.DOUBLE, daysDiff);
        }
    } else {
        if (left.getType() == MocaType.DOUBLE || right.getType() == MocaType.DOUBLE) {
            return new MocaValue(MocaType.DOUBLE, Double.valueOf(left.asDouble() - right.asDouble()));
        } else {
            return new MocaValue(MocaType.INTEGER, Integer.valueOf(left.asInt() - right.asInt()));
        }
    }
    return null;
}

From source file:com.sapienter.jbilling.server.process.PeriodOfTime.java

License:Open Source License

/**
 * Find the number of days between the period start date to the period end date. This means
 * that the start date is counted as a days within the period, but not the end date. For example, January 01 to
 * January 10th includes 9 days total.//w w  w.  j a  va  2 s  . co  m
 *
 * This method takes into account daylight savings time to ensure that days are counted
 * correctly across DST boundaries.
 *
 * @return number of days between start and end dates
 */
public int getDaysInPeriod() {
    if (start == null || end == null || end.isBefore(start)) {
        return 0;
    }
    return Days.daysBetween(start, end).getDays();
}

From source file:com.shantanu.coursebook.server.CourseServiceImpl.java

License:Open Source License

@SuppressWarnings("deprecation")
@Override/*from w  w  w  .  j  av  a 2 s . co m*/
public ArrayList<CourseData> getCourseList(String userId, Date d) {
    // TODO Auto-generated method stub
    Key<MyUser> p = ofy().load().type(MyUser.class).id(userId).key();
    List<CourseData> ls = ofy().load().type(CourseData.class).ancestor(p).list();

    ArrayList<CourseData> arr = new ArrayList<>();

    for (CourseData cd : ls) {
        d.setHours(cd.startdate.getHours());
        d.setMinutes(cd.startdate.getMinutes());
        d.setSeconds(cd.startdate.getSeconds());
        DateTime dt1 = new DateTime(d);
        DateTime dt2 = new DateTime(cd.startdate);
        int days = Days.daysBetween(dt1, dt2).getDays();

        if (days % (7 * cd.frequency) == 0)
            arr.add(cd);
    }

    return arr;
}

From source file:com.smict.person.data.DoctorData.java

/**
 * Add doctor's workday depend on month pattern.
 * @author anubissmile/*from w  w w.  java2 s .c o m*/
 * @param DoctorModel docModel
 * @param DoctTimeModel docTimeModel
 * @return int rec | Count of record that get affected.
 */
public int addDoctorWorkdayPattern(DoctorModel docModel, DoctTimeModel docTimeModel) {
    DateUtil dt = new DateUtil();
    int key = 0;
    String[] workMonth;
    List<String> insertVal = new ArrayList<String>();
    DateTime firstOfMonth, endOfMonth, nowDate;
    DateTimeFormatter dayName = DateTimeFormat.forPattern("E");
    DateTimeFormatter fullDateTime = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    DateTimeFormatter fullDate = DateTimeFormat.forPattern("yyyy-MM-dd");
    String day, fullDay;
    String startDateTime, endDateTime;
    int workMinutes;

    /**
     * Loop month.
     */
    for (String month : docTimeModel.getWork_month()) {
        /**
         * Convert BE. to AD.
         */
        workMonth = month.split("-");
        workMonth[1] = String.valueOf(Integer.parseInt(workMonth[1]) - 543);

        /**
         * Make first date of month.
         */
        nowDate = firstOfMonth = DateTime.parse(workMonth[1] + "-" + workMonth[0] + "-" + "01");
        System.out.println(firstOfMonth);

        /**
         * Find Maximum date of month.   
         */
        endOfMonth = firstOfMonth.dayOfMonth().withMaximumValue();
        System.out.println(endOfMonth);

        /**
         * Loop day
         */
        while (Days.daysBetween(nowDate, endOfMonth).getDays() >= 0) {
            /**
             * Get day name.
             */
            day = dayName.print(nowDate);
            fullDay = fullDate.print(nowDate);
            System.out.print(day.concat(" | "));
            System.out.print(fullDay.concat(" | "));
            System.out.println(nowDate);

            /**
             * Fetch time range by day
             */
            //Mon
            // ('1', '2017-06-01 05:23:24', '2017-06-01 15:23:24', '25', '431', '0', '0000-00-00 00:00:01', '0000-00-00 00:00:01')
            if ((day.equals("Mon") || day.equals("."))
                    && (!docTimeModel.getTime_in_mon().get(key).equals("00:00")
                            || !docTimeModel.getTime_out_mon().get(key).equals("00:00"))) {
                workMinutes = Minutes.minutesBetween(LocalTime.parse(docTimeModel.getTime_in_mon().get(key)),
                        LocalTime.parse(docTimeModel.getTime_out_mon().get(key))).getMinutes();
                startDateTime = fullDate.print(nowDate).toString().concat(" ")
                        .concat(docTimeModel.getTime_in_mon().get(key)).concat(":00");
                endDateTime = fullDate.print(nowDate).toString().concat(" ")
                        .concat(docTimeModel.getTime_out_mon().get(key)).concat(":00");
                insertVal.add(" ('" + docModel.getDoctorID() + "', '" + startDateTime + "', '" + endDateTime
                        + "', '" + workMinutes + "', '" + docModel.getBranch_id()
                        + "', '0', '1', '0000-00-00 00:00:01', '0000-00-00 00:00:01') ");
                nowDate = nowDate.plusDays(1);
                continue;
            }

            //Tue
            if ((day.equals("Tue") || day.equals("."))
                    && (!docTimeModel.getTime_in_tue().get(key).equals("00:00")
                            || !docTimeModel.getTime_out_tue().get(key).equals("00:00"))) {
                workMinutes = Minutes.minutesBetween(LocalTime.parse(docTimeModel.getTime_in_tue().get(key)),
                        LocalTime.parse(docTimeModel.getTime_out_tue().get(key))).getMinutes();
                startDateTime = fullDate.print(nowDate).toString().concat(" ")
                        .concat(docTimeModel.getTime_in_tue().get(key)).concat(":00");
                endDateTime = fullDate.print(nowDate).toString().concat(" ")
                        .concat(docTimeModel.getTime_out_tue().get(key)).concat(":00");
                insertVal.add(" ('" + docModel.getDoctorID() + "', '" + startDateTime + "', '" + endDateTime
                        + "', '" + workMinutes + "', '" + docModel.getBranch_id()
                        + "', '0', '1', '0000-00-00 00:00:01', '0000-00-00 00:00:01') ");
                nowDate = nowDate.plusDays(1);
                continue;
            }

            //Wed
            if ((day.equals("Wed") || day.equals("."))
                    && (!docTimeModel.getTime_in_wed().get(key).equals("00:00")
                            || !docTimeModel.getTime_out_wed().get(key).equals("00:00"))) {
                workMinutes = Minutes.minutesBetween(LocalTime.parse(docTimeModel.getTime_in_wed().get(key)),
                        LocalTime.parse(docTimeModel.getTime_out_wed().get(key))).getMinutes();
                startDateTime = fullDate.print(nowDate).toString().concat(" ")
                        .concat(docTimeModel.getTime_in_wed().get(key)).concat(":00");
                endDateTime = fullDate.print(nowDate).toString().concat(" ")
                        .concat(docTimeModel.getTime_out_wed().get(key)).concat(":00");
                insertVal.add(" ('" + docModel.getDoctorID() + "', '" + startDateTime + "', '" + endDateTime
                        + "', '" + workMinutes + "', '" + docModel.getBranch_id()
                        + "', '0', '1', '0000-00-00 00:00:01', '0000-00-00 00:00:01') ");
                nowDate = nowDate.plusDays(1);
                continue;
            }

            //Thu
            if ((day.equals("Thu") || day.equals("."))
                    && (!docTimeModel.getTime_in_thu().get(key).equals("00:00")
                            || !docTimeModel.getTime_out_thu().get(key).equals("00:00"))) {
                workMinutes = Minutes.minutesBetween(LocalTime.parse(docTimeModel.getTime_in_thu().get(key)),
                        LocalTime.parse(docTimeModel.getTime_out_thu().get(key))).getMinutes();
                startDateTime = fullDate.print(nowDate).toString().concat(" ")
                        .concat(docTimeModel.getTime_in_thu().get(key)).concat(":00");
                endDateTime = fullDate.print(nowDate).toString().concat(" ")
                        .concat(docTimeModel.getTime_out_thu().get(key)).concat(":00");
                insertVal.add(" ('" + docModel.getDoctorID() + "', '" + startDateTime + "', '" + endDateTime
                        + "', '" + workMinutes + "', '" + docModel.getBranch_id()
                        + "', '0', '1', '0000-00-00 00:00:01', '0000-00-00 00:00:01') ");
                nowDate = nowDate.plusDays(1);
                continue;
            }

            //Fri
            if ((day.equals("Fri") || day.equals("."))
                    && (!docTimeModel.getTime_in_fri().get(key).equals("00:00")
                            || !docTimeModel.getTime_out_fri().get(key).equals("00:00"))) {
                workMinutes = Minutes.minutesBetween(LocalTime.parse(docTimeModel.getTime_in_fri().get(key)),
                        LocalTime.parse(docTimeModel.getTime_out_fri().get(key))).getMinutes();
                startDateTime = fullDate.print(nowDate).toString().concat(" ")
                        .concat(docTimeModel.getTime_in_fri().get(key)).concat(":00");
                endDateTime = fullDate.print(nowDate).toString().concat(" ")
                        .concat(docTimeModel.getTime_out_fri().get(key)).concat(":00");
                insertVal.add(" ('" + docModel.getDoctorID() + "', '" + startDateTime + "', '" + endDateTime
                        + "', '" + workMinutes + "', '" + docModel.getBranch_id()
                        + "', '0', '1', '0000-00-00 00:00:01', '0000-00-00 00:00:01') ");
                nowDate = nowDate.plusDays(1);
                continue;
            }

            //Sat
            if ((day.equals("Sat") || day.equals("."))
                    && (!docTimeModel.getTime_in_sat().get(key).equals("00:00")
                            || !docTimeModel.getTime_out_sat().get(key).equals("00:00"))) {
                workMinutes = Minutes.minutesBetween(LocalTime.parse(docTimeModel.getTime_in_sat().get(key)),
                        LocalTime.parse(docTimeModel.getTime_out_sat().get(key))).getMinutes();
                startDateTime = fullDate.print(nowDate).toString().concat(" ")
                        .concat(docTimeModel.getTime_in_sat().get(key)).concat(":00");
                endDateTime = fullDate.print(nowDate).toString().concat(" ")
                        .concat(docTimeModel.getTime_out_sat().get(key)).concat(":00");
                insertVal.add(" ('" + docModel.getDoctorID() + "', '" + startDateTime + "', '" + endDateTime
                        + "', '" + workMinutes + "', '" + docModel.getBranch_id()
                        + "', '0', '1', '0000-00-00 00:00:01', '0000-00-00 00:00:01') ");
                nowDate = nowDate.plusDays(1);
                continue;
            }

            //Sun
            if ((day.equals("Sun") || day.equals("."))
                    && (!docTimeModel.getTime_in_sun().get(key).equals("00:00")
                            || !docTimeModel.getTime_out_sun().get(key).equals("00:00"))) {
                workMinutes = Minutes.minutesBetween(LocalTime.parse(docTimeModel.getTime_in_sun().get(key)),
                        LocalTime.parse(docTimeModel.getTime_out_sun().get(key))).getMinutes();
                startDateTime = fullDate.print(nowDate).toString().concat(" ")
                        .concat(docTimeModel.getTime_in_sun().get(key)).concat(":00");
                endDateTime = fullDate.print(nowDate).toString().concat(" ")
                        .concat(docTimeModel.getTime_out_sun().get(key)).concat(":00");
                insertVal.add(" ('" + docModel.getDoctorID() + "', '" + startDateTime + "', '" + endDateTime
                        + "', '" + workMinutes + "', '" + docModel.getBranch_id()
                        + "', '0', '1', '0000-00-00 00:00:01', '0000-00-00 00:00:01') ");
                nowDate = nowDate.plusDays(1);
                continue;
            }

            /**
             * Plus one day.
             */
            nowDate = nowDate.plusDays(1);
        }

        ++key;
    }

    String SQL = StringUtils.join(insertVal, ", ");
    SQL = "INSERT INTO `doctor_workday` " + "(`doctor_id`, `start_datetime`, " + "`end_datetime`, `work_hour`, "
            + "`branch_id`, `branch_room_id`, " + "`checkin_status`, `checkin_datetime`, `checkout_datetime`) "
            + "VALUES ".concat(SQL);

    agent.connectMySQL();
    agent.begin();
    int rec = agent.exeUpdate(SQL);
    agent.commit();
    agent.disconnectMySQL();

    return rec;
}

From source file:com.soen.smbank.utils.DateUtil.java

public static int DateDifference(DateTime fromDate, DateTime toDate) {
    int days = Days.daysBetween(fromDate, toDate).getDays();
    return days;//from  w  w  w . j av  a 2 s . c  om

}