From ab65e628d3af6457e769d3d79665fd62f3fab16c Mon Sep 17 00:00:00 2001 From: rfm Date: Mon, 10 Sep 2012 05:18:09 +0000 Subject: [PATCH] OSX compatibility tweaks inspiered by testplant git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@35555 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 8 ++++++++ Headers/Foundation/NSDate.h | 8 ++++++++ Source/NSCalendarDate.m | 19 ++++++++++++++----- Source/NSDate.m | 14 +++++++------- Source/NSRunLoop.m | 14 +++++++++++++- 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8463cdd3b..a94a731b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2012-09-10 Richard Frith-Macdonald + + * Headers/Foundation/NSDate.h: Declare new OSX method to add time + interval to a date. + * Source/NSDate.m: Implement it + * Source/NSCalendarDate.m: Ditto + * Source/NSRunLoop.m: Add exception handling for run loop performer. + 2012-09-10 Sergii Stoian * Source/NSFileManager.m: diff --git a/Headers/Foundation/NSDate.h b/Headers/Foundation/NSDate.h index 0faada148..723ee4eb5 100644 --- a/Headers/Foundation/NSDate.h +++ b/Headers/Foundation/NSDate.h @@ -106,6 +106,14 @@ GS_EXPORT const NSTimeInterval NSTimeIntervalSince1970; - (BOOL) isEqualToDate: (NSDate*)other; - (NSDate*) laterDate: (NSDate*)otherDate; +#if OS_API_VERSION(100600,GS_API_LATEST) +/** + * Returns an autoreleased NSDate instance whose value is offset from + * that of the receiver by the specified interval. + */ +- (id) dateByAddingTimeInterval: (NSTimeInterval)ti; +#endif + #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) + (id) dateWithNaturalLanguageString: (NSString*)string; + (id) dateWithNaturalLanguageString: (NSString*)string diff --git a/Source/NSCalendarDate.m b/Source/NSCalendarDate.m index 2c1f878f8..9ea6801d7 100644 --- a/Source/NSCalendarDate.m +++ b/Source/NSCalendarDate.m @@ -445,6 +445,20 @@ GSPrivateTimeNow(void) * value of the receiver and adding the interval in seconds specified. */ - (id) addTimeInterval: (NSTimeInterval)seconds +{ + return [self dateByAddingTimeInterval: seconds]; +} + +- (Class) classForCoder +{ + return [self class]; +} + +/** + * Creates and returns a new NSCalendarDate object by taking the + * value of the receiver and adding the interval specified. + */ +- (id) dateByAddingTimeInterval: (NSTimeInterval)seconds { id newObj = [[self class] dateWithTimeIntervalSinceReferenceDate: [self timeIntervalSinceReferenceDate] + seconds]; @@ -455,11 +469,6 @@ GSPrivateTimeNow(void) return newObj; } -- (Class) classForCoder -{ - return [self class]; -} - - (id) replacementObjectForPortCoder: (NSPortCoder*)aRmc { return self; diff --git a/Source/NSDate.m b/Source/NSDate.m index 3f56ff573..ca37ec027 100644 --- a/Source/NSDate.m +++ b/Source/NSDate.m @@ -1132,6 +1132,12 @@ otherTime(NSDate* other) return self; } +- (id) dateByAddingTimeInterval: (NSTimeInterval)seconds +{ + return [[self class] dateWithTimeIntervalSinceReferenceDate: + otherTime(self) + seconds]; +} + /** * Returns an autoreleased instance of the [NSCalendarDate] class whose * date/time value is the same as that of the receiver, and which uses @@ -1203,15 +1209,9 @@ otherTime(NSDate* other) return [s autorelease]; } -/** - * Returns an autoreleased NSDate instance whose value if offset from - * that of the receiver by seconds. - */ - (id) addTimeInterval: (NSTimeInterval)seconds { - /* xxx We need to check for overflow? */ - return [[self class] dateWithTimeIntervalSinceReferenceDate: - otherTime(self) + seconds]; + return [self dateByAddingTimeInterval: seconds]; } /** diff --git a/Source/NSRunLoop.m b/Source/NSRunLoop.m index 2b78a4f03..37ffef023 100644 --- a/Source/NSRunLoop.m +++ b/Source/NSRunLoop.m @@ -105,7 +105,19 @@ static NSDate *theFuture = nil; - (void) fire { - [target performSelector: selector withObject: argument]; + NS_DURING + { + [target performSelector: selector withObject: argument]; + } + NS_HANDLER + { + NSLog(@"*** NSRunLoop ignoring exception '%@' (reason '%@') " + @"raised during performSelector... with target %p " + @"and selector '%@'", + [localException name], [localException reason], target, + NSStringFromSelector([target selector])); + } + NS_ENDHANDLER } - (id) initWithSelector: (SEL)aSelector