Open bassil-altamimi opened 3 years ago
This issue is because the UmmalquraCalendar can't specify the max year. you can fix the problem by setting the max date to the current date using the following code if you user kotlin language
val dialog = HijriDatePickerDialog.newInstance( this, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH) ) dialog.maxDate = UmmalquraCalendar( now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH) )
If you use koltin this method will fix your issue
fun selectDateOfBirthHijri(context: Context, editText: EditText, childFragmentManager: FragmentManager) {
val now = Calendar.getInstance()
val dateOfBirthClickListener =
HijriDatePickerDialog.OnDateSetListener { view, year, month, dayOfMonth ->
now.set(Calendar.YEAR, year)
now.set(Calendar.MONTH, month)
now.set(Calendar.DAY_OF_MONTH, dayOfMonth)
editText.setText(
Formatter.format(
now.time.toString(),
Formatter.EEE_MMM_DD_HH_MM_SS_ZZZ_YYYY,
Formatter.DD_MM_YYYY
)
)
}
val ummAlquraCalendar = UmmalquraCalendar()
val b = HijriDatePickerDialog.newInstance(
dateOfBirthClickListener,
ummAlquraCalendar.get(UmmalquraCalendar.YEAR),
ummAlquraCalendar.get(UmmalquraCalendar.MONTH),
ummAlquraCalendar.get(UmmalquraCalendar.DAY_OF_MONTH)
)
b.maxDate = UmmalquraCalendar(ummAlquraCalendar.get(Calendar.YEAR),
ummAlquraCalendar.get(Calendar.MONTH),
ummAlquraCalendar.get(Calendar.DAY_OF_MONTH))
b.setTitle(context.getString(R.string.hint_date_of_birth))
b.show(childFragmentManager, "HijriDatePickerDialog")
}
com.github.msarhan.ummalqura.calendar.DateTimeException: Invalid Hijrah day of month: 31 at com.github.msarhan.ummalqura.calendar.HijrahChronology.getEpochDay(HijrahChronology.java:255) at com.github.msarhan.ummalqura.calendar.HijrahChronology.toGregorian(HijrahChronology.java:697) at com.github.msarhan.ummalqura.calendar.UmmalquraCalendar.set(UmmalquraCalendar.java:259) at net.alhazmy13.hijridatepicker.date.hijri.HijriDatePickerDialog.getEndDate(HijriDatePickerDialog.java:1030) at net.alhazmy13.hijridatepicker.date.hijri.MonthAdapter.getCount(MonthAdapter.java:147) at android.widget.ListView.setAdapter(ListView.java:581) at net.alhazmy13.hijridatepicker.date.hijri.DayPickerView.refreshAdapter(DayPickerView.java:142) at net.alhazmy13.hijridatepicker.date.hijri.DayPickerView.setController(DayPickerView.java:114) at net.alhazmy13.hijridatepicker.date.hijri.DayPickerView.(DayPickerView.java:105) at net.alhazmy13.hijridatepicker.date.hijri.SimpleDayPickerView.(SimpleDayPickerView.java:32) at net.alhazmy13.hijridatepicker.date.hijri.HijriDatePickerDialog.onCreateView(HijriDatePickerDialog.java:345) at android.app.Fragment.performCreateView(Fragment.java:2505) at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1303) at android.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2431) at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2210) at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2166) at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2067) at android.app.FragmentManagerImpl$1.run(FragmentManager.java:742) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7664) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
If you use koltin this method will fix your issue
fun selectDateOfBirthHijri(context: Context, editText: EditText, childFragmentManager: FragmentManager) { val now = Calendar.getInstance() val dateOfBirthClickListener = HijriDatePickerDialog.OnDateSetListener { view, year, month, dayOfMonth -> now.set(Calendar.YEAR, year) now.set(Calendar.MONTH, month) now.set(Calendar.DAY_OF_MONTH, dayOfMonth) editText.setText( Formatter.format( now.time.toString(), Formatter.EEE_MMM_DD_HH_MM_SS_ZZZ_YYYY, Formatter.DD_MM_YYYY ) ) } val ummAlquraCalendar = UmmalquraCalendar() val b = HijriDatePickerDialog.newInstance( dateOfBirthClickListener, ummAlquraCalendar.get(UmmalquraCalendar.YEAR), ummAlquraCalendar.get(UmmalquraCalendar.MONTH), ummAlquraCalendar.get(UmmalquraCalendar.DAY_OF_MONTH) ) b.maxDate = UmmalquraCalendar(ummAlquraCalendar.get(Calendar.YEAR), ummAlquraCalendar.get(Calendar.MONTH), ummAlquraCalendar.get(Calendar.DAY_OF_MONTH)) b.setTitle(context.getString(R.string.hint_date_of_birth)) b.show(childFragmentManager, "HijriDatePickerDialog") }
com.github.msarhan.ummalqura.calendar.DateTimeException: Invalid Hijrah day of month: 31 at com.github.msarhan.ummalqura.calendar.HijrahChronology.getEpochDay(HijrahChronology.java:255) at com.github.msarhan.ummalqura.calendar.HijrahChronology.toGregorian(HijrahChronology.java:697) at com.github.msarhan.ummalqura.calendar.UmmalquraCalendar.set(UmmalquraCalendar.java:259) at net.alhazmy13.hijridatepicker.date.hijri.HijriDatePickerDialog.getEndDate(HijriDatePickerDialog.java:1030) at net.alhazmy13.hijridatepicker.date.hijri.MonthAdapter.getCount(MonthAdapter.java:147) at android.widget.ListView.setAdapter(ListView.java:581) at net.alhazmy13.hijridatepicker.date.hijri.DayPickerView.refreshAdapter(DayPickerView.java:142) at net.alhazmy13.hijridatepicker.date.hijri.DayPickerView.setController(DayPickerView.java:114) at net.alhazmy13.hijridatepicker.date.hijri.DayPickerView.(DayPickerView.java:105)
at net.alhazmy13.hijridatepicker.date.hijri.SimpleDayPickerView.(SimpleDayPickerView.java:32)
at net.alhazmy13.hijridatepicker.date.hijri.HijriDatePickerDialog.onCreateView(HijriDatePickerDialog.java:345)
at android.app.Fragment.performCreateView(Fragment.java:2505)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1303)
at android.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2431)
at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2210)
at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2166)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2067)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:742)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7664)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)