Example usage for org.joda.time Weeks weeksBetween

List of usage examples for org.joda.time Weeks weeksBetween

Introduction

In this page you can find the example usage for org.joda.time Weeks weeksBetween.

Prototype

public static Weeks weeksBetween(ReadablePartial start, ReadablePartial end) 

Source Link

Document

Creates a Weeks representing the number of whole weeks between the two specified partial datetimes.

Usage

From source file:org.easy.scrum.model.embedded.PersistentPeriod.java

License:Apache License

public int getWeeksBetween() {
    return Weeks.weeksBetween(new DateMidnight(start.getTime()), new DateMidnight(end.getTime())).getWeeks();
}

From source file:org.gbif.crawler.scheduler.CrawlSchedulerService.java

License:Apache License

/**
 * This method checks whether a dataset should automatically be scheduled to crawl or not.
 *
 * @return {@code true} if the dataset should be crawled
 *///from  w  w  w.j a v  a2 s .co  m
private boolean isDatasetEligibleToCrawl(Dataset dataset, ReadableInstant now) {
    if (dataset.getDeleted() != null) {
        return false;
    }

    if (dataset.isExternal()) {
        return false;
    }

    PagingResponse<DatasetProcessStatus> list = registryService.listDatasetProcessStatus(dataset.getKey(),
            null);

    // We always crawl datasets that haven't been crawled before
    if (list.getResults().isEmpty()) {
        return true;
    }

    DatasetProcessStatus status = list.getResults().get(0);
    ReadableInstant lastCrawlDate = new DateTime(status.getFinishedCrawling());

    // Check whether less than a week has passed since the last crawl
    if (Weeks.weeksBetween(lastCrawlDate, now).getWeeks() < 1) {
        return false;
    }

    // Check whether the Dataset is currently being crawled
    return crawlService.getDatasetProcessStatus(dataset.getKey()) == null;
}

From source file:org.gnucash.android.model.Recurrence.java

License:Apache License

/**
 * Returns the number of periods from the start date of this recurrence until the end of the
 * interval multiplier specified in the {@link PeriodType}
 * //fixme: Improve the documentation/*from   w  w  w .jav a2s.com*/
 * @return Number of periods in this recurrence
 */
public int getNumberOfPeriods(int numberOfPeriods) {
    LocalDate startDate = new LocalDate(mPeriodStart.getTime());
    LocalDate endDate;
    int interval = mPeriodType.getMultiplier();
    //// TODO: 15.08.2016 Why do we add the number of periods. maybe rename method or param
    switch (mPeriodType) {

    case DAY:
        return 1;
    case WEEK:
        endDate = startDate.dayOfWeek().withMaximumValue().plusWeeks(numberOfPeriods);
        return Weeks.weeksBetween(startDate, endDate).getWeeks() / interval;
    case MONTH:
        endDate = startDate.dayOfMonth().withMaximumValue().plusMonths(numberOfPeriods);
        return Months.monthsBetween(startDate, endDate).getMonths() / interval;
    case YEAR:
        endDate = startDate.dayOfYear().withMaximumValue().plusYears(numberOfPeriods);
        return Years.yearsBetween(startDate, endDate).getYears() / interval;
    }

    return 0;
}

From source file:org.goobi.managedbeans.ProjectBean.java

License:Open Source License

private Double getThroughputPerDay() {
    DateTime start = new DateTime(this.myProjekt.getStartDate().getTime());
    DateTime end = new DateTime(this.myProjekt.getEndDate().getTime());
    Weeks weeks = Weeks.weeksBetween(start, end);
    logger.trace(weeks.getWeeks());/*from www.  ja  v a2  s.c om*/
    int days = (weeks.getWeeks() * 5);

    if (days < 1) {
        days = 1;
    }
    double back = (double) this.myProjekt.getNumberOfVolumes() / (double) days;
    return back;
}

From source file:org.goobi.managedbeans.ProjectBean.java

License:Open Source License

/**
 * calculate throughput of pages per day
 * //from  ww w .  j  av a 2 s .com
 * @return calculation
 */

private Double getThroughputPagesPerDay() {
    DateTime start = new DateTime(this.myProjekt.getStartDate().getTime());
    DateTime end = new DateTime(this.myProjekt.getEndDate().getTime());

    Weeks weeks = Weeks.weeksBetween(start, end);
    int days = (weeks.getWeeks() * 5);
    if (days < 1) {
        days = 1;
    }
    double back = (double) this.myProjekt.getNumberOfPages() / (double) days;
    return back;
}

From source file:org.jhub1.agent.statistics.SmartDateDisplay.java

License:Open Source License

public static String showHowLong(DateTime rDate) {
    StringBuilder sb = new StringBuilder();
    DateTime dt = new DateTime();
    Weeks w = Weeks.weeksBetween(rDate, dt);
    Days d = Days.daysBetween(rDate, dt);
    Hours h = Hours.hoursBetween(rDate, dt);
    Minutes m = Minutes.minutesBetween(rDate, dt);
    Seconds s = Seconds.secondsBetween(rDate, dt);
    if (s.getSeconds() != 0) {
        sb.append(s.getSeconds() % 60).append("s");
    }//from www  .j  av  a2s.c o  m
    if (m.getMinutes() != 0) {
        sb.insert(0, (m.getMinutes() % 60) + "m ");
    }
    if (h.getHours() != 0) {
        sb.insert(0, (h.getHours() % 24) + "h ");
    }
    if (d.getDays() != 0) {
        sb.insert(0, (d.getDays() % 7) + "d ");
    }
    if (w.getWeeks() != 0) {
        sb.insert(0, w.getWeeks() + "w ");
    }
    return sb.toString();
}

From source file:org.jimcat.gui.histogram.image.DateTakenDimension.java

License:Open Source License

/**
 * this methode will reload statistical information from the library
 * /*from  ww  w . ja  va 2  s .c  om*/
 * @param library
 */
private void reloadValues(ImageLibrary library) {
    // get images
    List<Image> images = new ArrayList<Image>(library.getAll());

    // 1) find min / max date
    int i = 0;
    DateTime min = null;
    DateTime max = null;
    while (min == null && i < images.size()) {
        min = getDateTaken(images.get(i));
        max = min;
        i++;
    }

    if (min == null || max == null) {
        // result is an empty vector
        values = new int[RESOLUTION_COUNT][0];
        maxValues = new int[RESOLUTION_COUNT];
        minDate = null;
        fireStructureChangedEvent();
        return;
    }

    // iterate through images
    for (; i < images.size(); i++) {
        Image img = images.get(i);
        DateTime date = getDateTaken(img);
        if (date != null && min.isAfter(date)) {
            min = date;
        }
        if (date != null && max.isBefore(date)) {
            max = date;
        }
    }

    // save min dates
    // get references
    // must be a pure day
    DateTime dayRef = new DateTime(2000, 1, 1, 0, 0, 0, 0);

    // must be a monday
    DateTime weekRef = new DateTime(2000, 1, 3, 0, 0, 0, 0);

    // must be the first of any month
    DateTime monthRef = dayRef;

    minDate = new DateTime[RESOLUTION_COUNT];
    minDate[DAYS] = dayRef.plusDays(Days.daysBetween(dayRef, min).getDays());
    minDate[WEEKS] = weekRef.plusWeeks(Weeks.weeksBetween(weekRef, min).getWeeks());
    minDate[MONTHS] = monthRef.plusMonths(Months.monthsBetween(monthRef, min).getMonths());

    // 2) build arrays
    values = new int[RESOLUTION_COUNT][];
    values[DAYS] = new int[Days.daysBetween(minDate[DAYS], max).getDays() + 1];
    values[WEEKS] = new int[Weeks.weeksBetween(minDate[WEEKS], max).getWeeks() + 1];
    values[MONTHS] = new int[Months.monthsBetween(minDate[MONTHS], max).getMonths() + 1];

    // 3) fill in values
    for (Image img : images) {
        // extract date
        DateTime date = getDateTaken(img);
        if (date != null) {
            values[DAYS][Days.daysBetween(minDate[DAYS], date).getDays()]++;
            values[WEEKS][Weeks.weeksBetween(minDate[WEEKS], date).getWeeks()]++;
            values[MONTHS][Months.monthsBetween(minDate[MONTHS], date).getMonths()]++;
        }
    }

    // 4) get max values
    maxValues = new int[RESOLUTION_COUNT];
    for (int j = 0; j < RESOLUTION_COUNT; j++) {
        maxValues[j] = values[j][0];
        for (int k = 1; k < values[j].length; k++) {
            if (maxValues[j] < values[j][k]) {
                maxValues[j] = values[j][k];
            }
        }
    }

    // 6) notify listners
    fireStructureChangedEvent();
}

From source file:org.jimcat.gui.histogram.image.DateTakenDimension.java

License:Open Source License

/**
 * converte a given resolution / date pair to a index
 * //from   ww w.  j  a v a  2s  .  c  o  m
 * @param resolution
 * @param date
 * @return the converted index
 */
private int dateToIndex(int resolution, DateTime date) {
    if (date == null || minDate == null) {
        return 0;
    }

    // convert to new resolution
    switch (resolution) {
    case DAYS:
        return Days.daysBetween(minDate[DAYS], date).getDays();
    case WEEKS:
        return Weeks.weeksBetween(minDate[WEEKS], date).getWeeks();
    default:
        return Months.monthsBetween(minDate[MONTHS], date).getMonths();
    }
}

From source file:org.jimcat.model.filter.metadata.RelativeDateFilter.java

License:Open Source License

/**
 * /*from   ww  w .j a v  a2 s.  c  om*/
 * @param time
 * @return the value to compare depending on time unit set
 */
private int getCompareValue(DateTime time) {
    DateTime now = new DateTime();
    switch (timeUnit) {
    case DAYS:
        return Days.daysBetween(time, now).getDays();
    case WEEKS:
        return Weeks.weeksBetween(time, now).getWeeks();
    case MONTHS:
        return Months.monthsBetween(time, now).getMonths();
    }
    return -1;
}

From source file:org.medcada.android.db.DatabaseHandler.java

License:Open Source License

public List<Integer> getAverageGlucoseReadingsByWeek() {
    JodaTimeAndroid.init(mContext);/*from   w  ww.  ja  v  a 2s  . c  o  m*/

    DateTime maxDateTime = new DateTime(realm.where(GlucoseReading.class).maximumDate("created").getTime());
    DateTime minDateTime = new DateTime(realm.where(GlucoseReading.class).minimumDate("created").getTime());

    DateTime currentDateTime = minDateTime;
    DateTime newDateTime = minDateTime;

    ArrayList<Integer> averageReadings = new ArrayList<Integer>();

    // The number of weeks is at least 1 since we do have average for the current week even if incomplete
    int weeksNumber = Weeks.weeksBetween(minDateTime, maxDateTime).getWeeks() + 1;

    for (int i = 0; i < weeksNumber; i++) {
        newDateTime = currentDateTime.plusWeeks(1);
        RealmResults<GlucoseReading> readings = realm.where(GlucoseReading.class)
                .between("created", currentDateTime.toDate(), newDateTime.toDate()).findAll();
        averageReadings.add(((int) readings.average("reading")));
        currentDateTime = newDateTime;
    }
    return averageReadings;
}