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:module.mission.domain.PersonelExpenseItem.java

License:Open Source License

public int calculateNumberOfDays() {
    final LocalDate startDate = getStart().toLocalDate();
    final LocalDate endDate = getEnd().toLocalDate().plusDays(1);
    return Days.daysBetween(startDate, endDate).getDays();
}

From source file:module.Prescriptions.ViewAndPrintPrescription.java

public String ifPrescriptionIsValid() {
    int days = Days.daysBetween(new DateTime(this.currentPrescription.getStartDate()),
            new DateTime(this.currentPrescription.getendDate())).getDays();
    if (days < 0) {
        return "Expired";
    }/* w w w.j a  va 2  s  . c o  m*/
    return days + " days";
}

From source file:net.cbtltd.rest.nextpax.A_Handler.java

License:Open Source License

private void addToAvailableDates(SortedSet<DateTime> availableDates, String startdate, String enddate)
        throws ParseException {
    int daysBetween = Days.daysBetween(new DateTime(DF.parse(startdate)), new DateTime(DF.parse(enddate)))
            .getDays();//  w ww .  jav  a  2 s  .c o m
    DateTime startDate = new DateTime(DF.parse(startdate));
    for (int i = 0; i <= daysBetween; i++) {
        availableDates.add(startDate.withFieldAdded(DurationFieldType.days(), i));
    }
}

From source file:net.cbtltd.rest.nextpax.A_Handler.java

License:Open Source License

private void createSchedule(SortedSet<DateTime> availableDates, Product product, Date version,
        SqlSession sqlSession) {//from   w w w  .ja va 2 s  .  c  o m
    DateTime currentDate = new DateTime(version).withTime(0, 0, 0, 0);

    // create reservation if current date is less than the first date in the available dates set
    DateTime firstAvailableDate = availableDates.first();
    int daysBetween = Days.daysBetween(currentDate, availableDates.first()).getDays();
    if (daysBetween > 1) {
        PartnerService.createSchedule(sqlSession, product, currentDate.toDate(),
                firstAvailableDate.withFieldAdded(DurationFieldType.days(), -1).toDate(), version);
    }

    DateTime fromDate = firstAvailableDate;

    boolean first = true;
    for (DateTime toDate : availableDates) {
        if (first) {
            first = false;
            continue;
        }
        daysBetween = Days.daysBetween(fromDate, toDate).getDays();
        if (daysBetween > 1 && toDate.isAfterNow()) {
            PartnerService.createSchedule(sqlSession, product,
                    fromDate.withFieldAdded(DurationFieldType.days(), 1).toDate(),
                    toDate.withFieldAdded(DurationFieldType.days(), -1).toDate(), version);
        }
        fromDate = toDate;
    }
}

From source file:net.cbtltd.rest.Quote.java

public void updateExactMatch() {
    Date date = null;//  w ww  .j av a2s  .  c o  m
    Date departDate = null;
    try {
        date = JSONService.DF.parse(this.getArrive());
        departDate = JSONService.DF.parse(this.getDepart());
    } catch (ParseException ex) {
        this.exactmatch = false;
        return;
    }

    if (date != null && departDate != null) {
        Boolean checkInMatch = this.getPriceCheckInDayRule() == Price.EXACTMATCH ? true : false;
        Boolean minStayMatch = false;
        if (this.getMinstay() != null) {
            minStayMatch = this.getMinstay() <= Days.daysBetween(new LocalDate(date), new LocalDate(departDate))
                    .getDays() ? true : false;
            if (checkInMatch && minStayMatch) {
                this.exactmatch = true;
                return;
            }
        }
        this.exactmatch = false;
        this.suggestedby = new ArrayList<String>();
        if (!minStayMatch) {
            this.suggestedby.add(Quote.SUGGESTED_BY_MIN_STAY);
        }
        if (!checkInMatch) {
            this.suggestedby.add(Quote.SUGGESTED_BY_CHECK_IN);
        }
    }
}

From source file:net.cbtltd.rest.yandex.A_Handler.java

License:Open Source License

private void createSchedule(SortedSet<DateTime> availableDates, Product product, Date version,
        SqlSession sqlSession) {//from w  w  w  .  j  a v a2s  .  c o  m
    DateTime currentDate = new DateTime(version).withTime(0, 0, 0, 0);

    // create reservation if current date is less than the first date in the available dates set
    DateTime firstAvailableDate = availableDates.first();
    System.out.println("firstAvailableDate = " + firstAvailableDate);
    int daysBetween = Days.daysBetween(currentDate, availableDates.first()).getDays();
    System.out.println("createSchedule daysBetween: " + daysBetween);
    System.out.println("daysBetween = " + currentDate + ",  " + availableDates.first());
    if (daysBetween > 1) {
        PartnerService.createSchedule(sqlSession, product, currentDate.toDate(),
                firstAvailableDate.withFieldAdded(DurationFieldType.days(), -1).toDate(), version);
    }

    DateTime fromDate = firstAvailableDate;

    boolean first = true;
    System.out.println("availableDates size = " + availableDates.size());
    for (DateTime toDate : availableDates) {
        if (first) {
            first = false;
            continue;
        }
        daysBetween = Days.daysBetween(fromDate, toDate).getDays();
        if (daysBetween > 1 && toDate.isAfterNow()) {
            System.out.println("createSchedule availableDates daysBetween: " + daysBetween);
            PartnerService.createSchedule(sqlSession, product,
                    fromDate.withFieldAdded(DurationFieldType.days(), 1).toDate(),
                    toDate.withFieldAdded(DurationFieldType.days(), -1).toDate(), version);
        }
        fromDate = toDate;
    }
}

