mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Fix to return nil initialising from invalid string.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@9964 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
9896f623a1
commit
3a4145f95b
2 changed files with 38 additions and 11 deletions
|
@ -1,3 +1,10 @@
|
|||
2001-05-18 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSDate.m: check for nil dates in some init methods so
|
||||
we return nil on initialisation failure rather than raising an
|
||||
exception. I believe that init failures should deallocate their
|
||||
objects and return nil.
|
||||
|
||||
2001-05-14 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Headers/gnustep/base/objc-gnu2next.h: Add apply_t prototype.
|
||||
|
|
|
@ -831,8 +831,15 @@ GSTimeNow()
|
|||
NSLog(@"Date resulted in wrong day of week.\n");
|
||||
return nil;
|
||||
}
|
||||
return [self dateWithTimeIntervalSinceReferenceDate:
|
||||
otherTime(theDate)];
|
||||
if (theDate == nil)
|
||||
{
|
||||
return theDate;
|
||||
}
|
||||
else
|
||||
{
|
||||
return [self dateWithTimeIntervalSinceReferenceDate:
|
||||
otherTime(theDate)];
|
||||
}
|
||||
}
|
||||
|
||||
+ (id) dateWithString: (NSString*)description
|
||||
|
@ -931,17 +938,31 @@ GSTimeNow()
|
|||
NSCalendarDate *d = [calendarClass alloc];
|
||||
|
||||
d = [d initWithString: description];
|
||||
self = [self initWithTimeIntervalSinceReferenceDate: otherTime(d)];
|
||||
RELEASE(d);
|
||||
return self;
|
||||
if (d == nil)
|
||||
{
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
self = [self initWithTimeIntervalSinceReferenceDate: otherTime(d)];
|
||||
RELEASE(d);
|
||||
return self;
|
||||
}
|
||||
}
|
||||
|
||||
- (id) initWithTimeInterval: (NSTimeInterval)secsToBeAdded
|
||||
sinceDate: (NSDate*)anotherDate;
|
||||
{
|
||||
if (anotherDate == nil)
|
||||
{
|
||||
NSLog(@"initWithTimeInterval:sinceDate: given nil date");
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
// Get the other date's time, add the secs and init thyself
|
||||
return [self initWithTimeIntervalSinceReferenceDate:
|
||||
otherTime(anotherDate) + secsToBeAdded];
|
||||
otherTime(anotherDate) + secsToBeAdded];
|
||||
}
|
||||
|
||||
- (id) initWithTimeIntervalSinceNow: (NSTimeInterval)secsToBeAdded;
|
||||
|
@ -1027,7 +1048,7 @@ GSTimeNow()
|
|||
{
|
||||
/* xxx We need to check for overflow? */
|
||||
return [[self class] dateWithTimeIntervalSinceReferenceDate:
|
||||
otherTime(self) + seconds];
|
||||
otherTime(self) + seconds];
|
||||
}
|
||||
|
||||
- (NSTimeInterval) timeIntervalSince1970
|
||||
|
@ -1097,7 +1118,7 @@ GSTimeNow()
|
|||
if (other == nil)
|
||||
return NO;
|
||||
if ([other isKindOf: abstractClass]
|
||||
&& 1.0 > ABS(otherTime(self) - otherTime(other)))
|
||||
&& 1.0 > ABS(otherTime(self) - otherTime(other)))
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
@ -1118,8 +1139,7 @@ GSTimeNow()
|
|||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"nil argument for laterDate:"];
|
||||
}
|
||||
if (otherTime(self)
|
||||
< otherTime(otherDate))
|
||||
if (otherTime(self) < otherTime(otherDate))
|
||||
return otherDate;
|
||||
return self;
|
||||
}
|
||||
|
@ -1224,7 +1244,7 @@ GSTimeNow()
|
|||
if (other == nil)
|
||||
return NO;
|
||||
if ([other isKindOfClass: abstractClass]
|
||||
&& 1.0 > ABS(_seconds_since_ref - otherTime(other)))
|
||||
&& 1.0 > ABS(_seconds_since_ref - otherTime(other)))
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue