public void setLastDate(int endYear, int endMonth) {
        if (endYear < startYear || (endYear == startYear && endMonth < startMonth)) {
            throw new IllegalArgumentException("Last visible date cannot be before first visible date");
        }

        Calendar firstDate = Calendar.getInstance();
        firstDate.set(startYear, startMonth, 1);
        Calendar lastDate = Calendar.getInstance();
        lastDate.set(endYear, endMonth, 1);
        int diffYear = lastDate.get(Calendar.YEAR) - firstDate.get(Calendar.YEAR);
        int diffMonth = diffYear * 12 + lastDate.get(Calendar.MONTH) - firstDate.get(Calendar.MONTH);

        setMonthCount(diffMonth + 1);
    }
Color when month is before the current selected month
library/src/main/java/com/github/badoualy/datepicker/MonthView.java