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:
Andrew McCallum 1996-10-31 17:14:00 +00:00
parent aead21cd6d
commit ed1a7d0ae2
5 changed files with 195 additions and 144 deletions

View file

@ -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>
* src/StdioStream.m (strerror) [!HAS_STRERROR]: New function from

View file

@ -33,7 +33,11 @@ typedef double NSTimeInterval;
@class NSTimeZone;
@class NSTimeZoneDetail;
@interface NSDate : NSObject <NSCopying>
@interface NSDate : NSObject
{
NSTimeInterval seconds_since_ref;
}
// Getting current time
@ -41,13 +45,13 @@ typedef double NSTimeInterval;
// Allocation and initializing
+ (id) allocWithZone: (NSZone*)z;
+ (NSDate*) date;
+ (NSDate*) dateWithTimeIntervalSinceNow: (NSTimeInterval)seconds;
+ (NSDate*) dateWithTimeIntervalSince1970: (NSTimeInterval)seconds;
+ (NSDate*) dateWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds;
+ (NSDate*) distantFuture;
+ (NSDate*) distantPast;
- (id) init;
- (id) initWithString: (NSString*)description;
- (NSDate*) initWithTimeInterval: (NSTimeInterval)secsToBeAdded
sinceDate: (NSDate*)anotherDate;
@ -64,6 +68,7 @@ typedef double NSTimeInterval;
- (NSString*) description;
- (NSString*) descriptionWithCalendarFormat: (NSString*)format
timeZone: (NSTimeZone*)aTimeZone;
- (NSString *) descriptionWithLocale: (NSDictionary *)locale;
// Adding and getting intervals
@ -129,4 +134,88 @@ typedef double NSTimeInterval;
@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 */

View file

@ -357,6 +357,7 @@ NSAssertionHandler.m \
NSAutoreleasePool.m \
NSBitmapCharSet.m \
NSBundle.m \
NSCalendarDate.m \
NSCallBacks.m \
NSCharacterSet.m \
NSCoder.m \

View file

