Example usage for org.joda.time LocalDateTime withDayOfYear

List of usage examples for org.joda.time LocalDateTime withDayOfYear

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime withDayOfYear.

Prototype

public LocalDateTime withDayOfYear(int dayOfYear) 

Source Link

Document

Returns a copy of this datetime with the day of year field updated.

Usage

From source file:org.gnucash.android.ui.report.BarChartFragment.java

License:Apache License

/**
 * Calculates difference between two date values accordingly to {@code mGroupInterval}
 * @param start start date//  w  w  w  .  j a  v a  2  s  .  c om
 * @param end end date
 * @return difference between two dates or {@code -1}
 */
private int getDateDiff(LocalDateTime start, LocalDateTime end) {
    switch (mGroupInterval) {
    case QUARTER:
        int y = Years.yearsBetween(start.withDayOfYear(1).withMillisOfDay(0),
                end.withDayOfYear(1).withMillisOfDay(0)).getYears();
        return (getQuarter(end) - getQuarter(start) + y * 4);
    case MONTH:
        return Months.monthsBetween(start.withDayOfMonth(1).withMillisOfDay(0),
                end.withDayOfMonth(1).withMillisOfDay(0)).getMonths();
    case YEAR:
        return Years.yearsBetween(start.withDayOfYear(1).withMillisOfDay(0),
                end.withDayOfYear(1).withMillisOfDay(0)).getYears();
    default:
        return -1;
    }
}

From source file:org.gnucash.android.ui.report.BaseReportFragment.java

License:Apache License

/**
 * Calculates difference between two date values accordingly to {@code mGroupInterval}
 * @param start start date/*from   w  w  w.j a v a 2  s  .  c o  m*/
 * @param end end date
 * @return difference between two dates or {@code -1}
 */
protected int getDateDiff(LocalDateTime start, LocalDateTime end) {
    switch (mGroupInterval) {
    case QUARTER:
        int y = Years.yearsBetween(start.withDayOfYear(1).withMillisOfDay(0),
                end.withDayOfYear(1).withMillisOfDay(0)).getYears();
        return getQuarter(end) - getQuarter(start) + y * 4;
    case MONTH:
        return Months.monthsBetween(start.withDayOfMonth(1).withMillisOfDay(0),
                end.withDayOfMonth(1).withMillisOfDay(0)).getMonths();
    case YEAR:
        return Years.yearsBetween(start.withDayOfYear(1).withMillisOfDay(0),
                end.withDayOfYear(1).withMillisOfDay(0)).getYears();
    default:
        return -1;
    }
}