From source file:net.rrm.ehour.report.reports.element.AssignmentAggregateReportElement.java

License:Open Source License

/**
 * Get the progress (booked hours) in percentage of the allotted hours, leaving out the overrun
 * or for date ranges use the current date vs start & end date (if they're both null)
 *//*  w  w  w  . j a  v  a  2s  .co  m*/
public Optional<Float> getProgressPercentage() {
    Optional<Float> percentage = Optional.absent();

    if (projectAssignment == null) {
        return Optional.absent();
    }

    if (projectAssignment.getAssignmentType().isAllottedType()) {
        if (hours != null && projectAssignment.getAllottedHours() != null && hours.floatValue() > 0
                && projectAssignment.getAllottedHours() > 0) {
            percentage = Optional.of((hours.floatValue() / projectAssignment.getAllottedHours()) * 100);

        }
    } else if (projectAssignment.getAssignmentType().isDateType() && projectAssignment.getDateStart() != null
            && projectAssignment.getDateEnd() != null) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime start = new LocalDateTime(projectAssignment.getDateStart());
        LocalDateTime end = new LocalDateTime(projectAssignment.getDateEnd());

        if (now.isBefore(start)) {
            percentage = Optional.of(0f);
        } else if (now.isAfter(end)) {
            percentage = Optional.of(100f);
        } else {
            float totalRange = Days.daysBetween(start, end).getDays();
            float daysConsumed = Days.daysBetween(start, now).getDays();

            percentage = Optional.of((daysConsumed / totalRange) * 100);
        }

        // if percentage is above 100 for daterange the user can't book anymore hours
        // so don't display more than 100%
        if (percentage.get() > 100) {
            percentage = Optional.of(100f);
        }
    }

    return percentage;
}

From source file:net.sf.jasperreports.functions.standard.DateTimeFunctions.java

License:Open Source License

/**
 * Returns the number of working days between two dates (inclusive). Saturday and Sunday are not considered working days.
 *//*from ww  w . j ava  2s  .c om*/
@Function("NETWORKDAYS")
@FunctionParameters({ @FunctionParameter("startDate"), @FunctionParameter("endDate") })
public Integer NETWORKDAYS(Object startDate, Object endDate) {
    Date startDateObj = convertDateObject(startDate);
    if (startDateObj == null) {
        logCannotConvertToDate();
        return null;
    }
    Date endDateObj = convertDateObject(endDate);
    if (endDateObj == null) {
        logCannotConvertToDate();
        return null;
    } else {
        DateTime cursorDateTime = new DateTime(startDateObj);
        DateTime endDateTime = new DateTime(endDateObj);
        int workingDays = 0;
        if (cursorDateTime.isAfter(endDateTime)) {
            // Swap data information
            DateTime tmp = cursorDateTime;
            cursorDateTime = endDateTime;
            endDateTime = tmp;
        }
        while (Days.daysBetween(cursorDateTime, endDateTime).getDays() > 0) {
            int dayOfWeek = cursorDateTime.getDayOfWeek();
            if (!(dayOfWeek == DateTimeConstants.SATURDAY || dayOfWeek == DateTimeConstants.SUNDAY)) {
                workingDays++;
            }
            cursorDateTime = cursorDateTime.plusDays(1);
        }
        return workingDays;
    }
}

From source file:net.sf.jasperreports.functions.standard.DateTimeFunctions.java

License:Open Source License

/**
 * Returns the number of days between two dates.
 *///from w w  w  . j a va 2s  . c  o  m
@Function("DAYS")
@FunctionParameters({ @FunctionParameter("startDate"), @FunctionParameter("endDate") })
public Integer DAYS(Object startDate, Object endDate) {
    Date startDateObj = convertDateObject(startDate);
    if (startDateObj == null) {
        logCannotConvertToDate();
        return null;
    }
    Date endDateObj = convertDateObject(endDate);
    if (endDateObj == null) {
        logCannotConvertToDate();
        return null;
    } else {
        DateTime dt1 = new DateTime(startDateObj);
        DateTime dt2 = new DateTime(endDateObj);
        return Days.daysBetween(dt1, dt2).getDays();
    }
}

From source file:net.sourceforge.fenixedu.domain.accessControl.NotUpdatedAlumniInfoForSpecificDaysGroup.java

License:Open Source License

private boolean notRecentlyUpdated(DateTime now, DateTime lastModifiedDate) {
    Days days = Days.daysBetween(lastModifiedDate, now);
    return days.getDays() > daysNotUpdated;
}