0

It's clear how can I calculate the time between two exact date, but I would like to know the date between the actual date and the next monday 2:00 PM.

As an instance, users can reserve places for yoga classes, there is a class that starts on every monday 2:00 PM. So how can I calculate the date of next monday compared to [NSDate date]? I would like to display the remaining time until the next class.

 // Date of the next class - how can i get this date?
// NSDate *nextCourse = [NSDate ??];

  NSCalendar *deviceCalendar = [NSCalendar autoupdatingCurrentCalendar];

  NSDate *date2 = [[NSDate alloc] initWithTimeInterval:nextCourse sinceDate:date1];

  unsigned int unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;

  NSDateComponents *conversionInfo = [deviceCalendar components:unitFlags fromDate:date1  toDate:date2  options:0];
rihekopo
  • 3,241
  • 4
  • 34
  • 63
  • 1
    Your prose says your problem is finding the difference, but your code says your problem is getting the `NSDate` representing "next Monday at 2PM". Please be more clear about which it is. Also, how is the information about "Monday at 2" stored? – jscs Dec 18 '14 at 23:34
  • I've pointed this to a solution based on the problem in the code. If that's not your actual problem, edit your question, leave me a comment, and I will reopen this. – jscs Dec 18 '14 at 23:44

1 Answers1

1

I can recommend a third party library called DateTools, https://github.com/MatthewYork/DateTools.

Specifically, you can use the: daysUntil:, hoursUntil:, minutesUntil: methods.

For example:

double hoursUntilClass = [date2 hoursUntil];
ddevaz
  • 2,253
  • 1
  • 17
  • 10