mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
Tweaks to NSDate changes
This commit is contained in:
parent
7a59450341
commit
d0bff27c77
2 changed files with 113 additions and 78 deletions
|
@ -1,3 +1,8 @@
|
|||
2024-11-01 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSDate.m: Fix returing receiver when earlier/later argument
|
||||
is equal to the receiver. Various formatting fixes.
|
||||
|
||||
2024-10-29 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSUndoManager.m: set zero/nil return value when forwarding
|
||||
|
|
|
@ -158,7 +158,9 @@ union DoubleBits {
|
|||
};
|
||||
};
|
||||
|
||||
static __attribute__((always_inline)) uintptr_t compressTimeInterval(NSTimeInterval interval) {
|
||||
static __attribute__((always_inline)) uintptr_t
|
||||
compressTimeInterval(NSTimeInterval interval)
|
||||
{
|
||||
union CompressedDouble c;
|
||||
union DoubleBits db;
|
||||
intptr_t exponent;
|
||||
|
@ -178,7 +180,9 @@ static __attribute__((always_inline)) uintptr_t compressTimeInterval(NSTimeInter
|
|||
return c.data;
|
||||
}
|
||||
|
||||
static __attribute__((always_inline)) NSTimeInterval decompressTimeInterval(uintptr_t compressed) {
|
||||
static __attribute__((always_inline)) NSTimeInterval
|
||||
decompressTimeInterval(uintptr_t compressed)
|
||||
{
|
||||
union CompressedDouble c;
|
||||
union DoubleBits d;
|
||||
intptr_t biased_exponent;
|
||||
|
@ -234,10 +238,13 @@ static BOOL useSmallDate;
|
|||
+ (void) load
|
||||
{
|
||||
useSmallDate = objc_registerSmallObjectClass_np(self, SMALL_DATE_MASK);
|
||||
// If this fails, someone else has already registered a small object class for this slot.
|
||||
/* If this fails, someone else has already registered
|
||||
* a small object class for this slot.
|
||||
*/
|
||||
if (unlikely(useSmallDate == NO))
|
||||
{
|
||||
[NSException raise: NSInternalInconsistencyException format: @"Failed to register GSSmallDate small object class"];
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Failed to register GSSmallDate small object class"];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -349,6 +356,7 @@ static BOOL useSmallDate;
|
|||
- (id) initWithCoder: (NSCoder*)coder
|
||||
{
|
||||
double secondsSinceRef;
|
||||
|
||||
if ([coder allowsKeyedCoding])
|
||||
{
|
||||
secondsSinceRef = [coder decodeDoubleForKey: @"NS.time"];
|
||||
|
@ -396,7 +404,9 @@ static BOOL useSmallDate;
|
|||
if (IS_CONCRETE_CLASS(otherDate))
|
||||
{
|
||||
otherTime = GET_INTERVAL(otherDate);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
otherTime = [otherDate timeIntervalSinceReferenceDate];
|
||||
}
|
||||
|
||||
|
@ -424,10 +434,13 @@ static BOOL useSmallDate;
|
|||
if (IS_CONCRETE_CLASS(other))
|
||||
{
|
||||
otherTime = GET_INTERVAL(other);
|
||||
} else if ([other isKindOfClass: abstractClass])
|
||||
}
|
||||
else if ([other isKindOfClass: abstractClass])
|
||||
{
|
||||
otherTime = [other timeIntervalSinceReferenceDate];
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
@ -454,12 +467,16 @@ static BOOL useSmallDate;
|
|||
if (IS_CONCRETE_CLASS(otherDate))
|
||||
{
|
||||
otherTime = GET_INTERVAL(otherDate);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
otherTime = [otherDate timeIntervalSinceReferenceDate];
|
||||
}
|
||||
|
||||
// If the receiver and anotherDate represent the same date, returns the receiver.
|
||||
if (selfTime <= otherTime)
|
||||
/* If the receiver and anotherDate represent the same date,
|
||||
* returns the receiver.
|
||||
*/
|
||||
if (selfTime < otherTime)
|
||||
{
|
||||
return otherDate;
|
||||
}
|
||||
|
@ -482,12 +499,16 @@ static BOOL useSmallDate;
|
|||
if (IS_CONCRETE_CLASS(otherDate))
|
||||
{
|
||||
otherTime = GET_INTERVAL(otherDate);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
otherTime = [otherDate timeIntervalSinceReferenceDate];
|
||||
}
|
||||
|
||||
// If the receiver and anotherDate represent the same date, returns the receiver.
|
||||
if (selfTime >= otherTime)
|
||||
/* If the receiver and anotherDate represent the same date,
|
||||
* returns the receiver.
|
||||
*/
|
||||
if (selfTime > otherTime)
|
||||
{
|
||||
return otherDate;
|
||||
}
|
||||
|
@ -498,9 +519,10 @@ static BOOL useSmallDate;
|
|||
- (void) encodeWithCoder: (NSCoder*)coder
|
||||
{
|
||||
double time = GET_INTERVAL(self);
|
||||
|
||||
if ([coder allowsKeyedCoding])
|
||||
{
|
||||
[coder encodeDouble:time forKey:@"NS.time"];
|
||||
[coder encodeDouble: time forKey:@"NS.time"];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -519,6 +541,7 @@ static BOOL useSmallDate;
|
|||
- (NSTimeInterval) timeIntervalSinceDate: (NSDate*)otherDate
|
||||
{
|
||||
double otherTime;
|
||||
|
||||
if (unlikely(otherDate == nil))
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
|
@ -528,7 +551,9 @@ static BOOL useSmallDate;
|
|||
if (IS_CONCRETE_CLASS(otherDate))
|
||||
{
|
||||
otherTime = GET_INTERVAL(otherDate);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
otherTime = [otherDate timeIntervalSinceReferenceDate];
|
||||
}
|
||||
|
||||
|
@ -700,7 +725,9 @@ otherTime(NSDate* other)
|
|||
if (self == abstractClass)
|
||||
{
|
||||
#if USE_SMALL_DATE
|
||||
return [DATE_CONCRETE_CLASS_NAME alloc]; // alloc is overridden to return a small object
|
||||
/* alloc is overridden to return a small object
|
||||
*/
|
||||
return [DATE_CONCRETE_CLASS_NAME alloc];
|
||||
#else
|
||||
return NSAllocateObject(concreteClass, 0, NSDefaultMallocZone());
|
||||
#endif
|
||||
|
@ -713,7 +740,9 @@ otherTime(NSDate* other)
|
|||
if (self == abstractClass)
|
||||
{
|
||||
#if USE_SMALL_DATE
|
||||
return [DATE_CONCRETE_CLASS_NAME alloc]; // alloc is overridden to return a small object
|
||||
/* alloc is overridden to return a small object
|
||||
*/
|
||||
return [DATE_CONCRETE_CLASS_NAME alloc];
|
||||
#else
|
||||
return NSAllocateObject(concreteClass, 0, z);
|
||||
#endif
|
||||
|
@ -1784,6 +1813,7 @@ otherTime(NSDate* other)
|
|||
- (NSDate*) laterDate: (NSDate*)otherDate
|
||||
{
|
||||
double selfTime;
|
||||
|
||||
if (otherDate == nil)
|
||||
{
|
||||
return nil;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue