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:org.openmrs.module.kenyaemr.calculation.BaseEmrCalculation.java

License:Open Source License

/**
 * Calculates the days since the given date
 * @param date the date//from   w  ww. ja va  2  s. c om
 * @param calculationContext the calculation context
 * @return the number of days
 */
protected static int daysSince(Date date, CalculationContext calculationContext) {
    DateTime d1 = new DateTime(date.getTime());
    DateTime d2 = new DateTime(calculationContext.getNow().getTime());
    return Days.daysBetween(d1, d2).getDays();
}

From source file:org.openmrs.module.kenyaemr.calculation.EmrCalculationUtils.java

License:Open Source License

/**
 * Calculates the days since the given date
 * @param date the date//from w  ww.j a v a  2  s .  com
 * @param calculationContext the calculation context
 * @return the number of days
 */
public static int daysSince(Date date, CalculationContext calculationContext) {
    DateTime d1 = new DateTime(date.getTime());
    DateTime d2 = new DateTime(calculationContext.getNow().getTime());
    return Days.daysBetween(d1, d2).getDays();
}

From source file:org.openmrs.module.kenyaemr.calculation.library.hiv.art.PatientPreArtOutComeCalculation.java

License:Open Source License

int daysBetweenDates(Date d1, Date d2) {
    DateTime dateTime1 = new DateTime(d1.getTime());
    DateTime dateTime2 = new DateTime(d2.getTime());
    return Math.abs(Days.daysBetween(dateTime1, dateTime2).getDays());
}

From source file:org.openmrs.module.kenyaemr.calculation.library.hiv.InCareHasAtLeast2VisitsCalculation.java

License:Open Source License

private int daysSince(Date date1, Date date2) {
    DateTime d1 = new DateTime(date1.getTime());
    DateTime d2 = new DateTime(date2.getTime());
    return Days.daysBetween(d1, d2).getDays();
}

From source file:org.openmrs.module.pihmalawi.common.AppointmentInfo.java

License:Open Source License

/**
 * @return the days remaining until the appointment date. a negative number indicates that number of days overdue. null indicates no scheduled appointment found.
 *///w ww .ja  v  a2s.  co  m
public Integer getDaysToAppointment() {

    // No scheduled appointment
    if (nextScheduledDate == null || !currentlyEnrolled) {
        return null;
    }

    // No scheduled appointment since prevoius encounter
    if (lastEncounterDate != null && nextScheduledDate.compareTo(lastEncounterDate) <= 0) {
        return null;
    }

    Date today = DateUtil.getStartOfDay(effectiveDate);
    Date apptDate = DateUtil.getStartOfDay(nextScheduledDate);
    int multiplier = apptDate.compareTo(today); // If appt date is in the past, multiply by -1

    Date fromDate = (multiplier < 0 ? apptDate : today);
    Date toDate = (multiplier < 0 ? today : apptDate);

    Days days = Days.daysBetween(new DateTime(fromDate), new DateTime(toDate.getTime()));
    return days.getDays() * multiplier;
}

From source file:org.openmrs.module.pihmalawi.reporting.definition.data.converter.DurationConverter.java

License:Open Source License

/**
 * @see DataConverter#convert(Object)//from w  w w  .j av a 2 s  . c  om
 */
public Object convert(Object original) {
    if (original != null) {
        DateTime from = new DateTime((Date) original);
        if (durationToDate == null) {
            durationToDate = new Date();
        }
        DateTime to = new DateTime(durationToDate);
        if (durationUnit == DurationUnit.YEARS) {
            return Years.yearsBetween(from, to).getYears();
        } else if (durationUnit == DurationUnit.MONTHS) {
            return Months.monthsBetween(from, to).getMonths();
        } else if (durationUnit == DurationUnit.WEEKS) {
            return Weeks.weeksBetween(from, to).getWeeks();
        } else if (durationUnit == DurationUnit.DAYS) {
            return Days.daysBetween(from, to).getDays();
        } else if (durationUnit == DurationUnit.HOURS) {
            return Hours.hoursBetween(from, to).getHours();
        } else if (durationUnit == DurationUnit.MINUTES) {
            return Minutes.minutesBetween(from, to).getMinutes();
        } else if (durationUnit == DurationUnit.SECONDS) {
            return Seconds.secondsBetween(from, to).getSeconds();
        } else {
            throw new IllegalArgumentException("Unable to convert with duration unit: " + durationUnit);
        }
    }
    return null;
}

