Easiest way to get an NSDate representation of "the next 7am that will occur" in Cocoa?

Posted by Drarok on Stack Overflow See other posts from Stack Overflow or by Drarok
Published on 2010-05-27T01:18:13Z Indexed on 2010/05/27 1:21 UTC
Read the original article Hit count: 252

Filed under:
|
|
|

I figure I can achieve what I want by using NSCalendar and NSDateComponents, but that would run something like the following:

  • Get "now"
  • Create an NSDateComponents from "now".
  • If "now" is pre-7am, then use today's date.
  • If "now" is post-7am, use tomorrow's date.
    • If today is the last day of the month, increase month, set day to 1.
      • If it was December, increase year by 1 also.
  • Set hour, minute, second.
  • Create a new NSDate.

It all seems very long-winded, but that appears to be what other answers on here suggest, and the documentation doesn't offer any clues. I'm going back and forth between all the date and calendar classes I can find.

Is there a simple way to ask for the "next occurring 7am" ?

Thanks.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa