1995-03-31 15:39:12 +00:00
|
|
|
|
/* Implementation for NSDate for GNUStep
|
1997-05-03 20:21:48 +00:00
|
|
|
|
Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
1995-03-31 15:39:12 +00:00
|
|
|
|
|
1995-04-13 21:57:29 +00:00
|
|
|
|
Written by: Jeremy Bettis <jeremy@hksys.com>
|
1996-10-31 17:14:00 +00:00
|
|
|
|
Rewritten by: Scott Christley <scottc@net-community.com>
|
1995-04-13 21:57:29 +00:00
|
|
|
|
Date: March 1995
|
|
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
|
This file is part of the GNUstep Base Library.
|
1995-03-31 15:39:12 +00:00
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
|
License along with this library; if not, write to the Free
|
|
|
|
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
1995-04-13 21:57:29 +00:00
|
|
|
|
1995-03-31 02:41:00 -0600 Jeremy Bettis <jeremy@hksys.com>
|
|
|
|
|
Release the first draft of NSDate.
|
|
|
|
|
Three methods not implemented, and NSCalendarDate/NSTimeZone don't exist.
|
1995-03-31 15:39:12 +00:00
|
|
|
|
*/
|
|
|
|
|
|
1997-11-06 00:51:23 +00:00
|
|
|
|
#include <config.h>
|
1998-11-30 10:04:24 +00:00
|
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
|
#include <Foundation/NSDictionary.h>
|
1995-04-17 21:13:20 +00:00
|
|
|
|
#include <Foundation/NSDate.h>
|
1995-08-02 15:21:54 +00:00
|
|
|
|
#include <Foundation/NSString.h>
|
1997-09-01 21:59:51 +00:00
|
|
|
|
#include <Foundation/NSCoder.h>
|
1998-11-19 21:26:27 +00:00
|
|
|
|
#include <Foundation/NSException.h>
|
1998-11-30 10:04:24 +00:00
|
|
|
|
#include <Foundation/NSUserDefaults.h>
|
1996-07-15 18:41:44 +00:00
|
|
|
|
#ifndef __WIN32__
|
1996-03-12 14:48:07 +00:00
|
|
|
|
#include <time.h>
|
1996-07-15 18:41:44 +00:00
|
|
|
|
#endif /* !__WIN32__ */
|
1996-03-12 14:48:07 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
1996-07-15 18:41:44 +00:00
|
|
|
|
#ifndef __WIN32__
|
1995-03-31 15:39:12 +00:00
|
|
|
|
#include <sys/time.h>
|
1996-07-15 18:41:44 +00:00
|
|
|
|
#endif /* !__WIN32__ */
|
1996-02-13 15:43:30 +00:00
|
|
|
|
|
1996-03-12 14:48:07 +00:00
|
|
|
|
/* The number of seconds between 1/1/2001 and 1/1/1970 = -978307200. */
|
|
|
|
|
/* This number comes from:
|
|
|
|
|
-(((31 years * 365 days) + 8 days for leap years) =total number of days
|
|
|
|
|
* 24 hours
|
|
|
|
|
* 60 minutes
|
|
|
|
|
* 60 seconds)
|
|
|
|
|
This ignores leap-seconds. */
|
|
|
|
|
#define UNIX_REFERENCE_INTERVAL -978307200.0
|
|
|
|
|
|
|
|
|
|
/* I hope 100,000 years is distant enough. */
|
|
|
|
|
#define DISTANT_YEARS 100000.0
|
|
|
|
|
#define DISTANT_FUTURE (DISTANT_YEARS * 365.0 * 24 * 60 * 60)
|
|
|
|
|
#define DISTANT_PAST (-DISTANT_FUTURE)
|
|
|
|
|
|
|
|
|
|
|
1996-10-31 17:14:00 +00:00
|
|
|
|
/* The implementation of NSDate. */
|
1995-04-13 21:57:29 +00:00
|
|
|
|
|
1995-03-31 15:39:12 +00:00
|
|
|
|
@implementation NSDate
|
|
|
|
|
|
1998-11-30 10:04:24 +00:00
|
|
|
|
+ (void) initialize
|
|
|
|
|
{
|
|
|
|
|
if (self == [NSDate class])
|
|
|
|
|
{
|
|
|
|
|
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
NSDictionary *registrationDefaults;
|
|
|
|
|
NSArray *ampm;
|
|
|
|
|
NSArray *long_day;
|
|
|
|
|
NSArray *long_month;
|
|
|
|
|
NSArray *short_day;
|
|
|
|
|
NSArray *short_month;
|
|
|
|
|
|
|
|
|
|
ampm = [NSArray arrayWithObjects: @"AM", @"PM", nil];
|
|
|
|
|
short_month = [NSArray arrayWithObjects:
|
|
|
|
|
@"Jan",
|
|
|
|
|
@"Feb",
|
|
|
|
|
@"Mar",
|
|
|
|
|
@"Apr",
|
|
|
|
|
@"May",
|
|
|
|
|
@"Jun",
|
|
|
|
|
@"Jul",
|
|
|
|
|
@"Aug",
|
|
|
|
|
@"Sep",
|
|
|
|
|
@"Oct",
|
|
|
|
|
@"Nov",
|
|
|
|
|
@"Dec",
|
|
|
|
|
nil];
|
|
|
|
|
long_month = [NSArray arrayWithObjects:
|
|
|
|
|
@"January",
|
|
|
|
|
@"February",
|
|
|
|
|
@"March",
|
|
|
|
|
@"April",
|
|
|
|
|
@"May",
|
|
|
|
|
@"June",
|
|
|
|
|
@"July",
|
|
|
|
|
@"August",
|
|
|
|
|
@"September",
|
|
|
|
|
@"October",
|
|
|
|
|
@"November",
|
|
|
|
|
@"December",
|
|
|
|
|
nil];
|
|
|
|
|
short_day = [NSArray arrayWithObjects:
|
|
|
|
|
@"Sun",
|
|
|
|
|
@"Mon",
|
|
|
|
|
@"Tue",
|
|
|
|
|
@"Wed",
|
|
|
|
|
@"Thu",
|
|
|
|
|
@"Fri",
|
|
|
|
|
@"Sat",
|
|
|
|
|
nil];
|
|
|
|
|
long_day = [NSArray arrayWithObjects:
|
|
|
|
|
@"Sunday",
|
|
|
|
|
@"Monday",
|
|
|
|
|
@"Tuesday",
|
|
|
|
|
@"Wednesday",
|
|
|
|
|
@"Thursday",
|
|
|
|
|
@"Friday",
|
|
|
|
|
@"Saturday",
|
|
|
|
|
nil];
|
|
|
|
|
registrationDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
|
ampm, NSAMPMDesignation,
|
|
|
|
|
long_month, NSMonthNameArray,
|
|
|
|
|
long_day, NSWeekDayNameArray,
|
|
|
|
|
short_month, NSShortMonthNameArray,
|
|
|
|
|
short_day, NSShortWeekDayNameArray,
|
|
|
|
|
nil];
|
|
|
|
|
[defs registerDefaults: registrationDefaults];
|
|
|
|
|
}
|
|
|
|
|
}
|
1995-03-31 15:39:12 +00:00
|
|
|
|
// Getting current time
|
|
|
|
|
|
|
|
|
|
+ (NSTimeInterval) timeIntervalSinceReferenceDate
|
|
|
|
|
{
|
1997-09-13 17:52:31 +00:00
|
|
|
|
#if !defined(__WIN32__) && !defined(_WIN32)
|
1996-03-12 14:48:07 +00:00
|
|
|
|
volatile NSTimeInterval interval;
|
|
|
|
|
struct timeval tp;
|
|
|
|
|
|
|
|
|
|
interval = UNIX_REFERENCE_INTERVAL;
|
1997-05-03 18:13:17 +00:00
|
|
|
|
gettimeofday (&tp, NULL);
|
1996-03-12 14:48:07 +00:00
|
|
|
|
interval += tp.tv_sec;
|
|
|
|
|
interval += (double)tp.tv_usec / 1000000.0;
|
|
|
|
|
|
|
|
|
|
/* There seems to be a problem with bad double arithmetic... */
|
1998-11-19 21:26:27 +00:00
|
|
|
|
NSAssert(interval < 0, NSInternalInconsistencyException);
|
1996-03-12 14:48:07 +00:00
|
|
|
|
|
|
|
|
|
return interval;
|
1996-10-31 17:22:04 +00:00
|
|
|
|
#else
|
|
|
|
|
TIME_ZONE_INFORMATION sys_time_zone;
|
|
|
|
|
SYSTEMTIME sys_time;
|
|
|
|
|
NSCalendarDate *d;
|
|
|
|
|
NSTimeInterval t;
|
|
|
|
|
|
|
|
|
|
// Get the time zone information
|
|
|
|
|
GetTimeZoneInformation(&sys_time_zone);
|
|
|
|
|
|
|
|
|
|
// Get the system time
|
|
|
|
|
GetLocalTime(&sys_time);
|
|
|
|
|
|
|
|
|
|
// Use an NSCalendar object to make it easier
|
|
|
|
|
d = [NSCalendarDate alloc];
|
|
|
|
|
[d initWithYear: sys_time.wYear
|
|
|
|
|
month: sys_time.wMonth
|
|
|
|
|
day: sys_time.wDay
|
|
|
|
|
hour: sys_time.wHour
|
|
|
|
|
minute: sys_time.wMinute
|
|
|
|
|
second: sys_time.wSecond
|
|
|
|
|
timeZone: [NSTimeZone defaultTimeZone]];
|
|
|
|
|
t = [d timeIntervalSinceReferenceDate];
|
|
|
|
|
[d release];
|
|
|
|
|
return t;
|
|
|
|
|
#endif /* __WIN32__ */
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Allocation and initializing
|
|
|
|
|
|
1998-01-21 14:56:24 +00:00
|
|
|
|
+ (id) date
|
1995-03-31 15:39:12 +00:00
|
|
|
|
{
|
1996-10-31 17:14:00 +00:00
|
|
|
|
return [[[self alloc] init] autorelease];
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-01-21 14:56:24 +00:00
|
|
|
|
+ (id) dateWithString: (NSString*)description
|
1995-03-31 15:39:12 +00:00
|
|
|
|
{
|
1998-01-21 14:56:24 +00:00
|
|
|
|
return [[[self alloc] initWithString: description] autorelease];
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-01-21 14:56:24 +00:00
|
|
|
|
+ (id) dateWithTimeIntervalSinceNow: (NSTimeInterval)seconds
|
|
|
|
|
{
|
|
|
|
|
return [[[self alloc] initWithTimeIntervalSinceNow: seconds] autorelease];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (id)dateWithTimeIntervalSince1970:(NSTimeInterval)seconds
|
1996-10-31 17:14:00 +00:00
|
|
|
|
{
|
|
|
|
|
return [[[self alloc] initWithTimeIntervalSinceReferenceDate:
|
|
|
|
|
UNIX_REFERENCE_INTERVAL + seconds] autorelease];
|
|
|
|
|
}
|
|
|
|
|
|
1998-01-21 14:56:24 +00:00
|
|
|
|
+ (id) dateWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds
|
1995-03-31 15:39:12 +00:00
|
|
|
|
{
|
1996-03-12 14:48:07 +00:00
|
|
|
|
return [[[self alloc] initWithTimeIntervalSinceReferenceDate: seconds]
|
|
|
|
|
autorelease];
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-01-21 14:56:24 +00:00
|
|
|
|
+ (id) distantFuture
|
1995-03-31 15:39:12 +00:00
|
|
|
|
{
|
1996-03-18 18:31:37 +00:00
|
|
|
|
static id df = nil;
|
|
|
|
|
if (!df)
|
|
|
|
|
df = [[self alloc] initWithTimeIntervalSinceReferenceDate: DISTANT_FUTURE];
|
|
|
|
|
return df;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-01-21 14:56:24 +00:00
|
|
|
|
+ (id) distantPast
|
1995-03-31 15:39:12 +00:00
|
|
|
|
{
|
1996-03-18 18:31:37 +00:00
|
|
|
|
static id dp = nil;
|
|
|
|
|
if (!dp)
|
|
|
|
|
dp = [[self alloc] initWithTimeIntervalSinceReferenceDate: DISTANT_PAST];
|
|
|
|
|
return dp;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (id) copyWithZone:(NSZone*)zone
|
|
|
|
|
{
|
|
|
|
|
if (NSShouldRetainWithZone(self, zone))
|
|
|
|
|
return [self retain];
|
|
|
|
|
else
|
1998-07-28 17:51:55 +00:00
|
|
|
|
return NSCopyObject(self, 0, zone);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (Class) classForConnectedCoder: aRmc
|
|
|
|
|
{
|
|
|
|
|
/* Make sure that Connection's always send us bycopy,
|
|
|
|
|
i.e. as our own class, not a Proxy class. */
|
|
|
|
|
return [self class];
|
|
|
|
|
}
|
|
|
|
|
|
1997-09-29 14:39:53 +00:00
|
|
|
|
- (Class) classForPortCoder
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
|
|
|
|
return [self class];
|
|
|
|
|
}
|
|
|
|
|
- replacementObjectForPortCoder: aRmc
|
|
|
|
|
{
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) encodeWithCoder:(NSCoder*)coder
|
|
|
|
|
{
|
|
|
|
|
[super encodeWithCoder:coder];
|
1998-10-20 15:40:25 +00:00
|
|
|
|
[coder encodeValueOfObjCType:@encode(NSTimeInterval) at:&seconds_since_ref];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithCoder:(NSCoder*)coder
|
|
|
|
|
{
|
|
|
|
|
self = [super initWithCoder:coder];
|
1998-10-20 15:40:25 +00:00
|
|
|
|
[coder decodeValueOfObjCType:@encode(NSTimeInterval) at:&seconds_since_ref];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
1995-03-31 15:39:12 +00:00
|
|
|
|
- (id) init
|
|
|
|
|
{
|
1996-10-31 17:14:00 +00:00
|
|
|
|
return [self initWithTimeIntervalSinceReferenceDate:
|
|
|
|
|
[[self class] timeIntervalSinceReferenceDate]];
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-04-13 21:57:29 +00:00
|
|
|
|
- (id) initWithString: (NSString*)description
|
1995-03-31 15:39:12 +00:00
|
|
|
|
{
|
1996-10-31 17:14:00 +00:00
|
|
|
|
// 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;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-01-21 14:56:24 +00:00
|
|
|
|
- (id) initWithTimeInterval: (NSTimeInterval)secsToBeAdded
|
1995-04-13 21:57:29 +00:00
|
|
|
|
sinceDate: (NSDate*)anotherDate;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
{
|
1996-10-31 17:14:00 +00:00
|
|
|
|
// Get the other date's time, add the secs and init thyself
|
1995-04-13 21:57:29 +00:00
|
|
|
|
return [self initWithTimeIntervalSinceReferenceDate:
|
1996-10-31 17:14:00 +00:00
|
|
|
|
[anotherDate timeIntervalSinceReferenceDate] + secsToBeAdded];
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-01-21 14:56:24 +00:00
|
|
|
|
- (id) initWithTimeIntervalSinceNow: (NSTimeInterval)secsToBeAdded;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
{
|
1996-10-31 17:14:00 +00:00
|
|
|
|
// Get the current time, add the secs and init thyself
|
1995-04-13 21:57:29 +00:00
|
|
|
|
return [self initWithTimeIntervalSinceReferenceDate:
|
|
|
|
|
[[self class] timeIntervalSinceReferenceDate] + secsToBeAdded];
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-01-21 14:56:24 +00:00
|
|
|
|
- (id)initWithTimeIntervalSince1970:(NSTimeInterval)seconds
|
1997-03-03 20:07:35 +00:00
|
|
|
|
{
|
|
|
|
|
return [self initWithTimeIntervalSinceReferenceDate:
|
|
|
|
|
UNIX_REFERENCE_INTERVAL + seconds];
|
|
|
|
|
}
|
|
|
|
|
|
1996-10-31 17:14:00 +00:00
|
|
|
|
- (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)secs
|
1995-03-31 15:39:12 +00:00
|
|
|
|
{
|
1996-10-31 17:14:00 +00:00
|
|
|
|
[super init];
|
|
|
|
|
seconds_since_ref = secs;
|
|
|
|
|
return self;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Converting to NSCalendar
|
1995-08-08 15:46:04 +00:00
|
|
|
|
|
1995-04-13 21:57:29 +00:00
|
|
|
|
- (NSCalendarDate *) dateWithCalendarFormat: (NSString*)formatString
|
|
|
|
|
timeZone: (NSTimeZone*)timeZone
|
1995-03-31 15:39:12 +00:00
|
|
|
|
{
|
1996-10-31 17:14:00 +00:00
|
|
|
|
NSCalendarDate *d = [NSCalendarDate alloc];
|
|
|
|
|
[d initWithTimeIntervalSinceReferenceDate: seconds_since_ref];
|
|
|
|
|
[d setCalendarFormat: formatString];
|
|
|
|
|
[d setTimeZone: timeZone];
|
|
|
|
|
return [d autorelease];
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
1995-08-08 15:46:04 +00:00
|
|
|
|
|
1995-03-31 15:39:12 +00:00
|
|
|
|
// Representing dates
|
|
|
|
|
|
|
|
|
|
- (NSString*) description
|
|
|
|
|
{
|
1996-10-31 17:14:00 +00:00
|
|
|
|
// 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;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
1995-08-08 15:46:04 +00:00
|
|
|
|
|
1995-04-13 21:57:29 +00:00
|
|
|
|
- (NSString*) descriptionWithCalendarFormat: (NSString*)format
|
|
|
|
|
timeZone: (NSTimeZone*)aTimeZone
|
1998-11-30 10:04:24 +00:00
|
|
|
|
locale: (NSDictionary*)l
|
1995-03-31 15:39:12 +00:00
|
|
|
|
{
|
1996-10-31 17:14:00 +00:00
|
|
|
|
// Easiest to just have NSCalendarDate do the work for us
|
|
|
|
|
NSString *s;
|
|
|
|
|
NSCalendarDate *d = [NSCalendarDate alloc];
|
1998-11-30 10:04:24 +00:00
|
|
|
|
id f;
|
1996-10-31 17:14:00 +00:00
|
|
|
|
|
|
|
|
|
[d initWithTimeIntervalSinceReferenceDate: seconds_since_ref];
|
|
|
|
|
if (!format)
|
|
|
|
|
f = [d calendarFormat];
|
|
|
|
|
else
|
|
|
|
|
f = format;
|
1998-11-30 10:04:24 +00:00
|
|
|
|
if (aTimeZone)
|
|
|
|
|
[d setTimeZone: aTimeZone];
|
1996-10-31 17:14:00 +00:00
|
|
|
|
|
1998-11-30 10:04:24 +00:00
|
|
|
|
s = [d descriptionWithCalendarFormat: f locale: l];
|
1996-10-31 17:14:00 +00:00
|
|
|
|
[d release];
|
|
|
|
|
return s;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
1995-08-08 15:46:04 +00:00
|
|
|
|
|
1996-10-31 17:14:00 +00:00
|
|
|
|
- (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;
|
|
|
|
|
}
|
1995-03-31 15:39:12 +00:00
|
|
|
|
|
|
|
|
|
// Adding and getting intervals
|
|
|
|
|
|
1998-01-21 14:56:24 +00:00
|
|
|
|
- (id) addTimeInterval: (NSTimeInterval)seconds
|
1995-03-31 15:39:12 +00:00
|
|
|
|
{
|
1996-03-12 14:48:07 +00:00
|
|
|
|
/* xxx We need to check for overflow? */
|
1995-08-02 15:21:54 +00:00
|
|
|
|
return [[self class] dateWithTimeIntervalSinceReferenceDate:
|
1996-10-31 17:14:00 +00:00
|
|
|
|
seconds_since_ref + seconds];
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-03-03 20:07:35 +00:00
|
|
|
|
- (NSTimeInterval) timeIntervalSince1970
|
|
|
|
|
{
|
|
|
|
|
return seconds_since_ref - UNIX_REFERENCE_INTERVAL;
|
|
|
|
|
}
|
|
|
|
|
|
1995-04-13 21:57:29 +00:00
|
|
|
|
- (NSTimeInterval) timeIntervalSinceDate: (NSDate*)otherDate
|
1995-03-31 15:39:12 +00:00
|
|
|
|
{
|
1996-10-31 17:14:00 +00:00
|
|
|
|
return seconds_since_ref - [otherDate timeIntervalSinceReferenceDate];
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSTimeInterval) timeIntervalSinceNow
|
|
|
|
|
{
|
1996-03-12 14:48:07 +00:00
|
|
|
|
NSTimeInterval now = [[self class] timeIntervalSinceReferenceDate];
|
1996-10-31 17:14:00 +00:00
|
|
|
|
return seconds_since_ref - now;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSTimeInterval) timeIntervalSinceReferenceDate
|
|
|
|
|
{
|
1996-10-31 17:14:00 +00:00
|
|
|
|
return seconds_since_ref;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Comparing dates
|
|
|
|
|
|
1995-04-13 21:57:29 +00:00
|
|
|
|
- (NSComparisonResult) compare: (NSDate*)otherDate
|
1995-03-31 15:39:12 +00:00
|
|
|
|
{
|
1996-10-31 17:14:00 +00:00
|
|
|
|
if (seconds_since_ref > [otherDate timeIntervalSinceReferenceDate])
|
1995-04-13 21:57:29 +00:00
|
|
|
|
return NSOrderedDescending;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
|
1996-10-31 17:14:00 +00:00
|
|
|
|
if (seconds_since_ref < [otherDate timeIntervalSinceReferenceDate])
|
1995-04-13 21:57:29 +00:00
|
|
|
|
return NSOrderedAscending;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
|
1995-04-13 21:57:29 +00:00
|
|
|
|
return NSOrderedSame;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-04-13 21:57:29 +00:00
|
|
|
|
- (NSDate*) earlierDate: (NSDate*)otherDate
|
1995-03-31 15:39:12 +00:00
|
|
|
|
{
|
1996-10-31 17:14:00 +00:00
|
|
|
|
if (seconds_since_ref > [otherDate timeIntervalSinceReferenceDate])
|
1995-04-13 21:57:29 +00:00
|
|
|
|
return otherDate;
|
|
|
|
|
return self;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-04-13 21:57:29 +00:00
|
|
|
|
- (BOOL) isEqual: (id)other
|
1995-03-31 15:39:12 +00:00
|
|
|
|
{
|
1995-08-02 15:21:54 +00:00
|
|
|
|
if ([other isKindOf: [NSDate class]]
|
1997-05-03 18:13:17 +00:00
|
|
|
|
&& 1.0 > ABS(seconds_since_ref - [other timeIntervalSinceReferenceDate]))
|
1995-04-13 21:57:29 +00:00
|
|
|
|
return YES;
|
|
|
|
|
return NO;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-11-30 10:04:24 +00:00
|
|
|
|
- (BOOL) isEqualToDate: (NSDate*)other
|
|
|
|
|
{
|
|
|
|
|
if (1.0 > ABS(seconds_since_ref - [other timeIntervalSinceReferenceDate]))
|
|
|
|
|
return YES;
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
1995-04-13 21:57:29 +00:00
|
|
|
|
- (NSDate*) laterDate: (NSDate*)otherDate
|
1995-03-31 15:39:12 +00:00
|
|
|
|
{
|
1996-10-31 17:14:00 +00:00
|
|
|
|
if (seconds_since_ref < [otherDate timeIntervalSinceReferenceDate])
|
1995-04-13 21:57:29 +00:00
|
|
|
|
return otherDate;
|
|
|
|
|
return self;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|