From source file:org.openmrs.module.reporting.data.converter.AgeConverter.java

License:Open Source License

private Double getYearsToOneDecimalPlace(Age age) {
    if (age.getBirthDate() == null) {
        return null;
    }//from www.j a  v  a 2s  .  c  o  m
    Days days = Days.daysBetween(new DateTime(age.getBirthDate().getTime()),
            new DateTime((age.getCurrentDate() == null ? new Date() : age.getCurrentDate()).getTime()));
    return Math.round(10d * (days.getDays() / 365.25d)) / 10d;
}

From source file:org.opensingular.flow.core.TaskPredicates.java

License:Apache License

public static ITaskPredicate timeLimitInDays(final int numberOfDays) {
    TaskPredicateImpl taskPredicateImpl = new TaskPredicateImpl("Prazo Extrapolado " + numberOfDays + " dias",
            (taskInstance) -> {// w w  w. ja  va2s.co m
                Date date = taskInstance.getTargetEndDate();
                if (date != null) {
                    return Days.daysBetween(new DateTime(date), DateTime.now()).getDays() > numberOfDays;
                }
                return false;
            });
    taskPredicateImpl.setFullDescription("Prazo Extrapolado em " + numberOfDays + " dias");
    taskPredicateImpl.setEventType(EventType.TIMER);
    return taskPredicateImpl;
}

From source file:org.opentestsystem.delivery.testadmin.service.impl.ScheduleReportServiceImpl.java

License:Open Source License

public List<TestAdminReport> buildScheduledReport(String institutionId, DateTime startDate, DateTime endDate) {
    List<Schedule> scheduledList = scheduleRepository.findScheduleByStartDateAndEndDate(institutionId,
            startDate, endDate);/*from ww  w .ja v  a2 s.  c  o  m*/

    List<ScheduledDay> allScheduleDays = new ArrayList<ScheduledDay>();
    for (Schedule schedule : scheduledList) {
        allScheduleDays.addAll(schedule.getScheduledDays());
    }
    // Now Filter the Scheduled based on the given Date
    int days = Days.daysBetween(startDate, endDate).getDays();
    List<DateTime> rangeOfdates = new ArrayList<DateTime>();
    if (days == 0) {
        rangeOfdates.add(startDate);
    } else {
        for (int i = 0; i <= days; i++) {
            DateTime d = startDate.withFieldAdded(DurationFieldType.days(), i);
            rangeOfdates.add(d);
        }
    }
    return populateScheduleReport(allScheduleDays, rangeOfdates, institutionId);
}

From source file:org.openvpms.archetype.i18n.time.DateDurationFormatter.java

License:Open Source License

/**
 * Formats the duration between two timestamps.
 * <p/>//from   ww w.  j  ava2s.  com
 * NOTE: this currently doesn't do anything sensible for from > to. Possible solution would be to simply
 * reverse the times, and then prepend a - between each field using  the
 *
 * @param from the starting time
 * @param to   the ending time
 * @return the formatted duration
 */
protected String format(DateTime from, DateTime to) {
    int years = 0;
    int months = 0;
    int weeks = 0;
    int days = 0;
    int hours = 0;
    int minutes = 0;

    DateTime start = from;
    if (showYears) {
        years = Years.yearsBetween(start, to).getYears();
        start = start.plusYears(years);
    }
    if (showMonths) {
        months = Months.monthsBetween(start, to).getMonths();
        start = start.plusMonths(months);
    }
    if (showWeeks) {
        weeks = Weeks.weeksBetween(start, to).getWeeks();
        start = start.plusWeeks(weeks);
    }
    if (showDays) {
        days = Days.daysBetween(start, to).getDays();
        start = start.plusDays(days);
    }
    if (showHours) {
        hours = Hours.hoursBetween(start, to).getHours();
        start = start.plusHours(hours);
    }
    if (showMinutes) {
        minutes = Minutes.minutesBetween(start, to).getMinutes();
    }

    Period period = new Period(years, months, weeks, days, hours, minutes, 0, 0);
    return formatter.print(period);
}