MBCalendarKit icon indicating copy to clipboard operation
MBCalendarKit copied to clipboard

Selecting last day of the week jumps to next week when firstDayOfWeek set to Monday

Open glentregoning opened this issue 9 years ago • 7 comments

Steps to reproduce:

  1. Configure [CKCalendarView firstWeekDay] to be Monday (2)
  2. Run Demo app, change to Week view
  3. Select the last day of the current week (Sunday)

Observed: The week shown jumps forward by 1 week. Expected: The day should be selected, but the week shown should remain the same.

glentregoning avatar May 02 '15 22:05 glentregoning

Thanks for the succinct bug report.

Do you think this has to do with the firstWeekday fix you submitted last week? I think so, but I have to look at the code to see where the fix is.

I don't remember offhand, but there are probably some utility methods to determine what range of dates is being shown and then to determine if the selected day is in the visible range. Mostly, this has to do with the month view, because you can select dates in other months where weeks overlap two months.

Again, not sure, but that's where I'd start.

MosheBerman avatar May 03 '15 06:05 MosheBerman

I don' think it had to do with my change, but I haven't confirmed that.

I think the issue resides in

-(NSDate *) [NSCalendar+Juncture firstDayOfTheWeekUsingReferenceDate:(NSDate *)date andStartDay:(NSInteger)day]

We've had some luck by making the following change, but I'm not sure this is the right answer for the generalized solution (for weeks starting on anything other than Monday).

- (NSDate *)firstDayOfTheWeekUsingReferenceDate:(NSDate *)date andStartDay:(NSInteger)day
{
    // Make the calendar calculate Sunday correctly now that the week starts on Monday
    NSInteger dayOfWeek = [self weekdayInDate:date];
    if (dayOfWeek == 1) {
        dayOfWeek = 8;
    }
    NSInteger weekday = dayOfWeek-day;
    return [self dateBySubtractingDays:weekday fromDate:date];
}

glentregoning avatar May 03 '15 18:05 glentregoning

Has this solution been working out for you?

MosheBerman avatar Nov 04 '15 16:11 MosheBerman

Actually sorry to say I've switched to using another Calendar library (as I wanted something a little more decoupled).

glentregoning avatar Nov 04 '15 21:11 glentregoning

That's disappointing, but I totally understand.

Which library are you using?

MosheBerman avatar Nov 05 '15 02:11 MosheBerman

This is the project I'm currently using. https://github.com/jonathantribouharet/JTCalendar/

glentregoning avatar Nov 05 '15 04:11 glentregoning

Cool. MBCalendarKit 5 moves towards that decoupling a bit with a lot of re-architecting. Most significantly, the calendar view no longer automatically installs the table view. Now, that behavior is only provided by CKCalendarViewController.

Since I doubt there's any point to keeping it open, do you mind if we close this?

MosheBerman avatar Aug 17 '17 22:08 MosheBerman