mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Widened class cluster
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4123 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
c12d0a9fb8
commit
cf5b1990b9
1 changed files with 140 additions and 8 deletions
148
Source/NSDate.m
148
Source/NSDate.m
|
@ -33,6 +33,7 @@
|
|||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <Foundation/NSCharacterSet.h>
|
||||
#include <Foundation/NSScanner.h>
|
||||
#include <base/behavior.h>
|
||||
#include <base/fast.x>
|
||||
#ifndef __WIN32__
|
||||
#include <time.h>
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue