Skip to content

Commit

Permalink
proper handling of custom date range selections - fixes #611 (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
HeinrichLohse authored and codinguser committed Jan 23, 2017
1 parent daaf416 commit a003d51
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class DateRangePickerDialogFragment extends DialogFragment{
private Date mStartRange = LocalDate.now().minusMonths(1).toDate();
private Date mEndRange = LocalDate.now().toDate();
private OnDateRangeSetListener mDateRangeSetListener;
private static final long ONE_DAY_IN_MILLIS = 24 * 60 * 60 * 1000;

public static DateRangePickerDialogFragment newInstance(OnDateRangeSetListener dateRangeSetListener){
DateRangePickerDialogFragment fragment = new DateRangePickerDialogFragment();
Expand Down Expand Up @@ -89,7 +90,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
public void onClick(View v) {
List<Date> selectedDates = mCalendarPickerView.getSelectedDates();
Date startDate = selectedDates.get(0);
Date endDate = selectedDates.size() == 2 ? selectedDates.get(1) : new Date();
// If only one day is selected (no interval) start and end should be the same (the selected one)
Date endDate = selectedDates.size() > 1 ? selectedDates.get(selectedDates.size() - 1) : new Date(startDate.getTime());
// CaledarPicker returns the start of the selected day but we want all transactions of that day to be included.
// Therefore we have to add 24 hours to the endDate.
endDate.setTime(endDate.getTime() + ONE_DAY_IN_MILLIS);
mDateRangeSetListener.onDateRangeSet(startDate, endDate);
dismiss();
}
Expand Down

0 comments on commit a003d51

Please sign in to comment.