Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7695887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:39:05+00:00 2026-05-31T21:39:05+00:00

UPDATE: This is the working example. First we create a class to hold weekday,

  • 0

UPDATE: This is the working example.

First we create a class to hold weekday, hr, min, and sec:

myClass.h

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface myClass : NSObject {
NSString *weekday;
NSInteger hour;
NSInteger minute;
NSInteger second;
}

@property (nonatomic, strong) NSString *weekday;
@property (nonatomic, assign) NSInteger hour;
@property (nonatomic, assign) NSInteger minute;
@property (nonatomic, assign) NSInteger second;

@end

myClass.m

#import "myClass.h"

@implementation myClass
@synthesize weekday, hour, minute, second;

@end

Next, we need to create an instance of myClass that holds our date info.

Add this to ViewController.h:

@property (nonatomic, strong) NSMutableArray *myArray;

This code goes in ViewController.m wherever you’d like:

myArray = [[NSMutableArray alloc] init];

//Setup an instance of myClass 
myClass *c = [[myClass alloc] init];
[c setWeekday:@"Monday"];
[c setHour:13];
[c setMinute:0];
[c setSecond:0];

[myArray addObject:c];

Next we need to figure out how far in the future our event is. Thanks to rdelmar we have the code to do this, his answer is below

//Create a func that returns an NSDate. It requires that the Weekday, HR, Min and Secs are passed into it.
-(NSDate *)getNextDateOn:(NSString *)weekday atHour:(NSInteger)hour minute:(NSInteger)mins second:(NSInteger)secs {

//Setup an array of weekdays to compare to the imported (NSString *)weekday 
NSArray *array = [NSArray arrayWithObjects:@"Sunday",@"Monday",@"Tuesday",@"Wednesday",@"Thursday",@"Friday",@"Saturday",nil];
NSInteger weekdayNumber = [array indexOfObject:[weekday capitalizedString]] + 1;

//This code finds how many days in the future the imported (NSString *)weekday is
NSDate *now = [NSDate date];
NSCalendar *cal = [NSCalendar autoupdatingCurrentCalendar];
NSDateComponents *nowComps = [cal components:NSWeekdayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate:now];
NSInteger daysForward = (weekdayNumber - nowComps.weekday + 7) % 7;

//Lastly, create an NSDate called eventDate that consists of the 
NSDateComponents *eventComps = [[NSDateComponents alloc] init];
[eventComps setDay:daysForward];
[eventComps setHour: hour - nowComps.hour];
[eventComps setMinute: mins - nowComps.minute];
[eventComps setSecond: secs - nowComps.second];
eventDate = [cal dateByAddingComponents:eventComps toDate:now  options:0];

return eventDate;
}

Here, we take the newly created eventDate and use it to create our event in iCal:

        EKEventStore *eventStore = [[EKEventStore alloc] init];

        EKEvent *event  = [EKEvent eventWithEventStore:eventStore];
        event.title     = @"Move your car!";
        event.startDate = eventDate;
        event.endDate   = [[NSDate alloc] initWithTimeInterval:60.0f * 60.0f sinceDate:event.startDate]; //1 hr long
        [event addAlarm:[EKAlarm alarmWithRelativeOffset:60.0f * -30.0f]]; //30 min before
        //eventLoc was created using CLGeocoder and the method reverseGeocodeLocation:
        //The location is not necessary to create an event but if you'd like the code, ask and i'll post it.
        [event setLocation:eventLoc];
        [event setNotes:@"This event was set by me. ;P"];
        [event setCalendar:[eventStore defaultCalendarForNewEvents]];
        NSError *err;
        [eventStore saveEvent:event span:EKSpanThisEvent error:&err]; 
        NSLog(@"Event Set");

I hope this helps someone as much as it’s helped me.

:END OF UPDATE:

I’ve read through the documentation of NSDate hoping to find an easy way to find “the next upcoming Mon 1:00PM”.

For instance, lets say the bakery is open 1 day a week (Thurs) from 9am – 6pm… If it is now Thurs, 8am, I want to get an NSDate for 1hr from now. If today were Thurs @ 7pm, I’d want the NSDate for next Thurs at 9am.

I plan on making an event in iCal (tests have been successful) but the trouble is in calculating the event time.

Can you point me towards a good explanation of NSDate or help me figure out how to calculate the NSDate’s I’m looking for?

I’m looking to fix this code:

    EKEventStore *eventStore = [[EKEventStore alloc] init];

    EKEvent *event  = [EKEvent eventWithEventStore:eventStore];
    event.title     = @"Bakery's Open!";

    event.startDate = [[NSDate alloc] init];
    event.endDate   = [[NSDate alloc] initWithTimeInterval:600 sinceDate:event.startDate];

    [event setCalendar:[eventStore defaultCalendarForNewEvents]];
    NSError *err;
    [eventStore saveEvent:event span:EKSpanThisEvent error:&err]; 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:39:06+00:00Added an answer on May 31, 2026 at 9:39 pm

    To find a date like this requires using NSDateComponents and NSCalendar. The main task, I think, is to figure out how many days in the future your target date is. To do this you need to get the weekday date component of the current date and calculate how many days it is to the weekday you’re looking for. I think the following code should get you close:

    -(NSDate *)getNextDateOn:(NSString *)weekday atHour:(NSInteger)hour minute:(NSInteger)mins second:(NSInteger)secs {
    NSArray *array = [NSArray arrayWithObjects:@"Sunday",@"Monday",@"Tuesday",@"Wednesday",@"Thursday",@"Friday",@"Saturday",nil];
    NSInteger weekdayNumber = [array indexOfObject:[weekday capitalizedString]] + 1;
    NSDate *now = [NSDate date];
    NSCalendar *cal = [NSCalendar autoupdatingCurrentCalendar];
    NSDateComponents *nowComps = [cal components:NSWeekdayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate:now];
    NSInteger daysForward = (weekdayNumber - nowComps.weekday + 7) % 7;
    
    NSDateComponents *eventComps = [[NSDateComponents alloc] init];
    [eventComps setDay:daysForward];
    [eventComps setHour: hour - nowComps.hour];
    [eventComps setMinute: mins - nowComps.minute];
    [eventComps setSecond: secs - nowComps.second];
    NSDate *eventDate = [cal dateByAddingComponents:eventComps toDate:now  options:0];
    [eventComps release];
    return eventDate;
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: This question was an epic failure, but here's the working solution. It's based
I get this error when I do an svn update : Working copy XXXXXXXX
UPDATE: It was suggested in the comments that I create a wiki for this.
I have this classic ASP site which has been working fine until we updated
Update: This turned into a blog post, with updated links and code, over at
Update: this question, including the title, was rephrased, see history for details I know
Update: This does work, I was being stupid :( i have the following extension
Update: This is, as I was told, no principle Python related problem, but seems
UPDATE: this is a repost of How to make shell scripts robust to source
UPDATE: This question is out of date, but left for informational purposes. Original Question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.