mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
Changes from Scott Christley. See Oct 16 ChangeLog entry.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1885 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
785831bde1
commit
a1e578ebc0
5 changed files with 195 additions and 144 deletions
26
ChangeLog
26
ChangeLog
|
@ -1,3 +1,29 @@
|
||||||
|
Thu Oct 31 11:54:42 1996 Andrew McCallum <mccallum@cs.cmu.edu>
|
||||||
|
|
||||||
|
* src/mframe.m (method_types_get_next_argument): Do weird argframe
|
||||||
|
workaround not just on m68k, but on all NeXT systems. (Reported
|
||||||
|
by Richard Frith-Macdonald <richard@brainstorm.co.uk>.)
|
||||||
|
|
||||||
|
* src/RunLoop.m ([RunLoop -acceptInputForMode:beforeDate:]): Fix
|
||||||
|
assignment of TIMEOUT.TV_USEC. (Reported by Richard
|
||||||
|
Frith-Macdonald <richard@brainstorm.co.uk>.)
|
||||||
|
|
||||||
|
Wed Oct 16 10:01:23 1996 Scott Christley <scottc@net-community.com>
|
||||||
|
|
||||||
|
* checks/nsdate.m: New file.
|
||||||
|
* src/NSCalendarDate.m: New file.
|
||||||
|
* checks/Makefile.in: Add test program for NSDate classes.
|
||||||
|
* src/Makefile.in (GNUSTEP_MFILES: Add NSCalendarDate.m.
|
||||||
|
* src/NSDate.m: Eliminate use of NSConcreteDate. Utilize the
|
||||||
|
NSCalendarDate class for implementing some methods.
|
||||||
|
* src/include/NSDate.h: Add NSCalendarDate interface.
|
||||||
|
|
||||||
|
Tue Oct 1 12:56:09 1996 Nicholas Christopher <nwc@gun.com>
|
||||||
|
|
||||||
|
* NSString.m: Added initWithContentsOfFile: and
|
||||||
|
propertyListFromStringsFileFormat:.
|
||||||
|
* stringsfile.l, stringsfile.y: New files.
|
||||||
|
|
||||||
Fri Oct 25 20:22:37 1996 Andrew McCallum <mccallum@cs.cmu.edu>
|
Fri Oct 25 20:22:37 1996 Andrew McCallum <mccallum@cs.cmu.edu>
|
||||||
|
|
||||||
* src/StdioStream.m (strerror) [!HAS_STRERROR]: New function from
|
* src/StdioStream.m (strerror) [!HAS_STRERROR]: New function from
|
||||||
|
|
|
@ -33,7 +33,11 @@ typedef double NSTimeInterval;
|
||||||
@class NSTimeZone;
|
@class NSTimeZone;
|
||||||
@class NSTimeZoneDetail;
|
@class NSTimeZoneDetail;
|
||||||
|
|
||||||
@interface NSDate : NSObject <NSCopying>
|
@interface NSDate : NSObject
|
||||||
|
|
||||||
|
{
|
||||||
|
NSTimeInterval seconds_since_ref;
|
||||||
|
}
|
||||||
|
|
||||||
// Getting current time
|
// Getting current time
|
||||||
|
|
||||||
|
@ -41,13 +45,13 @@ typedef double NSTimeInterval;
|
||||||
|
|
||||||
// Allocation and initializing
|
// Allocation and initializing
|
||||||
|
|
||||||
+ (id) allocWithZone: (NSZone*)z;
|
|
||||||
+ (NSDate*) date;
|
+ (NSDate*) date;
|
||||||
+ (NSDate*) dateWithTimeIntervalSinceNow: (NSTimeInterval)seconds;
|
+ (NSDate*) dateWithTimeIntervalSinceNow: (NSTimeInterval)seconds;
|
||||||
|
+ (NSDate*) dateWithTimeIntervalSince1970: (NSTimeInterval)seconds;
|
||||||
+ (NSDate*) dateWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds;
|
+ (NSDate*) dateWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds;
|
||||||
+ (NSDate*) distantFuture;
|
+ (NSDate*) distantFuture;
|
||||||
+ (NSDate*) distantPast;
|
+ (NSDate*) distantPast;
|
||||||
- (id) init;
|
|
||||||
- (id) initWithString: (NSString*)description;
|
- (id) initWithString: (NSString*)description;
|
||||||
- (NSDate*) initWithTimeInterval: (NSTimeInterval)secsToBeAdded
|
- (NSDate*) initWithTimeInterval: (NSTimeInterval)secsToBeAdded
|
||||||
sinceDate: (NSDate*)anotherDate;
|
sinceDate: (NSDate*)anotherDate;
|
||||||
|
@ -64,6 +68,7 @@ typedef double NSTimeInterval;
|
||||||
- (NSString*) description;
|
- (NSString*) description;
|
||||||
- (NSString*) descriptionWithCalendarFormat: (NSString*)format
|
- (NSString*) descriptionWithCalendarFormat: (NSString*)format
|
||||||
timeZone: (NSTimeZone*)aTimeZone;
|
timeZone: (NSTimeZone*)aTimeZone;
|
||||||
|
- (NSString *) descriptionWithLocale: (NSDictionary *)locale;
|
||||||
|
|
||||||
// Adding and getting intervals
|
// Adding and getting intervals
|
||||||
|
|
||||||
|
@ -129,4 +134,88 @@ typedef double NSTimeInterval;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@interface NSCalendarDate : NSDate
|
||||||
|
|
||||||
|
{
|
||||||
|
NSString *calendar_format;
|
||||||
|
NSTimeZoneDetail *time_zone;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getting an NSCalendar Date
|
||||||
|
+ (NSCalendarDate *)calendarDate;
|
||||||
|
+ (NSCalendarDate *)dateWithString:(NSString *)description
|
||||||
|
calendarFormat:(NSString *)format;
|
||||||
|
+ (NSCalendarDate *)dateWithString:(NSString *)description
|
||||||
|
calendarFormat:(NSString *)format
|
||||||
|
locale:(NSDictionary *)dictionary;
|
||||||
|
+ (NSCalendarDate *)dateWithYear:(int)year
|
||||||
|
month:(unsigned int)month
|
||||||
|
day:(unsigned int)day
|
||||||
|
hour:(unsigned int)hour
|
||||||
|
minute:(unsigned int)minute
|
||||||
|
second:(unsigned int)second
|
||||||
|
timeZone:(NSTimeZone *)aTimeZone;
|
||||||
|
|
||||||
|
// Initializing an NSCalendar Date
|
||||||
|
- (id)initWithString:(NSString *)description;
|
||||||
|
- (id)initWithString:(NSString *)description
|
||||||
|
calendarFormat:(NSString *)format;
|
||||||
|
- (id)initWithString:(NSString *)description
|
||||||
|
calendarFormat:(NSString *)format
|
||||||
|
locale:(NSDictionary *)dictionary;
|
||||||
|
- (id)initWithYear:(int)year
|
||||||
|
month:(unsigned int)month
|
||||||
|
day:(unsigned int)day
|
||||||
|
hour:(unsigned int)hour
|
||||||
|
minute:(unsigned int)minute
|
||||||
|
second:(unsigned int)second
|
||||||
|
timeZone:(NSTimeZone *)aTimeZone;
|
||||||
|
|
||||||
|
// Retreiving Date Elements
|
||||||
|
- (int)dayOfCommonEra;
|
||||||
|
- (int)dayOfMonth;
|
||||||
|
- (int)dayOfWeek;
|
||||||
|
- (int)dayOfYear;
|
||||||
|
- (int)hourOfDay;
|
||||||
|
- (int)minuteOfHour;
|
||||||
|
- (int)monthOfYear;
|
||||||
|
- (int)secondOfMinute;
|
||||||
|
- (int)yearOfCommonEra;
|
||||||
|
|
||||||
|
// Providing Adjusted Dates
|
||||||
|
- (NSCalendarDate *)addYear:(int)year
|
||||||
|
month:(unsigned int)month
|
||||||
|
day:(unsigned int)day
|
||||||
|
hour:(unsigned int)hour
|
||||||
|
minute:(unsigned int)minute
|
||||||
|
second:(unsigned int)second;
|
||||||
|
|
||||||
|
// Getting String Descriptions of Dates
|
||||||
|
- (NSString *)description;
|
||||||
|
- (NSString *)descriptionWithCalendarFormat:(NSString *)format;
|
||||||
|
- (NSString *)descriptionWithCalendarFormat:(NSString *)format
|
||||||
|
locale:(NSDictionary *)locale;
|
||||||
|
- (NSString *)descriptionWithLocale:(NSDictionary *)locale;
|
||||||
|
|
||||||
|
// Getting and Setting Calendar Formats
|
||||||
|
- (NSString *)calendarFormat;
|
||||||
|
- (void)setCalendarFormat:(NSString *)format;
|
||||||
|
|
||||||
|
// Getting and Setting Time Zones
|
||||||
|
- (void)setTimeZone:(NSTimeZone *)aTimeZone;
|
||||||
|
- (NSTimeZoneDetail *)timeZoneDetail;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface NSCalendarDate (GregorianDate)
|
||||||
|
|
||||||
|
- (int)lastDayOfGregorianMonth:(int)month year:(int)year;
|
||||||
|
- (int)absoluteGregorianDay:(int)day month:(int)month year:(int)year;
|
||||||
|
- (void)gregorianDateFromAbsolute:(int)d
|
||||||
|
day:(int *)day
|
||||||
|
month:(int *)month
|
||||||
|
year:(int *)year;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
#endif /* __NSDate_h_GNUSTEP_BASE_INCLUDE */
|
#endif /* __NSDate_h_GNUSTEP_BASE_INCLUDE */
|
||||||
|
|
|
@ -357,6 +357,7 @@ NSAssertionHandler.m \
|
||||||
NSAutoreleasePool.m \
|
NSAutoreleasePool.m \
|
||||||
NSBitmapCharSet.m \
|
NSBitmapCharSet.m \
|
||||||
NSBundle.m \
|
NSBundle.m \
|
||||||
|
NSCalendarDate.m \
|
||||||
NSCallBacks.m \
|
NSCallBacks.m \
|
||||||
NSCharacterSet.m \
|
NSCharacterSet.m \
|
||||||
NSCoder.m \
|
NSCoder.m \
|
||||||
|
|
214
Source/NSDate.m
214
Source/NSDate.m
|
@ -2,6 +2,7 @@
|
||||||
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
|
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
|
||||||
|
|
||||||
Written by: Jeremy Bettis <jeremy@hksys.com>
|
Written by: Jeremy Bettis <jeremy@hksys.com>
|
||||||
|
Rewritten by: Scott Christley <scottc@net-community.com>
|
||||||
Date: March 1995
|
Date: March 1995
|
||||||
|
|
||||||
This file is part of the GNUstep Base Library.
|
This file is part of the GNUstep Base Library.
|
||||||
|
@ -53,71 +54,10 @@
|
||||||
#define DISTANT_PAST (-DISTANT_FUTURE)
|
#define DISTANT_PAST (-DISTANT_FUTURE)
|
||||||
|
|
||||||
|
|
||||||
/* Concrete implementation of NSDate. */
|
/* The implementation of NSDate. */
|
||||||
|
|
||||||
@interface NSConcreteDate : NSDate
|
|
||||||
{
|
|
||||||
NSTimeInterval seconds_since_ref;
|
|
||||||
}
|
|
||||||
- (id) copyWithZone: (NSZone*)zone;
|
|
||||||
- (NSTimeInterval) timeIntervalSinceReferenceDate;
|
|
||||||
- (id) init;
|
|
||||||
- (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)secs;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation NSConcreteDate
|
|
||||||
|
|
||||||
- (id) copyWithZone: (NSZone*)zone
|
|
||||||
{
|
|
||||||
return [[[self class] allocWithZone: zone]
|
|
||||||
initWithTimeIntervalSinceReferenceDate: seconds_since_ref];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSTimeInterval) timeIntervalSinceReferenceDate
|
|
||||||
{
|
|
||||||
return seconds_since_ref;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSTimeInterval) timeIntervalSinceNow
|
|
||||||
{
|
|
||||||
NSTimeInterval now = [[self class] timeIntervalSinceReferenceDate];
|
|
||||||
return seconds_since_ref - now;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) init
|
|
||||||
{
|
|
||||||
return [self initWithTimeIntervalSinceReferenceDate:
|
|
||||||
[[self class] timeIntervalSinceReferenceDate]];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)secs
|
|
||||||
{
|
|
||||||
self = [super init];
|
|
||||||
seconds_since_ref = secs;
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
|
|
||||||
/* The abstract implementation of NSDate. */
|
|
||||||
|
|
||||||
@implementation NSDate
|
@implementation NSDate
|
||||||
|
|
||||||
+ (void) initialize
|
|
||||||
{
|
|
||||||
/* xxx Force NSConcreteDate to initialize itself. There seems to be
|
|
||||||
a bug with __objc_word_forward and returning doubles? */
|
|
||||||
if (self == [NSDate class])
|
|
||||||
[NSConcreteDate instanceMethodForSelector:
|
|
||||||
@selector(timeIntervalSinceReferenceDate)];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) copyWithZone: (NSZone*)zone
|
|
||||||
{
|
|
||||||
return [[NSConcreteDate class] copyWithZone:zone];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getting current time
|
// Getting current time
|
||||||
|
|
||||||
+ (NSTimeInterval) timeIntervalSinceReferenceDate
|
+ (NSTimeInterval) timeIntervalSinceReferenceDate
|
||||||
|
@ -139,17 +79,9 @@
|
||||||
|
|
||||||
// Allocation and initializing
|
// Allocation and initializing
|
||||||
|
|
||||||
+ (id) allocWithZone: (NSZone*)z
|
|
||||||
{
|
|
||||||
if (self != [NSDate class])
|
|
||||||
return [super allocWithZone:z];
|
|
||||||
return [NSConcreteDate allocWithZone:z];
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSDate*) date
|
+ (NSDate*) date
|
||||||
{
|
{
|
||||||
return [[[self alloc] init]
|
return [[[self alloc] init] autorelease];
|
||||||
autorelease];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSDate*) dateWithTimeIntervalSinceNow: (NSTimeInterval)seconds
|
+ (NSDate*) dateWithTimeIntervalSinceNow: (NSTimeInterval)seconds
|
||||||
|
@ -158,6 +90,12 @@
|
||||||
autorelease];
|
autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (NSDate *)dateWithTimeIntervalSince1970:(NSTimeInterval)seconds
|
||||||
|
{
|
||||||
|
return [[[self alloc] initWithTimeIntervalSinceReferenceDate:
|
||||||
|
UNIX_REFERENCE_INTERVAL + seconds] autorelease];
|
||||||
|
}
|
||||||
|
|
||||||
+ (NSDate*) dateWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds
|
+ (NSDate*) dateWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds
|
||||||
{
|
{
|
||||||
return [[[self alloc] initWithTimeIntervalSinceReferenceDate: seconds]
|
return [[[self alloc] initWithTimeIntervalSinceReferenceDate: seconds]
|
||||||
|
@ -182,46 +120,41 @@
|
||||||
|
|
||||||
- (id) init
|
- (id) init
|
||||||
{
|
{
|
||||||
// We have to do this, otherwise the subclasses cannot do [super init];
|
return [self initWithTimeIntervalSinceReferenceDate:
|
||||||
return [super init];
|
[[self class] timeIntervalSinceReferenceDate]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithString: (NSString*)description
|
- (id) initWithString: (NSString*)description
|
||||||
{
|
{
|
||||||
NSTimeInterval theTime = 0;
|
// Easiest to just have NSCalendarDate do the work for us
|
||||||
/* From the doc:
|
NSCalendarDate *d = [NSCalendarDate alloc];
|
||||||
Returns an calendar date object with a date and time value
|
[d initWithString: description];
|
||||||
specified by the international string-representation format:
|
[self initWithTimeIntervalSinceReferenceDate:
|
||||||
YYYY-MM-DD HH:MM:SS -HHMM, where -HHMM is a time zone offset in
|
[d timeIntervalSinceReferenceDate]];
|
||||||
hours and minutes from Greenwich Mean Time. (Adding the offset to
|
[d release];
|
||||||
the specified time yields the equivalent GMT.) An example string
|
return self;
|
||||||
might be "1994-03-30 13:12:43 +0900". You must specify all fields of
|
|
||||||
the format, including the time-zone offset, which must have a plus-
|
|
||||||
or minus-sign prefix.
|
|
||||||
*/
|
|
||||||
/* a miracle occurs ****************************** */
|
|
||||||
[self notImplemented:_cmd];
|
|
||||||
return [self initWithTimeIntervalSinceReferenceDate: theTime];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDate*) initWithTimeInterval: (NSTimeInterval)secsToBeAdded
|
- (NSDate*) initWithTimeInterval: (NSTimeInterval)secsToBeAdded
|
||||||
sinceDate: (NSDate*)anotherDate;
|
sinceDate: (NSDate*)anotherDate;
|
||||||
{
|
{
|
||||||
|
// Get the other date's time, add the secs and init thyself
|
||||||
return [self initWithTimeIntervalSinceReferenceDate:
|
return [self initWithTimeIntervalSinceReferenceDate:
|
||||||
[anotherDate timeIntervalSinceReferenceDate]];
|
[anotherDate timeIntervalSinceReferenceDate] + secsToBeAdded];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDate*) initWithTimeIntervalSinceNow: (NSTimeInterval)secsToBeAdded;
|
- (NSDate*) initWithTimeIntervalSinceNow: (NSTimeInterval)secsToBeAdded;
|
||||||
{
|
{
|
||||||
// Get the current time, add the secs and init thyself;
|
// Get the current time, add the secs and init thyself
|
||||||
return [self initWithTimeIntervalSinceReferenceDate:
|
return [self initWithTimeIntervalSinceReferenceDate:
|
||||||
[[self class] timeIntervalSinceReferenceDate] + secsToBeAdded];
|
[[self class] timeIntervalSinceReferenceDate] + secsToBeAdded];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)secs;
|
- (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)secs
|
||||||
{
|
{
|
||||||
[self subclassResponsibility: _cmd];
|
[super init];
|
||||||
return nil;
|
seconds_since_ref = secs;
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Converting to NSCalendar
|
// Converting to NSCalendar
|
||||||
|
@ -229,50 +162,59 @@
|
||||||
- (NSCalendarDate *) dateWithCalendarFormat: (NSString*)formatString
|
- (NSCalendarDate *) dateWithCalendarFormat: (NSString*)formatString
|
||||||
timeZone: (NSTimeZone*)timeZone
|
timeZone: (NSTimeZone*)timeZone
|
||||||
{
|
{
|
||||||
// Not done yet, NSCalendarDate doesn't exist yet!
|
NSCalendarDate *d = [NSCalendarDate alloc];
|
||||||
[self notImplemented: _cmd];
|
[d initWithTimeIntervalSinceReferenceDate: seconds_since_ref];
|
||||||
return nil;
|
[d setCalendarFormat: formatString];
|
||||||
|
[d setTimeZone: timeZone];
|
||||||
|
return [d autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Representing dates
|
// Representing dates
|
||||||
|
|
||||||
- (NSString*) description
|
- (NSString*) description
|
||||||
{
|
{
|
||||||
/* *********************** only works for >1970 dates */
|
// Easiest to just have NSCalendarDate do the work for us
|
||||||
struct tm *theTime;
|
NSString *s;
|
||||||
NSTimeInterval secs;
|
NSCalendarDate *d = [NSCalendarDate alloc];
|
||||||
time_t unix_secs;
|
[d initWithTimeIntervalSinceReferenceDate: seconds_since_ref];
|
||||||
char buf[64];
|
s = [d description];
|
||||||
|
[d release];
|
||||||
secs = [self timeIntervalSinceReferenceDate];
|
return s;
|
||||||
unix_secs = (time_t)secs - (time_t)UNIX_REFERENCE_INTERVAL;
|
|
||||||
theTime = localtime(&unix_secs);
|
|
||||||
/*
|
|
||||||
Gregor Hoffleit <flight@mathi.uni-heidelberg.DE> reports problems
|
|
||||||
with strftime on i386-next-nextstep3.
|
|
||||||
Date: Fri, 12 Jan 96 16:00:42 +0100
|
|
||||||
*/
|
|
||||||
#ifdef NeXT
|
|
||||||
sprintf(buf,"%4d-%02d-%02d %02d:%02d:%02d %c%02d%02d",
|
|
||||||
1900+theTime->tm_year, theTime->tm_mon+1, theTime->tm_mday,
|
|
||||||
theTime->tm_hour, theTime->tm_min, theTime->tm_sec,
|
|
||||||
(theTime->tm_gmtoff>0)?'+':'-', abs(theTime->tm_gmtoff)/3600,
|
|
||||||
(abs(theTime->tm_gmtoff)/60)%60);
|
|
||||||
#else
|
|
||||||
strftime(buf, 64, "%Y-%m-%d %H:%M:%S", theTime);
|
|
||||||
#endif
|
|
||||||
return [NSString stringWithCString: buf];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString*) descriptionWithCalendarFormat: (NSString*)format
|
- (NSString*) descriptionWithCalendarFormat: (NSString*)format
|
||||||
timeZone: (NSTimeZone*)aTimeZone
|
timeZone: (NSTimeZone*)aTimeZone
|
||||||
{
|
{
|
||||||
// Not done yet, no NSCalendarDate or NSTimeZone...
|
// Easiest to just have NSCalendarDate do the work for us
|
||||||
[self notImplemented: _cmd];
|
NSString *s;
|
||||||
return nil;
|
NSCalendarDate *d = [NSCalendarDate alloc];
|
||||||
|
id f, t;
|
||||||
|
|
||||||
|
[d initWithTimeIntervalSinceReferenceDate: seconds_since_ref];
|
||||||
|
if (!format)
|
||||||
|
f = [d calendarFormat];
|
||||||
|
else
|
||||||
|
f = format;
|
||||||
|
if (!aTimeZone)
|
||||||
|
t = [d timeZoneDetail];
|
||||||
|
else
|
||||||
|
t = aTimeZone;
|
||||||
|
|
||||||
|
s = [d descriptionWithCalendarFormat: f timeZone: t];
|
||||||
|
[d release];
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString *) descriptionWithLocale: (NSDictionary *)locale
|
||||||
|
{
|
||||||
|
// Easiest to just have NSCalendarDate do the work for us
|
||||||
|
NSString *s;
|
||||||
|
NSCalendarDate *d = [NSCalendarDate alloc];
|
||||||
|
[d initWithTimeIntervalSinceReferenceDate: seconds_since_ref];
|
||||||
|
s = [d descriptionWithLocale: locale];
|
||||||
|
[d release];
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
// Adding and getting intervals
|
// Adding and getting intervals
|
||||||
|
|
||||||
|
@ -280,38 +222,33 @@
|
||||||
{
|
{
|
||||||
/* xxx We need to check for overflow? */
|
/* xxx We need to check for overflow? */
|
||||||
return [[self class] dateWithTimeIntervalSinceReferenceDate:
|
return [[self class] dateWithTimeIntervalSinceReferenceDate:
|
||||||
[self timeIntervalSinceReferenceDate] + seconds];
|
seconds_since_ref + seconds];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSTimeInterval) timeIntervalSinceDate: (NSDate*)otherDate
|
- (NSTimeInterval) timeIntervalSinceDate: (NSDate*)otherDate
|
||||||
{
|
{
|
||||||
return [self timeIntervalSinceReferenceDate] -
|
return seconds_since_ref - [otherDate timeIntervalSinceReferenceDate];
|
||||||
[otherDate timeIntervalSinceReferenceDate];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSTimeInterval) timeIntervalSinceNow
|
- (NSTimeInterval) timeIntervalSinceNow
|
||||||
{
|
{
|
||||||
NSTimeInterval now = [[self class] timeIntervalSinceReferenceDate];
|
NSTimeInterval now = [[self class] timeIntervalSinceReferenceDate];
|
||||||
NSTimeInterval me = [self timeIntervalSinceReferenceDate];
|
return seconds_since_ref - now;
|
||||||
return me - now;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSTimeInterval) timeIntervalSinceReferenceDate
|
- (NSTimeInterval) timeIntervalSinceReferenceDate
|
||||||
{
|
{
|
||||||
[self subclassResponsibility: _cmd];
|
return seconds_since_ref;
|
||||||
return 0.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comparing dates
|
// Comparing dates
|
||||||
|
|
||||||
- (NSComparisonResult) compare: (NSDate*)otherDate
|
- (NSComparisonResult) compare: (NSDate*)otherDate
|
||||||
{
|
{
|
||||||
if ([self timeIntervalSinceReferenceDate] >
|
if (seconds_since_ref > [otherDate timeIntervalSinceReferenceDate])
|
||||||
[otherDate timeIntervalSinceReferenceDate])
|
|
||||||
return NSOrderedDescending;
|
return NSOrderedDescending;
|
||||||
|
|
||||||
if ([self timeIntervalSinceReferenceDate] <
|
if (seconds_since_ref < [otherDate timeIntervalSinceReferenceDate])
|
||||||
[otherDate timeIntervalSinceReferenceDate])
|
|
||||||
return NSOrderedAscending;
|
return NSOrderedAscending;
|
||||||
|
|
||||||
return NSOrderedSame;
|
return NSOrderedSame;
|
||||||
|
@ -319,8 +256,7 @@
|
||||||
|
|
||||||
- (NSDate*) earlierDate: (NSDate*)otherDate
|
- (NSDate*) earlierDate: (NSDate*)otherDate
|
||||||
{
|
{
|
||||||
if ([self timeIntervalSinceReferenceDate] >
|
if (seconds_since_ref > [otherDate timeIntervalSinceReferenceDate])
|
||||||
[otherDate timeIntervalSinceReferenceDate])
|
|
||||||
return otherDate;
|
return otherDate;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -328,16 +264,14 @@
|
||||||
- (BOOL) isEqual: (id)other
|
- (BOOL) isEqual: (id)other
|
||||||
{
|
{
|
||||||
if ([other isKindOf: [NSDate class]]
|
if ([other isKindOf: [NSDate class]]
|
||||||
&& 1.0 > ([self timeIntervalSinceReferenceDate] -
|
&& 1.0 > (seconds_since_ref - [other timeIntervalSinceReferenceDate]))
|
||||||
[other timeIntervalSinceReferenceDate]))
|
|
||||||
return YES;
|
return YES;
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDate*) laterDate: (NSDate*)otherDate
|
- (NSDate*) laterDate: (NSDate*)otherDate
|
||||||
{
|
{
|
||||||
if ([self timeIntervalSinceReferenceDate] <
|
if (seconds_since_ref < [otherDate timeIntervalSinceReferenceDate])
|
||||||
[otherDate timeIntervalSinceReferenceDate])
|
|
||||||
return otherDate;
|
return otherDate;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,8 @@ cstream.m \
|
||||||
fref.m \
|
fref.m \
|
||||||
basic.m \
|
basic.m \
|
||||||
release.m \
|
release.m \
|
||||||
nsscanner.m
|
nsscanner.m \
|
||||||
|
nsdate.m
|
||||||
|
|
||||||
tcpport: FORCE
|
tcpport: FORCE
|
||||||
(cd ../src; $(MAKE))
|
(cd ../src; $(MAKE))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue