Example usage for org.joda.time Period getDays

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

Introduction

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

Prototype

public int getDays() 

Source Link

Document

Gets the days field part of the period.

Usage

From source file:com.gst.portfolio.loanaccount.loanschedule.domain.LoanApplicationTerms.java

License:Apache License

private Integer getPeriodsBetween(LocalDate fromDate, LocalDate toDate) {
    Integer numberOfPeriods = 0;//from  w w  w .  j  ava  2 s  .  c om
    PeriodType periodType = PeriodType.yearMonthDay();
    Period difference = new Period(fromDate, toDate, periodType);
    switch (this.repaymentPeriodFrequencyType) {
    case DAYS:
        numberOfPeriods = difference.getDays();
        break;
    case WEEKS:
        periodType = PeriodType.weeks();
        difference = new Period(fromDate, toDate, periodType);
        numberOfPeriods = difference.getWeeks();
        break;
    case MONTHS:
        numberOfPeriods = difference.getMonths();
        break;
    case YEARS:
        numberOfPeriods = difference.getYears();
        break;
    default:
        break;
    }
    return numberOfPeriods;
}

From source file:com.hendi.cekusia.Joda.java

public static void main(String[] args) {
    LocalDate birthdate = new LocalDate(1986, 9, 19); //Birth date
    LocalDate now = new LocalDate(); //Today's date
    Period period = new Period(birthdate, now, PeriodType.yearMonthDay());
    //Now access the values as below
    System.out.println("Using Joda Time");
    System.out.println("Usia : " + period.getYears() + " Tahun " + period.getMonths() + " Bulan "
            + period.getDays() + " Hari ");
    System.out.println();/*from www . j av  a2  s .  c  o m*/

}

From source file:com.huang.rp.common.utils.TimeUtils.java

License:Apache License

/**
 * ? /*from w w  w. ja v a 2 s .co m*/
 * @param dt1
 * @param dt2
 * @return
 */
public static int getDateDiff(DateTime dt1, DateTime dt2) {
    Period p = new Period(dt1, dt2, PeriodType.days());
    return p.getDays();
}

From source file:com.jajja.jorm.mixins.Postgres.java

License:Open Source License

public static PGInterval toInterval(Period period) {
    if (period == null) {
        return null;
    }/*from  w  w w.jav  a  2s  . c o  m*/
    return new PGInterval(period.getYears(), period.getMonths(), period.getDays(), period.getHours(),
            period.getMinutes(), period.getSeconds() + (double) period.getMillis() / 1000);
}

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

License:Apache License

/**
 * Adds adjustment to the shortest set time range in period. E.g.
 *  period("5 days 3 hours", 1) -> "5 days 4 hours". This will fall
 *  back to adjusting years if no field in the period is set.
 * @param period The period to be adjusted
 * @param adjustment The adjustment. Note that positive values will result
 *                   in larger periods and an earlier time
 * @return The adjusted period/*from w  ww .ja v  a 2  s .  c o m*/
 */
private Period adjust(final Period period, int adjustment) {
    if (adjustment == 0)
        return period;

    // Order is VERY important here
    LinkedHashMap<Integer, DurationFieldType> map = new LinkedHashMap<>();
    map.put(period.getSeconds(), DurationFieldType.seconds());
    map.put(period.getMinutes(), DurationFieldType.minutes());
    map.put(period.getHours(), DurationFieldType.hours());
    map.put(period.getDays(), DurationFieldType.days());
    map.put(period.getWeeks(), DurationFieldType.weeks());
    map.put(period.getMonths(), DurationFieldType.months());
    map.put(period.getYears(), DurationFieldType.years());

    for (Map.Entry<Integer, DurationFieldType> entry : map.entrySet()) {
        if (entry.getKey() > 0) {
            return period.withFieldAdded(entry.getValue(), adjustment);
        }
    }
    // Fall back to modifying years
    return period.withFieldAdded(DurationFieldType.years(), adjustment);
}

From source file:com.microsoft.azure.management.servicebus.implementation.TimeSpan.java

License:Open Source License

/**
 * Gets TimeSpan from given period.//from w ww.j a va 2s  .  c o  m
 *
 * @param period duration in period format
 * @return TimeSpan
 */
public static TimeSpan fromPeriod(Period period) {
    // Normalize (e.g. move weeks to hour part)
    //
    Period p = new Period(period.toStandardDuration().getMillis());
    return TimeSpan
            .parse((new TimeSpan().withDays(p.getDays()).withHours(p.getHours()).withMinutes(p.getMinutes())
                    .withSeconds(p.getSeconds()).withMilliseconds(p.getMillis())).toString());
}

From source file:com.microsoft.exchange.DateHelp.java

License:Apache License

public static List<Interval> generateIntervals(org.joda.time.DateTime start, org.joda.time.DateTime end,
        Period period) {
    if (period.getDays() > MAX_PERIOD.getDays()) {
        period = MAX_PERIOD;/*from ww w .ja  v  a2 s. c o m*/
    }
    List<Interval> list = new ArrayList<Interval>();
    org.joda.time.DateTime intervalEnd = start.plus(period);
    while (intervalEnd.isBefore(end)) {
        list.add(new Interval(start, intervalEnd));
        start = intervalEnd;
        intervalEnd = intervalEnd.plus(period);
    }
    if (start.isBefore(end)) {
        list.add(new Interval(start, end));
    }
    return list;
}

From source file:com.microsoft.exchange.ExchangeDateUtils.java

License:Apache License

/**
 * Construct a {@link List} of {@link Interval}s where each interval abuts and has a duration equal to that of {@code period}
 * @param start/*from  ww w . j a va 2 s.c om*/
 * @param end
 * @param period
 * @return
 */
public static List<Interval> generateIntervals(org.joda.time.DateTime start, org.joda.time.DateTime end,
        Period period) {
    if (period.getDays() > MAX_PERIOD.getDays()) {
        period = MAX_PERIOD;
    }
    List<Interval> list = new ArrayList<Interval>();
    org.joda.time.DateTime intervalEnd = start.plus(period);
    while (intervalEnd.isBefore(end)) {
        list.add(new Interval(start, intervalEnd));
        start = intervalEnd;
        intervalEnd = intervalEnd.plus(period);
    }
    if (start.isBefore(end)) {
        list.add(new Interval(start, end));
    }
    return list;
}

From source file:com.mobileman.kuravis.core.util.DateTimeUtils.java

License:Apache License

/**
 * @param date//from w ww .  j a  v  a 2  s . c  o  m
 * @return formatted elapsed time from now
 */
public static String fmtElapsedTime(Date date) {
    if (date == null) {
        return "";
    }
    Period period = new Period(date.getTime(), Calendar.getInstance().getTimeInMillis());
    PeriodFormatterBuilder pf = new PeriodFormatterBuilder();
    pf.appendPrefix(" vor ");
    if (period.getYears() > 0) {
        pf.appendYears().appendSuffix(" Jahr", " Jahren");
    } else if (period.getMonths() > 0) {
        pf.appendMonths().appendSuffix(" Monat", " Monaten");
    } else if (period.getWeeks() > 0) {
        pf.appendWeeks().appendSuffix(" Woche ", " Wochen");
    } else if (period.getDays() > 0) {
        pf.appendDays().appendSuffix(" Tag ", " Tagen");
    } else if (period.getHours() > 0) {
        pf.appendHours().appendSuffix(" Stunde ", " Stunden");
    } else if (period.getMinutes() > 0) {
        pf.appendMinutes().appendSuffix(" Minute ", " Minuten");
    } else if (period.getSeconds() > 0) {
        pf.appendSeconds().appendSuffix(" Sekunde ", " Sekunden");
    }
    return pf.toFormatter().print(period);
}

From source file:com.moss.jodapersist.SplitHoursMinutesDurationUserType.java

License:Open Source License

public void nullSafeSet(PreparedStatement statement, Object value, int index)
        throws HibernateException, SQLException {
    Period period = (Period) value;

    statement.setInt(index, period.getHours());
    statement.setInt(index + 1, period.getDays());
}