@ -2,6 +2,7 @@
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
Written by: Jeremy Bettis <jeremy@hksys.com>
Rewritten by: Scott Christley <scottc@net-community.com>
Date: March 1995
This file is part of the GNUstep Base Library.
@ -53,71 +54,10 @@
#define DISTANT_PAST (-DISTANT_FUTURE)
/* Concrete 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. */
/* The implementation of 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
+ (NSTimeInterval) timeIntervalSinceReferenceDate
@ -139,17 +79,9 @@
// Allocation and initializing
+ (id) allocWithZone: (NSZone*)z
{
if (self != [NSDate class])
return [super allocWithZone:z];
return [NSConcreteDate allocWithZone:z];
}
+ (NSDate*) date
{
return [[[self alloc] init]
autorelease];
return [[[self alloc] init] autorelease];
}
+ (NSDate*) dateWithTimeIntervalSinceNow: (NSTimeInterval)seconds
@ -158,6 +90,12 @@
autorelease];
}
+ (NSDate *)dateWithTimeIntervalSince1970:(NSTimeInterval)seconds
{
return [[[self alloc] initWithTimeIntervalSinceReferenceDate:
UNIX_REFERENCE_INTERVAL + seconds] autorelease];
}
+ (NSDate*) dateWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds
{
return [[[self alloc] initWithTimeIntervalSinceReferenceDate: seconds]
@ -182,46 +120,41 @@
- (id) init
{
// We have to do this, otherwise the subclasses cannot do [super init];
return [super init];
return [self initWithTimeIntervalSinceReferenceDate:
[[self class] timeIntervalSinceReferenceDate]];
}
- (id) initWithString: (NSString*)description
{
NSTimeInterval theTime = 0;
/* From the doc:
Returns an calendar date object with a date and time value
specified by the international string-representation format:
YYYY-MM-DD HH:MM:SS -HHMM, where -HHMM is a time zone offset in
hours and minutes from Greenwich Mean Time. (Adding the offset to
the specified time yields the equivalent GMT.) An example string
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];
// Easiest to just have NSCalendarDate do the work for us
NSCalendarDate *d = [NSCalendarDate alloc];
[d initWithString: description];
[self initWithTimeIntervalSinceReferenceDate:
[d timeIntervalSinceReferenceDate]];
[d release];
return self;
}
- (NSDate*) initWithTimeInterval: (NSTimeInterval)secsToBeAdded
sinceDate: (NSDate*)anotherDate;
{
// Get the other date's time, add the secs and init thyself
return [self initWithTimeIntervalSinceReferenceDate:
[anotherDate timeIntervalSinceReferenceDate]];
[anotherDate timeIntervalSinceReferenceDate] + 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:
[[self class] timeIntervalSinceReferenceDate] + secsToBeAdded];
}
- (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)secs;
- (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)secs
{
[self subclassResponsibility: _cmd];
return nil;
[super init];
seconds_since_ref = secs;
return self;
}
// Converting to NSCalendar
@ -229,50 +162,59 @@
- (NSCalendarDate *) dateWithCalendarFormat: (NSString*)formatString
timeZone: (NSTimeZone*)timeZone
{
// Not done yet, NSCalendarDate doesn't exist yet!
[self notImplemented: _cmd];
return nil;
NSCalendarDate *d = [NSCalendarDate alloc];
[d initWithTimeIntervalSinceReferenceDate: seconds_since_ref];
[d setCalendarFormat: formatString];
[d setTimeZone: timeZone];
return [d autorelease];
}
// Representing dates
- (NSString*) description
{
/* *********************** only works for >1970 dates */
struct tm *theTime;
NSTimeInterval secs;
time_t unix_secs;
char buf[64];
secs = [self timeIntervalSinceReferenceDate];
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];
// Easiest to just have NSCalendarDate do the work for us
NSString *s;
NSCalendarDate *d = [NSCalendarDate alloc];
[d initWithTimeIntervalSinceReferenceDate: seconds_since_ref];
s = [d description];
[d release];
return s;
}
- (NSString*) descriptionWithCalendarFormat: (NSString*)format
timeZone: (NSTimeZone*)aTimeZone
{
// Not done yet, no NSCalendarDate or NSTimeZone...
[self notImplemented: _cmd];
return nil;
// Easiest to just have NSCalendarDate do the work for us
NSString *s;
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
@ -280,38 +222,33 @@
{
/* xxx We need to check for overflow? */
return [[self class] dateWithTimeIntervalSinceReferenceDate:
[self timeIntervalSinceReferenceDate] + seconds];
seconds_since_ref + seconds];
}
- (NSTimeInterval) timeIntervalSinceDate: (NSDate*)otherDate
{
return [self timeIntervalSinceReferenceDate] -
[otherDate timeIntervalSinceReferenceDate];
return seconds_since_ref - [otherDate timeIntervalSinceReferenceDate];
}
- (NSTimeInterval) timeIntervalSinceNow
{
NSTimeInterval now = [[self class] timeIntervalSinceReferenceDate];
NSTimeInterval me = [self timeIntervalSinceReferenceDate];
return me - now;
return seconds_since_ref - now;
}
- (NSTimeInterval) timeIntervalSinceReferenceDate
{
[self subclassResponsibility: _cmd];
return 0.0;
return seconds_since_ref;
}
// Comparing dates
- (NSComparisonResult) compare: (NSDate*)otherDate
{
if ([self timeIntervalSinceReferenceDate] >
[otherDate timeIntervalSinceReferenceDate])
if (seconds_since_ref > [otherDate timeIntervalSinceReferenceDate])
return NSOrderedDescending;
if ([self timeIntervalSinceReferenceDate] <
[otherDate timeIntervalSinceReferenceDate])
if (seconds_since_ref < [otherDate timeIntervalSinceReferenceDate])
return NSOrderedAscending;
return NSOrderedSame;
@ -319,8 +256,7 @@
- (NSDate*) earlierDate: (NSDate*)otherDate
{
if ([self timeIntervalSinceReferenceDate] >
[otherDate timeIntervalSinceReferenceDate])
if (seconds_since_ref > [otherDate timeIntervalSinceReferenceDate])
return otherDate;
return self;
}
@ -328,16 +264,14 @@
- (BOOL) isEqual: (id)other
{
if ([other isKindOf: [NSDate class]]
&& 1.0 > ([self timeIntervalSinceReferenceDate] -
[other timeIntervalSinceReferenceDate]))
&& 1.0 > (seconds_since_ref - [other timeIntervalSinceReferenceDate]))
return YES;
return NO;
}
- (NSDate*) laterDate: (NSDate*)otherDate
{
if ([self timeIntervalSinceReferenceDate] <
[otherDate timeIntervalSinceReferenceDate])
if (seconds_since_ref < [otherDate timeIntervalSinceReferenceDate])
return otherDate;
return self;
}

View file

@ -96,7 +96,8 @@ cstream.m \
fref.m \
basic.m \
release.m \
nsscanner.m
nsscanner.m \
nsdate.m
tcpport: FORCE
(cd ../src; $(MAKE))