mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
Implementation of most functions.
This commit is contained in:
parent
49e2e14dd8
commit
58a7201645
2 changed files with 76 additions and 1 deletions
|
@ -36,7 +36,12 @@ extern "C" {
|
||||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_12, GS_API_LATEST)
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_12, GS_API_LATEST)
|
||||||
|
|
||||||
@interface NSDateInterval : NSObject <NSCoding, NSCopying>
|
@interface NSDateInterval : NSObject <NSCoding, NSCopying>
|
||||||
|
{
|
||||||
|
NSTimeInterval _duration;
|
||||||
|
NSDate *_startDate;
|
||||||
|
NSDate *_endDate;
|
||||||
|
}
|
||||||
|
|
||||||
// Init
|
// Init
|
||||||
- (instancetype) init;
|
- (instancetype) init;
|
||||||
|
|
||||||
|
|
|
@ -24,26 +24,51 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Foundation/NSDateInterval.h>
|
#include <Foundation/NSDateInterval.h>
|
||||||
|
#include <Foundation/NSDate.h>
|
||||||
|
|
||||||
@implementation NSDateInterval
|
@implementation NSDateInterval
|
||||||
|
|
||||||
// Init
|
// Init
|
||||||
- (instancetype)init
|
- (instancetype)init
|
||||||
{
|
{
|
||||||
|
self = [super init];
|
||||||
|
if(self != nil)
|
||||||
|
{
|
||||||
|
_startDate = nil;
|
||||||
|
_duration = 0.0;
|
||||||
|
}
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithStartDate:(NSDate *)startDate
|
- (instancetype)initWithStartDate:(NSDate *)startDate
|
||||||
duration:(NSTimeInterval)duration
|
duration:(NSTimeInterval)duration
|
||||||
{
|
{
|
||||||
|
self = [super init];
|
||||||
|
if(self != nil)
|
||||||
|
{
|
||||||
|
ASSIGNCOPY(_startDate, startDate);
|
||||||
|
ASSIGNCOPY(_endDate, [startDate dateByAddingTimeInterval: duration]);
|
||||||
|
_duration = duration;
|
||||||
|
}
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithStartDate:(NSDate *)startDate
|
- (instancetype)initWithStartDate:(NSDate *)startDate
|
||||||
endDate:(NSDate *)endDate
|
endDate:(NSDate *)endDate
|
||||||
{
|
{
|
||||||
|
self = [super init];
|
||||||
|
if(self != nil)
|
||||||
|
{
|
||||||
|
ASSIGNCOPY(_startDate, startDate);
|
||||||
|
ASSIGNCOPY(_endDate, endDate);
|
||||||
|
_duration = [endDate timeIntervalSinceDate: startDate];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype) initWithCoder: (NSCoder *)coder
|
- (instancetype) initWithCoder: (NSCoder *)coder
|
||||||
{
|
{
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) encodeWithCoder: (NSCoder *)coder
|
- (void) encodeWithCoder: (NSCoder *)coder
|
||||||
|
@ -52,54 +77,99 @@
|
||||||
|
|
||||||
- (id) copyWithZone: (NSZone *)zone
|
- (id) copyWithZone: (NSZone *)zone
|
||||||
{
|
{
|
||||||
|
return [[[self class] allocWithZone: zone]
|
||||||
|
initWithStartDate: _startDate
|
||||||
|
duration: _duration];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) dealloc
|
||||||
|
{
|
||||||
|
RELEASE(_startDate);
|
||||||
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Access
|
// Access
|
||||||
- (NSDate *) startDate
|
- (NSDate *) startDate
|
||||||
{
|
{
|
||||||
|
return _startDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setStartDate: (NSDate *)startDate
|
- (void) setStartDate: (NSDate *)startDate
|
||||||
{
|
{
|
||||||
|
ASSIGNCOPY(_startDate, startDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDate *) endDate
|
- (NSDate *) endDate
|
||||||
{
|
{
|
||||||
|
return _endDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setEndDate: (NSDate *)endDate
|
- (void) setEndDate: (NSDate *)endDate
|
||||||
{
|
{
|
||||||
|
ASSIGNCOPY(_endDate, endDate);
|
||||||
|
_duration = [endDate timeIntervalSinceDate: _startDate];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSTimeInterval) duration
|
- (NSTimeInterval) duration
|
||||||
{
|
{
|
||||||
|
return _duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setDuration: (NSTimeInterval)duration
|
- (void) setDuration: (NSTimeInterval)duration
|
||||||
{
|
{
|
||||||
|
NSDate *newEndDate = [_startDate dateByAddingTimeInterval: duration];
|
||||||
|
_duration = duration;
|
||||||
|
[self setEndDate: newEndDate];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare
|
// Compare
|
||||||
- (NSComparisonResult) compare: (NSDateInterval *)dateInterval
|
- (NSComparisonResult) compare: (NSDateInterval *)dateInterval
|
||||||
{
|
{
|
||||||
|
// NSOrderedAscending
|
||||||
|
if([_startDate isEqualToDate: [dateInterval startDate]] &&
|
||||||
|
_duration < [dateInterval duration])
|
||||||
|
return NSOrderedAscending;
|
||||||
|
if([_startDate compare: [dateInterval startDate]] == NSOrderedAscending)
|
||||||
|
return NSOrderedAscending;
|
||||||
|
|
||||||
|
// NSOrderedSame
|
||||||
|
if([self isEqualToDateInterval: dateInterval])
|
||||||
|
return NSOrderedSame;
|
||||||
|
|
||||||
|
if([_startDate isEqualToDate: [dateInterval startDate]] &&
|
||||||
|
_duration > [dateInterval duration])
|
||||||
|
return NSOrderedDescending;
|
||||||
|
if([_startDate compare: [dateInterval startDate]] == NSOrderedDescending)
|
||||||
|
return NSOrderedDescending;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) isEqualToDateInterval: (NSDateInterval *)dateInterval
|
- (BOOL) isEqualToDateInterval: (NSDateInterval *)dateInterval
|
||||||
{
|
{
|
||||||
|
return ([_startDate isEqualToDate: [dateInterval startDate]] &&
|
||||||
|
_duration == [dateInterval duration]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine
|
// Determine
|
||||||
- (BOOL) intersectsDateInterval: (NSDateInterval *)dateInterval
|
- (BOOL) intersectsDateInterval: (NSDateInterval *)dateInterval
|
||||||
{
|
{
|
||||||
|
return [self intersectionWithDateInterval: dateInterval] != nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDateInterval *) intersectionWithDateInterval: (NSDateInterval *)dateInterval
|
- (NSDateInterval *) intersectionWithDateInterval: (NSDateInterval *)dateInterval
|
||||||
{
|
{
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Contain
|
// Contain
|
||||||
- (BOOL) containsDate: (NSDate *)date
|
- (BOOL) containsDate: (NSDate *)date
|
||||||
{
|
{
|
||||||
|
return ([_startDate compare: date] == NSOrderedSame ||
|
||||||
|
[_endDate compare: date] == NSOrderedSame ||
|
||||||
|
([_startDate compare: date] == NSOrderedAscending &&
|
||||||
|
[_endDate compare: date] == NSOrderedDescending));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue