florent37 / SingleDateAndTimePicker

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

I am unable to select 29 Feb 2020 #244

Closed mxdldev closed 4 years ago

mxdldev commented 4 years ago

I chose February 29, 2020 and returned March 1, 2020

zsoltlengyelit commented 4 years ago

hi @mxdldev: the same problem here. Did you find some solution? Thanks in advance

dimabran commented 4 years ago

I'm having the same issue any solution?

zsoltlengyelit commented 4 years ago

I found a workaround solution: if you use a dateFormat that has year in it, then SimpleDateFormat won't use 1970 as default year. 1970 was not a leap year.

The problem occurs at this line: https://github.com/florent37/SingleDateAndTimePicker/blob/master/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/widget/WheelDayPicker.java#L132

itemText == "Sat 29 Feb"
date = getDateFormat().parse(itemText);
date.toString() == "Sun Mar 01 00:00:00 GMT+01:00 1970"
zsoltlengyelit commented 4 years ago

PR is opened.

https://github.com/florent37/SingleDateAndTimePicker/pull/250

gowrishg commented 4 years ago

Thanks for the PR, for some reason the app kept crashing when we set the default date. Instead, I just applied this crappy logic below to fix the problem for now (at least it fixes for next 4years).

                if(itemText.equals("Sat 29 Feb")) {
                    Calendar leapCal = Calendar.getInstance();
                    leapCal.set(Calendar.YEAR, 2020);
                    leapCal.set(Calendar.MONTH, 1);
                    leapCal.set(Calendar.DAY_OF_MONTH, 29);
                    leapCal.set(Calendar.HOUR_OF_DAY, 0);
                    leapCal.set(Calendar.MINUTE, 0);
                    leapCal.set(Calendar.SECOND, 0);
                    leapCal.set(Calendar.MILLISECOND, 0);
                    date = leapCal.getTime();
                } else {
                    date = simpleDateFormat.parse(itemText);
                }
Tgo1014 commented 4 years ago

I'm having the same issue, selecting Feb, 29 makes it return March, 1st.

florent37 commented 4 years ago

should be fixed, can you try ?