#import "NSDate+GanttAdditions.h"

@implementation NSDate (GanttAdditions)

- (NSDate *)dateByRoundingToNearest:(NSTimeInterval)seconds
{
    NSTimeInterval intv = [self timeIntervalSince1970];
    NSTimeInterval remainder = fmod(intv, seconds);
    if (remainder > seconds/2.0)
        intv += (seconds - remainder);
    else
        intv -= remainder;
    return [NSDate dateWithTimeIntervalSince1970:intv];
}

- (NSDate *)max:(NSDate *)aDate
{
    if ([self compare:aDate] == NSOrderedDescending)
        return self;
    return aDate;
}

- (NSDate *)min:(NSDate *)aDate
{
    if ([self compare:aDate] == NSOrderedAscending)
        return self;
    return aDate;
}

#if GNUSTEP_BASE_LIBRARY || UNIVERSAL_INTERFACES_VERSION <= 0x0400

- (NSDate *)dateByAddingTimeInterval:(NSTimeInterval)seconds
{
    return [NSDate dateWithTimeIntervalSinceReferenceDate:seconds+[self timeIntervalSinceReferenceDate]];
}

#endif

@end
