Unix.st
changeset 810 9b3676f51220
parent 809 5eef87c2907b
child 811 6fbd6e7fdb74
--- a/Unix.st	Sat Dec 23 01:35:10 1995 +0100
+++ b/Unix.st	Sat Dec 23 12:02:57 1995 +0100
@@ -136,21 +136,7 @@
 #   include <time.h>
 #   include <sys\timeb.h>
 #  else
-#   ifdef ultrix
-     /*
-      * ultrix only defines localtime & daylight, if _XOPEN_SOURCE
-      * is defined
-      */
-#    ifndef _XOPEN_SOURCE
-#     define _XOPEN_SOURCE
-#     include <sys/time.h>
-#     undef _XOPEN_SOURCE
-#    else
-#     include <sys/time.h>
-#    endif
-#   else /* not ultrix */
-#    include <sys/time.h>
-#   endif
+#   include <sys/time.h>
 #   include <sys/types.h>
 #  endif
 
@@ -4438,9 +4424,9 @@
 
 !OperatingSystem class methodsFor:'time and date'!
 
-computeDatePartsOf:timeLow and:timeHi for:aBlock
-    "compute year, month and day from the time-parts timeLow and
-     timeHi and evaluate the argument, a 3-arg block with these.
+computeDatePartsOf:osTimeLow and:osTimeHi for:aBlock
+    "compute year, month and day from the OS time-parts osTimeLow and
+     osTimeHi and evaluate the argument, a 3-arg block with these.
      Conversion is to localtime including any daylight saving adjustments.
 
      This method was added to avoid LargeInteger arithmetic and to be
@@ -4449,47 +4435,48 @@
 
     |year month day|
 
-    ((timeLow isMemberOf:SmallInteger) and:[timeHi isMemberOf:SmallInteger])
-    ifFalse:[
+    ((osTimeLow isMemberOf:SmallInteger)
+    and:[osTimeHi isMemberOf:SmallInteger]) ifFalse:[
 	^ self primitiveFailed
     ].
 %{
     struct tm *tmPtr;
     long t;
 
-    t = (_intVal(timeHi) << 16) | _intVal(timeLow);
+    t = (_intVal(osTimeHi) << 16) | _intVal(osTimeLow);
     tmPtr = localtime(&t);
     year = _MKSMALLINT(tmPtr->tm_year + 1900);
     month = _MKSMALLINT(tmPtr->tm_mon + 1);
     day = _MKSMALLINT(tmPtr->tm_mday);
-%}
-.
+%}.
     aBlock value:year value:month value:day
 !
 
-computeDatePartsOf:timeParts for:aBlock
+computeDatePartsOf:osTimeParts for:aBlock
     "compute year, month and day from the ostime in timeParts,
      and evaluate the argument, a 3-arg block with these.
      Conversion is to localtime including any daylight saving adjustments."
 
-     ^ self computeDatePartsOf:(timeParts at:1) and:(timeParts at:2) for:aBlock
+     ^ self 
+	computeDatePartsOf:(osTimeParts at:1) 
+	and:(osTimeParts at:2)
+	for:aBlock
 !
 
-computeTimeAndDateFrom:timeParts
+computeTimeAndDateFrom:osTimeParts
     "given an Array containing the OS-dependent time, return an Array
-     containing year, month, day, hour, minute and seconds and offset to UTC.
+     containing year, month, day, hour, minute and seconds,
+     offset to UTC and a daylight savings time flag.
      Conversion is to localtime including any daylight saving adjustments."
 
