Skip to content

Commit

Permalink
Shift back to previous week
Browse files Browse the repository at this point in the history
  • Loading branch information
Thuy Trinh authored Feb 28, 2017
2 parents c041ca1 + 9cede16 commit 1785944
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/com/skedgo/android/weekpicker/WeekFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ protected static ArrayList<Date> getDateRangeWithWeekStart(Calendar selectedDate
ArrayList<Date> dateRange = new ArrayList<Date>();
Calendar calendar = (Calendar) selectedDate.clone();
calendar.set(Calendar.DAY_OF_WEEK, convertJodaTimeToCalendar(weekStart));

// For example, selected date is Monday and the week start is next Tuesday.
// If we don't shift back to previous week, the picker will show the week
// starting from next Tuesday. That will hide the selected date.
// We expect the picker to show the selected date, that's why we need
// to shift back.
if (calendar.after(selectedDate)) {
// Shift back to previous week.
calendar.add(Calendar.DATE, -7);
}

for (int i = 0; i < Calendar.DAY_OF_WEEK; i++) {
Date date = calendar.getTime();
dateRange.add(date);
Expand Down Expand Up @@ -271,4 +282,4 @@ public static boolean isSameDay(Calendar cal1, Calendar cal2) {
cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
}
}
}
}

0 comments on commit 1785944

Please sign in to comment.