Android Open Source - DisposableIncome-OldJava Withdraw Date Comparer






From Project

Back to project page DisposableIncome-OldJava.

License

The source code is released under:

MIT License

If you think the Android project DisposableIncome-OldJava listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package uk.co.wilka.disposableincome;
/* ww w  . j  a va  2s  .c o m*/
import java.util.Calendar;
import java.util.Date;

public class WithdrawDateComparer {
    private final IProvideCalendar calendarProvider;

    public WithdrawDateComparer(IProvideCalendar calendarProvider) {
        this.calendarProvider = calendarProvider;
    }

    public boolean isBeforeThisMonth(CashWithdraw withdraw) {
        Date now = calendarProvider.getCalendar().getTime();

        if(withdraw.getDate().getYear() < now.getYear())
            return true;

        if(withdraw.getDate().getYear() > now.getYear())
            return false;

        return withdraw.getDate().getMonth() < now.getMonth();
    }

    public boolean isAfterThisMonth(CashWithdraw withdraw) {
        Date now = calendarProvider.getCalendar().getTime();

        if(withdraw.getDate().getYear() < now.getYear())
            return false;

        if(withdraw.getDate().getYear() > now.getYear())
            return true;

        return withdraw.getDate().getMonth() > now.getMonth();
    }

    public boolean isInThePast(CashWithdraw withdraw) {
        return withdraw.getDate().before(Calendar.getInstance().getTime());
    }

    public boolean isThisMonth(CashWithdraw withdraw) {
        Date now = calendarProvider.getCalendar().getTime();
        return  withdraw.getDate().getYear() == now.getYear() &&
                withdraw.getDate().getMonth() == now.getMonth();
    }

    // TODO: Add unit tests for this
    public int getDaysUntilMonthEnd() {
        Calendar calendar = calendarProvider.getCalendar();
        int daysUntilMonthEnd = calendar.getActualMaximum(Calendar.DAY_OF_MONTH) - calendar.get(Calendar.DAY_OF_MONTH);
        if(daysUntilMonthEnd == 0) {
            daysUntilMonthEnd = 1;
        }

        return daysUntilMonthEnd;
    }
}




Java Source Code List

uk.co.wilka.disposableincome.CalendarAccess.java
uk.co.wilka.disposableincome.CalendarProvider.java
uk.co.wilka.disposableincome.CashWithdraw.java
uk.co.wilka.disposableincome.CashWithdrawalDetailsActivity.java
uk.co.wilka.disposableincome.Cash.java
uk.co.wilka.disposableincome.DatabaseHelper.java
uk.co.wilka.disposableincome.IAccessData.java
uk.co.wilka.disposableincome.IProvideCalendar.java
uk.co.wilka.disposableincome.MainActivity.java
uk.co.wilka.disposableincome.PlusOneMonthCalendarProvider.java
uk.co.wilka.disposableincome.WithdrawDateComparer.java
uk.co.wilka.disposableincome.WithdrawType.java
uk.co.wilka.disposableincome.WithdrawalForMonthCalculator.java
uk.co.wilka.disposableincome.test.CashTest.java
uk.co.wilka.disposableincome.test.CashWithdrawTest.java
uk.co.wilka.disposableincome.test.FakeCalendarProvider.java
uk.co.wilka.disposableincome.test.PlusOneMonthCalendarProviderTests.java
uk.co.wilka.disposableincome.test.WithdrawDateComparerTests.java
uk.co.wilka.disposableincome.test.WithdrawalForMonthCalculatorTests.java