From 8cd3966b44fdf83baa955a1e8fda85e373b0bc41 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 23 Apr 1999 14:38:03 +0000 Subject: [PATCH] Widened class cluster git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4123 72102866-910b-0410-8b05-ffd578937521 --- Source/NSDate.m | 148 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 140 insertions(+), 8 deletions(-) diff --git a/Source/NSDate.m b/Source/NSDate.m index 5ecfe89c2..9376a275c 100644 --- a/Source/NSDate.m +++ b/Source/NSDate.m @@ -33,6 +33,7 @@ #include #include #include +#include #include #ifndef __WIN32__ #include @@ -57,11 +58,25 @@ #define DISTANT_FUTURE (DISTANT_YEARS * 365.0 * 24 * 60 * 60) #define DISTANT_PAST (-DISTANT_FUTURE) + + static BOOL debug = NO; static Class abstractClass = nil; static Class concreteClass = nil; static Class calendarClass = nil; +@interface GSDateSingle : NSGDate +@end + +@interface GSDatePast : GSDateSingle +@end + +@interface GSDateFuture : GSDateSingle +@end + +static NSDate *_distantPast = nil; +static NSDate *_distantFuture = nil; + static NSString* findInArray(NSArray *array, unsigned pos, NSString *str) @@ -833,18 +848,16 @@ GSTimeNow() + (id) distantFuture { - static id df = nil; - if (!df) - df = [[self alloc] initWithTimeIntervalSinceReferenceDate: DISTANT_FUTURE]; - return df; + if (_distantFuture == nil) + return [GSDateFuture allocWithZone: 0]; + return _distantFuture; } + (id) distantPast { - static id dp = nil; - if (!dp) - dp = [[self alloc] initWithTimeIntervalSinceReferenceDate: DISTANT_PAST]; - return dp; + if (_distantPast == nil) + return [GSDatePast allocWithZone: 0]; + return _distantPast; } - (id) copyWithZone: (NSZone*)zone @@ -1178,3 +1191,122 @@ GSTimeNow() @end + + +/* + * This abstract class represents a date of which there can be only + * one instance. + */ +@implementation GSDateSingle + ++ (void) initialize +{ + if (self == [GSDateSingle class]) + { + [self setVersion: 1]; + behavior_class_add_class(self, [NSGDate class]); + } +} + +- (Class) classForPortCoder +{ + return [self class]; +} + +- replacementObjectForPortCoder: aRmc +{ + return self; +} + +- (void) encodeWithCoder: (NSCoder*)coder +{ +} + +- (id) initWithCoder: (NSCoder*)coder +{ + return self; +} + +- (void) autorelease +{ +} + +- (void) release +{ +} + +- (id) retain +{ + return self; +} + +- (id) allocWithZone: (NSZone*)z +{ + [NSException raise: NSInternalInconsistencyException + format: @"Attempt to allocate fixed date"]; +} + +- (id) copyWithZone: (NSZone*)z +{ + return self; +} + +- (void) dealloc +{ + [NSException raise: NSInternalInconsistencyException + format: @"Attempt to deallocate fixed date"]; +} + +- (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)secs +{ + return self; +} + +@end + + + +@implementation GSDatePast + ++ (id) allocWithZone: (NSZone*)z +{ + if (_distantPast == nil) + { + id obj = NSAllocateObject(self, 0, NSDefaultMallocZone()); + + _distantPast = [obj init]; + } + return _distantPast; +} + +- (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)secs +{ + seconds_since_ref = DISTANT_PAST; + return self; +} + +@end + + +@implementation GSDateFuture + ++ (id) allocWithZone: (NSZone*)z +{ + if (_distantFuture == nil) + { + id obj = NSAllocateObject(self, 0, NSDefaultMallocZone()); + + _distantFuture = [obj init]; + } + return _distantFuture; +} + +- (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)secs +{ + seconds_since_ref = DISTANT_FUTURE; + return self; +} + +@end + +