florent37 / SingleDateAndTimePicker

You can now select a date and a time with only one widget !
Apache License 2.0
1.02k stars 334 forks source link

Can't show dates older than 1998/newer than 2038 #160

Open Moonbloom opened 6 years ago

Moonbloom commented 6 years ago

No matter what combination of settings i use, the year picker will NEVER go below 1998 or above 2038.

I'm guessing this is because of the constants in 'SingleDateAndTimeConstants.java':

public static final int MIN_YEAR_DIFF = 20;
public static final int MAX_YEAR_DIFF = 20;

I've tried settings max/min/default date, and i also tried to use the Dialog builder, which has the same issue.

My XML:

<com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker
        android:id="@+id/date_time_picker"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"/>

My Java code:

private void setupPicker() {
        Calendar minDate = Calendar.getInstance();
        minDate.set(Calendar.MONTH, Calendar.JANUARY);
        minDate.set(Calendar.DAY_OF_MONTH, 1);
        minDate.set(Calendar.YEAR, 1900);
        singleDateAndTimePicker.setMinDate(minDate.getTime());

        Calendar now = Calendar.getInstance();
        singleDateAndTimePicker.setMaxDate(now.getTime());
        //singleDateAndTimePicker.setDefaultDate(minDate.getTime());

        singleDateAndTimePicker.setCyclic(false);
        singleDateAndTimePicker.setCurved(true);
        singleDateAndTimePicker.setMustBeOnFuture(false);

        singleDateAndTimePicker.setIsAmPm(false);
        singleDateAndTimePicker.setDisplayHours(false);
        singleDateAndTimePicker.setDisplayMinutes(false);
        singleDateAndTimePicker.setDisplayMonthNumbers(false);
        singleDateAndTimePicker.setDisplayYears(true);

        singleDateAndTimePicker.setDisplayDays(false);
        singleDateAndTimePicker.setDisplayMonths(true);
        singleDateAndTimePicker.setDisplayDaysOfMonth(true);

        singleDateAndTimePicker.addOnDateChangedListener((displayed, date) -> {

        });
    }

I can debug it internally and see that minYears is actually set to 1900, but the UI does not reflect this.

AndreiMorar commented 6 years ago

Oh, come on !!! How can you not make the MIN_YEAR_DIFF non final or something ... !!! I need it to reflect a birthday...so basically i need to limit my audience to the teens ... :))

hitesh-dhamshaniya commented 6 years ago

It should set from out side as well, I am stuck to select birth day of user who is 30-35 years old. :(