Example usage for org.joda.time Period toStandardDays

List of usage examples for org.joda.time Period toStandardDays

Introduction

In this page you can find the example usage for org.joda.time Period toStandardDays.

Prototype

public Days toStandardDays() 

Source Link

Document

Converts this period to a period in days assuming a 7 day week, 24 hour day, 60 minute hour and 60 second minute.

Usage

From source file:com.jbirdvegas.mgerrit.search.AgeSearch.java

License:Apache License

/**
 * Calculates the number of days spanned in a period assuming 365 days per year, 30 days per
 * month, 7 days per week, 24 hours per day, 60 minutes per hour and 60 seconds per minute.
 * @param period A period to retrieve the number of standard days for
 * @return The number of days spanned by the period.
 *//*from   ww w. j  ava  2  s . c  om*/
protected static int getDaysInPeriod(final Period period) {
    int totalDays = 0;
    Period temp = new Period(period);
    if (period.getYears() > 0) {
        int years = period.getYears();
        totalDays += 365 * years;
        temp = temp.minusYears(years);
    }
    if (period.getMonths() > 0) {
        int months = period.getMonths();
        totalDays += 30 * period.getMonths();
        temp = temp.minusMonths(months);
    }
    return totalDays + temp.toStandardDays().getDays();
}

From source file:de.azapps.mirakel.sync.taskwarrior.model.TaskWarriorTaskSerializer.java

License:Open Source License

public static void handleRecurrence(final JsonObject json, final Recurring r) {
    if (r == null) {
        Log.wtf(TAG, "recurring is null");
        return;//from w  w w  . j  a v  a2s.  c o m
    }
    if (!r.getWeekdays().isEmpty()) {
        switch (r.getWeekdays().size()) {
        case 1:
            json.addProperty("recur", "weekly");
            return;
        case 7:
            json.addProperty("recur", "daily");
            return;
        case 5:
            final List<Integer> weekdays = r.getWeekdays();
            for (Integer i = DateTimeConstants.MONDAY; i <= DateTimeConstants.FRIDAY; i++) {
                if (!weekdays.contains(i)) {
                    Log.w(TAG, "unsupported recurrence");
                    return;
                }
            }
            json.addProperty("recur", "weekdays");
            return;
        default:
            Log.w(TAG, "unsupported recurrence");
            return;
        }
    }
    final long interval = r.getIntervalMs() / (1000L * 60L);
    if (interval > 0L) {
        Period p = r.getInterval();
        if (r.getInterval().getMinutes() > 0) {
            json.addProperty("recur", p.toStandardMinutes().getMinutes() + "mins");
        } else if (r.getInterval().getHours() > 0) {
            json.addProperty("recur", p.toStandardHours().getHours() + "hours");
        } else if (r.getInterval().getDays() > 0) {
            json.addProperty("recur", p.toStandardDays().getDays() + "days");
        } else if (r.getInterval().getWeeks() > 0) {
            json.addProperty("recur", p.toStandardWeeks().getWeeks() + "weeks");
        } else if (r.getInterval().getMonths() > 0) {
            json.addProperty("recur", p.getMonths() + (12 * p.getYears()) + "months");
        } else {
            json.addProperty("recur", p.getYears() + "years");
        }
    }
}

From source file:org.kalypso.ui.rrm.internal.timeseries.view.evaporation.ChooseEvaporationInputFilesPage.java

License:Open Source License

private TimeseriesBean[] findInputFiles(final IFeatureBindingCollection<ITimeseries> collection,
        final String type) {
    final Set<TimeseriesBean> found = new LinkedHashSet<>();

    for (final ITimeseries timeseries : collection) {
        if (StringUtils.equals(timeseries.getParameterType(), type)) {
            // only tageswerte are supported
            final Period timestep = timeseries.getTimestep();
            final int days = timestep.toStandardDays().getDays();
            if (days == 1)
                found.add(new TimeseriesBean(timeseries));
        }// w  w  w .  jav  a2  s. co  m

    }

    return found.toArray(new TimeseriesBean[] {});
}

From source file:org.projectbuendia.client.utils.RelativeDateTimeFormatter.java

License:Apache License

/** Formats a representation of {@code date} relative to {@code anchor}. */
public String format(LocalDate date, LocalDate anchor) {
    if (date.isAfter(anchor)) {
        return "in the future"; // TODO/i18n
    }//from  w  w  w  .j a v  a 2 s .  c  o m
    Period period = new Period(date, anchor);
    int daysAgo = period.toStandardDays().getDays();
    return daysAgo > 1 ? daysAgo + " days ago" : // TODO/i18n
            daysAgo == 1 ? "yesterday" : "today"; // TODO/i18n
}

From source file:org.projectbuendia.client.utils.RelativeDateTimeFormatter.java

License:Apache License

/** Formats a representation of {@code dateTime} relative to {@code anchor}. */
public String format(DateTime dateTime, DateTime anchor) {
    if (dateTime.isAfter(anchor)) {
        return "in the future"; // TODO/i18n
    }//www . ja v a2 s .  c  o m
    Period period = new Period(dateTime, anchor);
    int daysAgo = period.toStandardDays().getDays();
    int hoursAgo = period.toStandardHours().getHours();
    int minutesAgo = period.toStandardMinutes().getMinutes();

    return daysAgo > 1 ? daysAgo + " days ago" : // TODO/i18n
            hoursAgo > 1 ? hoursAgo + " hours ago" : // TODO/i18n
                    minutesAgo > 1 ? minutesAgo + " min ago" : // TODO/i18n
                            "right now"; // TODO/i18n
}