Date tidyups

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14897 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2002-11-01 08:11:46 +00:00
parent 7d678efc4a
commit 770b64bc29
5 changed files with 33 additions and 19 deletions

View file

@ -1,3 +1,11 @@
2002-11-01 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/gnustep/base/NSDate.h: Added NSTimeIntervalSince1970 and
removed GSTimeNow() from public API.
* Source/NSDate.m: Update to use NSTimeIntervalSince1970
* Source/NSTimer.m: Declare GSTimeNow() locally
* Source/NSprocessInfo.m: ditto
Thu Oct 31 00:46:23 2002 Nicola Pero <n.pero@mi.flashnet.it>
* Headers/gnustep/base/NSBundle.h: Added more documentation.

View file

@ -21,9 +21,23 @@
#ifndef __NSDate_h_GNUSTEP_BASE_INCLUDE
#define __NSDate_h_GNUSTEP_BASE_INCLUDE
/* Time interval difference between two dates, in seconds.*/
#include <Foundation/NSObjCRuntime.h>
/**
* Time interval difference between two dates, in seconds.
*/
typedef double NSTimeInterval;
/**
* Time interval between the unix standard reference date of 1 January 1970
* and the OpenStep reference date of 1 January 2001<br />
* This number comes from:<br />
* (((31 years * 365 days) + 8 days for leap years) = total number of days<br />
* 24 hours * 60 minutes * 60 seconds)<br />
* This ignores leap-seconds.
*/
GS_EXPORT const NSTimeInterval NSTimeIntervalSince1970;
#include <Foundation/NSObject.h>
@class NSArray;
@ -96,8 +110,4 @@ typedef double NSTimeInterval;
@end
#ifndef NO_GNUSTEP
NSTimeInterval GSTimeNow(); /* Get time since reference date*/
#endif
#endif /* __NSDate_h_GNUSTEP_BASE_INCLUDE*/

View file

@ -50,20 +50,13 @@
#include <stdlib.h>
#include "GSPrivate.h"
/* 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)
const NSTimeInterval NSTimeIntervalSince1970 = 978307200.0;
static BOOL debug = NO;
@ -138,7 +131,7 @@ GSTimeNow()
struct timeval tp;
gettimeofday (&tp, NULL);
interval = UNIX_REFERENCE_INTERVAL;
interval = -NSTimeIntervalSince1970;
interval += tp.tv_sec;
interval += (double)tp.tv_usec / 1000000.0;
return interval;
@ -922,7 +915,7 @@ GSTimeNow()
+ (id) dateWithTimeIntervalSince1970: (NSTimeInterval)seconds
{
return AUTORELEASE([[self alloc] initWithTimeIntervalSinceReferenceDate:
UNIX_REFERENCE_INTERVAL + seconds]);
-NSTimeIntervalSince1970 + seconds]);
}
+ (id) dateWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds
@ -1043,7 +1036,7 @@ GSTimeNow()
- (id) initWithTimeIntervalSince1970: (NSTimeInterval)seconds
{
return [self initWithTimeIntervalSinceReferenceDate:
UNIX_REFERENCE_INTERVAL + seconds];
-NSTimeIntervalSince1970 + seconds];
}
- (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)secs
@ -1121,7 +1114,7 @@ GSTimeNow()
- (NSTimeInterval) timeIntervalSince1970
{
return otherTime(self) - UNIX_REFERENCE_INTERVAL;
return otherTime(self) + NSTimeIntervalSince1970;
}
- (NSTimeInterval) timeIntervalSinceDate: (NSDate*)otherDate
@ -1248,7 +1241,7 @@ GSTimeNow()
- (NSTimeInterval) timeIntervalSince1970
{
return _seconds_since_ref - UNIX_REFERENCE_INTERVAL;
return _seconds_since_ref + NSTimeIntervalSince1970;
}
- (NSTimeInterval) timeIntervalSinceDate: (NSDate*)otherDate

View file

@ -615,6 +615,8 @@ int main(int argc, char *argv[], char *env[])
[gnustep_global_lock lock];
if (host == nil)
{
extern NSTimeInterval GSTimeNow();
pid = [self processIdentifier];
start = (unsigned long)GSTimeNow();
host = [[self hostName] stringByReplacingString: @"." withString: @"_"];

View file

@ -201,6 +201,7 @@ static Class NSDate_class;
}
else if (_invalidated == NO)
{
extern NSTimeInterval GSTimeNow();
NSTimeInterval now = GSTimeNow();
NSTimeInterval nxt = [_date timeIntervalSinceReferenceDate];
int inc = -1;