From d1eacbcc7e4ba00187c6879bb33eb165bb2b1e84 Mon Sep 17 00:00:00 2001 From: mccallum Date: Thu, 31 Oct 1996 17:22:04 +0000 Subject: [PATCH] Changes from Scott Christley. See Oct 18 ChangeLog entry. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1887 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 10 ++++++++++ Headers/gnustep/base/NSZone.h | 2 ++ Source/Makefile.sed.nt | 2 +- Source/NSDate.m | 26 ++++++++++++++++++++++++++ Source/Time.m | 28 +++++++++++++++++++++++----- 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 85c4c423e..3ae18b9b7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,16 @@ Tue Oct 15 15:29:07 1996 Adam Fedor * src/include/objc-load.h (objc_load_modules, objc_unload_modules): Use Class not Class*. +Fri Oct 18 10:45:10 1996 Scott Christley + + * Makefile.sed.nt: Always force gnustep/base target. + * src/NSDate.m (+timeIntervalSinceReferenceDate): Use native + Win32 functions to obtain current time. + * src/Time.m (gettimeofday): Win32 implementation, not year + 2000 compliant so don't use it. + * src/include/NSZone.h: Include preface.c so that NSZone gets + configuration settings. + Wed Oct 16 10:01:23 1996 Scott Christley * checks/nsdate.m: New file. diff --git a/Headers/gnustep/base/NSZone.h b/Headers/gnustep/base/NSZone.h index 63f558723..782ce5392 100644 --- a/Headers/gnustep/base/NSZone.h +++ b/Headers/gnustep/base/NSZone.h @@ -25,6 +25,8 @@ #ifndef h_zone_NS_h #define h_zone_NS_h +#include + #if NeXT_runtime #include diff --git a/Source/Makefile.sed.nt b/Source/Makefile.sed.nt index 878bb2c09..ae250e251 100644 --- a/Source/Makefile.sed.nt +++ b/Source/Makefile.sed.nt @@ -137,7 +137,7 @@ install: installdirs all\ for %i in ( ${NEXTSTEP_HEADERS} ) do \\\ rm -f $(includedir)/%i /gnustep\/base:/,/ln -s $(srcdir)\/include Foundation/c\ -gnustep/base: include\/preface.h\ +gnustep/base: include\/preface.h FORCE\ -rm -rf gnustep\ -mkdir gnustep\ -mkdir gnustep\\base\ diff --git a/Source/NSDate.m b/Source/NSDate.m index 36fe49fd6..179390ac1 100644 --- a/Source/NSDate.m +++ b/Source/NSDate.m @@ -62,6 +62,7 @@ + (NSTimeInterval) timeIntervalSinceReferenceDate { +#ifndef __WIN32__ volatile NSTimeInterval interval; struct timeval tp; struct timezone tzp; @@ -75,6 +76,31 @@ assert (interval < 0); return interval; +#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__ */ } // Allocation and initializing diff --git a/Source/Time.m b/Source/Time.m index b68225101..0044cd34c 100644 --- a/Source/Time.m +++ b/Source/Time.m @@ -65,6 +65,7 @@ int gettimeofday(tvp, tzp) #endif /* _SEQUENT_ */ #ifdef __WIN32__ +#include /* Win32 does not provide gettimeofday() */ int gettimeofday(tvp, tzp) struct timeval *tvp; @@ -72,6 +73,7 @@ int gettimeofday(tvp, tzp) { TIME_ZONE_INFORMATION sys_time_zone; SYSTEMTIME sys_time; + struct tm timem; // Get the time zone information GetTimeZoneInformation(&sys_time_zone); @@ -79,11 +81,27 @@ int gettimeofday(tvp, tzp) // Get the local time GetLocalTime(&sys_time); - tvp->tv_usec = sys_time.wMilliseconds; - tvp->tv_sec = sys_time.wSecond; - tvp->tv_sec = tvp->tv_sec + (sys_time.wMinute * 60); - tvp->tv_sec = tvp->tv_sec + (sys_time.wHour * 60 * 60); - tvp->tv_sec = tvp->tv_sec + (sys_time.wDay * 60 * 60 * 24); + timem.tm_sec = sys_time.wSecond; + timem.tm_min = sys_time.wMinute; + timem.tm_hour = sys_time.wHour; + timem.tm_yday = 0; + timem.tm_mday = sys_time.wDay; + timem.tm_year = sys_time.wYear - 1900; + timem.tm_wday = sys_time.wDayOfWeek; + timem.tm_mon = sys_time.wMonth - 1; + + if (tvp) + { + tvp->tv_usec = sys_time.wMilliseconds; + tvp->tv_sec = mktime(&timem); + } + + if (tzp) + { + tzp->tz_minuteswest = sys_time_zone.Bias; + tzp->tz_dsttime = sys_time_zone.StandardBias != sys_time_zone.Bias; + } + return 0; }