Say I want to create a date at "3:00 pm Friday".
I know today is Monday (day = 1). Friday is day 6. I know the hour I want to create is 15.
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setDay:6];
[comps setMonth:currentDate.month];
[comps setYear:currentDate.year];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *date = [gregorian dateFromComponents:comps];
This might work in some cases I guess. But not if Friday is in a different month or year than today. Is there a robust solution to this, or do I have to manually account for the edge cases I mentioned?
EDIT: I don't know the day of the month or the year of the proposed date. I know today's date. I only know the day of the proposed date, and that it's the next date with that day from now. So, the next upcoming Friday from now, at 3:00 pm.