• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Adding 30 minutes to an NSDate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding 30 minutes to an NSDate


  • Subject: Re: Adding 30 minutes to an NSDate
  • From: Bob <email@hidden>
  • Date: Thu, 21 Jul 2005 00:26:05 +0200


El 20/07/2005, a las 9:14, Uli Kusterer escribió:

Hi,

is there a recommended way to add 30 minutes to an NSDate? I have an app that announces the time every hour. For that, I'm setting a Timer's next fire time to an NSCalendarDate after each announcement. Now the problem is the wrap-over from 23:00 to 0:00, where I'd also have to add 1 to the day and, if that day is at the end of the month, I'd also have to add to the month.

I could just hand-code this, but then I'd be effectively duplicating code that's already inside NSCalendarDate. So, is there a better way to do that? If not, has anyone already written that code and would like to share it?

Thanks for any clues, pointers to OS libraries or docs etc,
-- M. Uli Kusterer
http://www.zathras.de


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


Uli,

why you don't try the Omni Framework on it you will find in OmniFoundation you will find the following, with the classes included you can do what are looking for.

OFScheduler.h

#import <OmniFoundation/OFObject.h>

@class NSDate, NSRecursiveLock, NSMutableArray;
@class OFDedicatedThreadScheduler, OFInvocation, OFScheduledEvent;

#import <Foundation/NSDate.h> // For NSTimeInterval
#import <OmniFoundation/OFWeakRetainConcreteImplementation.h>

@interface OFScheduler : OFObject <OFWeakRetain>
{
    NSMutableArray *scheduleQueue;
    NSRecursiveLock *scheduleLock;
    BOOL terminationSignaled;
    OFWeakRetainConcreteImplementation_IVARS;
}

+ (OFScheduler *)mainScheduler;
+ (OFDedicatedThreadScheduler *)dedicatedThreadScheduler;

- (void)scheduleEvent:(OFScheduledEvent *)event;
- (BOOL)abortEvent:(OFScheduledEvent *)anEvent;
- (void)abortSchedule;
- (OFScheduler *)subscheduler;
- (NSDate *)dateOfFirstEvent;

OFWeakRetainConcreteImplementation_INTERFACE

@end

@interface OFScheduler (OFConvenienceMethods)
- (OFScheduledEvent *)scheduleInvocation:(OFInvocation *)anInvocation atDate:(NSDate *)date;
- (OFScheduledEvent *)scheduleInvocation:(OFInvocation *)anInvocation afterTime:(NSTimeInterval)time;
- (OFScheduledEvent *)scheduleSelector:(SEL)selector onObject:(id) anObject atDate:(NSDate *)date;
- (OFScheduledEvent *)scheduleSelector:(SEL)selector onObject:(id) anObject withObject:(id)anArgument atDate:(NSDate *)date;
- (OFScheduledEvent *)scheduleSelector:(SEL)selector onObject:(id) anObject withBool:(BOOL)anArgument atDate:(NSDate *)date;
- (OFScheduledEvent *)scheduleSelector:(SEL)selector onObject:(id) anObject afterTime:(NSTimeInterval)time;
- (OFScheduledEvent *)scheduleSelector:(SEL)selector onObject:(id) anObject withObject:(id)anArgument afterTime:(NSTimeInterval)time;
- (OFScheduledEvent *)scheduleSelector:(SEL)selector onObject:(id) anObject withBool:(BOOL)anArgument afterTime:(NSTimeInterval)time;
@end


@interface OFScheduler (SubclassesOnly)
- (void)invokeScheduledEvents;
// Subclasses call this method to invoke all events scheduled to happen up to the current time
- (void)scheduleEvents;
// Subclasses override this method to schedule their events
- (void)cancelScheduledEvents;
// Subclasses override this method to cancel their previously scheduled events.
@end


#import <OmniFoundation/FrameworkDefines.h>

OmniFoundation_EXTERN BOOL OFSchedulerDebug;

Roberto Cruz
InCrew Software

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Adding 30 minutes to an NSDate (From: Uli Kusterer <email@hidden>)

  • Prev by Date: Re: unreleased retained objects
  • Next by Date: Re: Where do I define awakeFromFetch?
  • Previous by thread: Re: Adding 30 minutes to an NSDate
  • Next by thread: Re: Adding 30 minutes to an NSDate
  • Index(es):
    • Date
    • Thread