AbstractOperatingSystem.st
changeset 7514 0335bec855aa
parent 7510 46a848d466b5
child 7637 6137943fb16c
--- a/AbstractOperatingSystem.st	Wed Jul 16 16:01:40 2003 +0200
+++ b/AbstractOperatingSystem.st	Wed Jul 16 16:07:30 2003 +0200
@@ -21,6 +21,14 @@
 	category:'System-Support'
 !
 
+Object subclass:#TimeInfo
+	instanceVariableNames:'year month day hours minutes seconds utcOffset dst milliseconds
+		dayInYear dayInWeek'
+	classVariableNames:''
+	poolDictionaries:''
+	privateIn:AbstractOperatingSystem
+!
+
 !AbstractOperatingSystem primitiveDefinitions!
 %{
 
@@ -4817,7 +4825,18 @@
      dayInYear (1..) and dayInWeek (1..).
      Conversion is to localtime including any daylight saving adjustments."
 
-    self subclassResponsibility
+    |millis osSeconds ret|
+
+    millis := osTime \\ 1000.
+    osSeconds := osTime // 1000.
+    ret := self timeInfoFromSeconds:osSeconds localTime:true.
+    ret milliseconds:millis.
+    ^ ret
+
+    "
+     OperatingSystem computeTimeAndDateFrom:0
+     OperatingSystem computeTimeAndDateFrom:1011
+    "
 !
 
 computeTimePartsOf:osTime for:aBlock
@@ -4830,12 +4849,32 @@
 
 computeUTCTimeAndDateFrom:osTime
     "given an OS-dependent time in osTime, return an Array
-     containing year, month, day, hour, minute and seconds,
-     offset to UTC, daylight savings time flag, milliseconds,
-     dayInYear (1..) and dayInWeek (1..).
-     Conversion is to UTC."
-
-    self subclassResponsibility
+     containing:
+        (full-) year, 
+        month,                          (1..)
+        day,                            (1..)
+        hour,                           (0..23)
+        minute                          (0..59)
+        seconds,                        (0..59)
+        offset to UTC,                  (seconds)
+        daylight savings time flag, 
+        milliseconds,                   (0..999)
+        dayInYear                       (1..)
+        dayInWeek                       (1..).
+     Conversion is to utc."
+
+    |millis osSeconds ret|
+
+    millis := osTime \\ 1000.
+    osSeconds := osTime // 1000.
+    ret := self timeInfoFromSeconds:osSeconds localTime:false.
+    ret milliseconds:millis.
+    ^ ret
+
+    "
+     OperatingSystem computeUTCTimeAndDateFrom:0     
+     OperatingSystem computeUTCTimeAndDateFrom:1011
+    "
 !
 
 computeUTCTimePartsOf:osTime for:aBlock
@@ -5019,6 +5058,17 @@
      only the calling thread sleep)."
 
     self subclassResponsibility
+!
+
+timeInfoClass
+    ^ TimeInfo
+!
+
+timeInfoFromSeconds:osSeconds localTime:isLocalTime
+    "return a timeInfo structure containing values for the given OS-second value.
+     An internal helper"
+
+    self subclassResponsibility
 ! !
 
 !AbstractOperatingSystem class methodsFor:'users & groups'!
@@ -5387,10 +5437,115 @@
     ^ false
 ! !
 
+!AbstractOperatingSystem::TimeInfo methodsFor:'accessing'!
+
+at:index
+    "backward compatibility"
+
+    self obsoleteMethodWarning:'use accessor for index ', index printString.
+    index == 1 ifTrue:[
+        ^ self year.
+    ].
+    index == 2 ifTrue:[
+        ^ self month.
+    ].
+    index == 3 ifTrue:[
+        ^ self day.
+    ].
+    index == 4 ifTrue:[
+        ^ self hours.
+    ].
+    index == 5 ifTrue:[
+        ^ self minutes.
+    ].
+    index == 6 ifTrue:[
+        ^ self seconds.
+    ].
+    index == 7 ifTrue:[
+        ^ self utcOffset.
+    ].
+    index == 8 ifTrue:[
+        ^ self dst.
+    ].
+    index == 9 ifTrue:[
+        ^ self milliseconds.
+    ].
+    index == 10 ifTrue:[
+        ^ self dayInYear.
+    ].
+    index == 11 ifTrue:[
+        ^ self dayInWeek.
+    ].
+    self subscriptBoundsError:index
+!
+
+day
+    ^ day
+!
+
+dayInWeek
+    ^ dayInWeek
+!
+
+dayInYear
+    ^ dayInYear
+!
+
+dst
+    ^ dst
+!
+
+hours
+    ^ hours
+!
+
+milliseconds
+    ^ milliseconds
+!
+
+milliseconds:something
+    milliseconds := something.
+!
+
+minutes
+    ^ minutes
+!
+
+month
+    ^ month
+!
+
+seconds
+    ^ seconds
+!
+
+utcOffset
+    ^ utcOffset
+!
+
+year
+    ^ year
+!
+
+year:yearArg month:monthArg day:dayArg hours:hoursArg minutes:minutesArg seconds:secondsArg utcOffset:utcOffsetArg dst:dstArg dayInYear:dayInYearArg dayInWeek:dayInWeekArg 
+    "set instance variables (automatically generated)"
+
+    year := yearArg.
+    month := monthArg.
+    day := dayArg.
+    hours := hoursArg.
+    minutes := minutesArg.
+    seconds := secondsArg.
+    utcOffset := utcOffsetArg.
+    dst := dstArg.
+    dayInYear := dayInYearArg.
+    dayInWeek := dayInWeekArg.
+! !
+
 !AbstractOperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/AbstractOperatingSystem.st,v 1.104 2003-07-15 14:03:28 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/AbstractOperatingSystem.st,v 1.105 2003-07-16 14:07:23 cg Exp $'
 ! !
 
 AbstractOperatingSystem initialize!