-    |low hi year month day hours minutes seconds utcOffset ret|
-
-    low := timeParts at:1.
-    hi := timeParts at:2.
+    |low hi year month day hours minutes seconds utcOffset dst ret|
+
+    low := osTimeParts at:1.
+    hi := osTimeParts at:2.
 %{
     struct tm *tmPtr;
+    struct tm *gmTmPtr;
     long t;
-#ifdef ultrix
-    extern long timezone, daylight;
-#endif
 
     if (__bothSmallInteger(low, hi)) {
         t = (_intVal(hi) << 16) | _intVal(low);
@@ -4502,24 +4489,22 @@
         month = _MKSMALLINT(tmPtr->tm_mon + 1);
         day = _MKSMALLINT(tmPtr->tm_mday);
 
-        if (tmPtr->tm_isdst == 0)
+        if (tmPtr->tm_isdst == 0) {
+	    dst = false;
             utcOffset = _MKSMALLINT(timezone);
-        else {
+        } else {
+	    dst = true;
 #ifdef HAS_ALTZONE
             utcOffset = _MKSMALLINT(altzone);
 #else
-# ifdef HAS_DAYLIGHT
-            utcOffset = _MKSMALLINT(daylight);
-# else
-            utcOffset = _MKSMALLINT(timezone);
-# endif
+	    utcOffset = _MKSMALLINT(timezone) + 3600;
 #endif
 	}
     }
 %}.
     year notNil ifTrue:[
         "I would love to have SELF-like inline objects ..."
-        ret := Array new:7.
+        ret := Array new:8.
         ret at:1 put:year.
         ret at:2 put:month.
         ret at:3 put:day.
@@ -4527,6 +4512,7 @@
         ret at:5 put:minutes.
         ret at:6 put:seconds.
         ret at:7 put:utcOffset.
+        ret at:8 put:dst.
         ^ ret
     ].
     ^ self primitiveFailed
@@ -4566,7 +4552,7 @@
     ^ self primitiveFailed
 !
 
-computeTimePartsOf:timeLow and:timeHi for:aBlock
+computeTimePartsOf:osTimeLow and:osTimeHi for:aBlock
     "compute hours, minutes and seconds from the time-parts timeLow and
      timeHi and evaluate the argument, a 3-arg block with these.
      Conversion is to localtime including any daylight saving adjustments.
@@ -4577,30 +4563,32 @@
 
     |hours minutes seconds|
 
-    ((timeLow isMemberOf:SmallInteger) and:[timeHi isMemberOf:SmallInteger])
-    ifFalse:[
+    ((osTimeLow isMemberOf:SmallInteger)
+    and:[osTimeHi isMemberOf:SmallInteger]) ifFalse:[
 	^ self primitiveFailed
     ].
 %{
     struct tm *tmPtr;
     long t;
 
-    t = (_intVal(timeHi) << 16) | _intVal(timeLow);
+    t = (_intVal(osTimeHi) << 16) | _intVal(osTimeLow);
     tmPtr = localtime(&t);
     hours = _MKSMALLINT(tmPtr->tm_hour);
     minutes = _MKSMALLINT(tmPtr->tm_min);
     seconds = _MKSMALLINT(tmPtr->tm_sec);
-%}
-.
+%}.
     aBlock value:hours value:minutes value:seconds
 !
 
-computeTimePartsOf:timeParts for:aBlock
+computeTimePartsOf:osTimeParts for:aBlock
     "compute hour, minute and seconds from the ostime in timeParts,
      and evaluate the argument, a 3-arg block with these.
      Conversion is to localtime including any daylight saving adjustments."
 
-     ^ self computeTimePartsOf:(timeParts at:1) and:(timeParts at:2) for:aBlock
+     ^ self 
+	computeTimePartsOf:(osTimeParts at:1) 
+	and:(osTimeParts at:2)
+	for:aBlock
 !
 
 getMillisecondTime
@@ -4741,8 +4729,7 @@
     now = time(0);
     hi  = _MKSMALLINT((now >> 16) & 0xFFFF);
     low = _MKSMALLINT(now & 0xFFFF);
-%}
-.
+%}.
     ^ Array with:low with:hi
 
     "OperatingSystem getTimeParts"
@@ -4823,7 +4810,8 @@
      The returned value is msTime1 - msTime2. The returned value is invalid
      if the delta is >= 0x10000000.
 
-     This should really be moved to some RelativeTime class."
+     This should really be moved to some RelativeTime class;
+     better yet: create a subclass of Integer named LimitedRangeInteger."
 
     (msTime1 > msTime2) ifTrue:[
 	^ msTime1 - msTime2
@@ -5382,6 +5370,6 @@
 !OperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Attic/Unix.st,v 1.106 1995-12-23 00:35:10 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Attic/Unix.st,v 1.107 1995-12-23 11:02:57 cg Exp $'
 ! !
 OperatingSystem initialize!