blazsolar / WeekDatePicker

Lightweight week date picker implmentation for Android.
MIT License
64 stars 17 forks source link

not expected result on selectDay(LocalDate date) #19

Open haoziliu opened 7 years ago

haoziliu commented 7 years ago
    private int getDayForDate(@NonNull LocalDate date) {
        return firstDay.until(date).getDays();
    }

This method is supposed to get the offset of days from first day. But in fact it only get the days of month. As a result, selectDay and setDateIndicator won't work correctly.

This would be correct:

    private int getDayForDate(@NonNull LocalDate date) {
        return (int) (date.toEpochDay() - firstDay.toEpochDay());
    }

or

    private int getDayForDate(@NonNull LocalDate date) {
        return (int) firstDay.until(date, ChronoUnit.DAYS);
    }