Index: src/OFDate.h ================================================================== --- src/OFDate.h +++ src/OFDate.h @@ -24,19 +24,12 @@ /** * @class OFDate OFDate.h ObjFW/OFDate.h * * @brief A class for storing, accessing and comparing dates. */ -#ifndef OF_DATE_M -OF_SUBCLASSING_RESTRICTED -#endif @interface OFDate: OFObject -{ - OFTimeInterval _seconds; -} - #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) OFDate *distantFuture; @property (class, readonly, nonatomic) OFDate *distantPast; #endif Index: src/OFDate.m ================================================================== --- src/OFDate.m +++ src/OFDate.m @@ -44,18 +44,20 @@ #if defined(OF_AMIGAOS_M68K) || defined(OF_MINT) /* amiga-gcc and freemint-gcc do not have trunc() */ # define trunc(x) ((int64_t)(x)) #endif -@interface OFDate () -+ (instancetype)of_alloc; +@interface OFDatePlaceholder: OFDate @end -@interface OFDateSingleton: OFDate +@interface OFConcreteDate: OFDate +{ + OFTimeInterval _seconds; +} @end -@interface OFDatePlaceholder: OFDateSingleton +@interface OFDateSingleton: OFConcreteDate @end #if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX @interface OFTaggedPointerDate: OFDateSingleton @end @@ -311,16 +313,33 @@ if (ret != nil) return ret; } #endif - return (id)[[OFDate of_alloc] initWithTimeIntervalSince1970: seconds]; + return (id)[[OFConcreteDate alloc] + initWithTimeIntervalSince1970: seconds]; } #ifdef __clang__ # pragma clang diagnostic pop #endif @end + +@implementation OFConcreteDate +- (instancetype)initWithTimeIntervalSince1970: (OFTimeInterval)seconds +{ + self = [super initWithTimeIntervalSince1970: seconds]; + + _seconds = seconds; + + return self; +} + +- (OFTimeInterval)timeIntervalSince1970 +{ + return _seconds; +} +@end #if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX @implementation OFTaggedPointerDate - (OFTimeInterval)timeIntervalSince1970 { @@ -361,15 +380,10 @@ #if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX dateTag = objc_registerTaggedPointerClass([OFTaggedPointerDate class]); #endif } -+ (instancetype)of_alloc -{ - return [super alloc]; -} - + (instancetype)alloc { if (self == [OFDate class]) return (id)&placeholder; @@ -426,15 +440,22 @@ return [self initWithTimeIntervalSince1970: now()]; } - (instancetype)initWithTimeIntervalSince1970: (OFTimeInterval)seconds { - self = [super init]; + if ([self isMemberOfClass: [OFDate class]]) { + @try { + [self doesNotRecognizeSelector: _cmd]; + } @catch (id e) { + [self release]; + @throw e; + } - _seconds = seconds; + abort(); + } - return self; + return [super init]; } - (instancetype)initWithTimeIntervalSinceNow: (OFTimeInterval)seconds { return [self initWithTimeIntervalSince1970: now() + seconds]; @@ -831,11 +852,11 @@ return self; } - (OFTimeInterval)timeIntervalSince1970 { - return _seconds; + OF_UNRECOGNIZED_SELECTOR } - (OFTimeInterval)timeIntervalSinceDate: (OFDate *)otherDate { return self.timeIntervalSince1970 - otherDate.timeIntervalSince1970;