Timestamp.st
changeset 16978 0840890ecedb
parent 16977 deb0f10f246a
child 16986 fafb2758c9f6
--- a/Timestamp.st	Fri Nov 07 20:04:28 2014 +0100
+++ b/Timestamp.st	Fri Nov 07 20:45:35 2014 +0100
@@ -1584,6 +1584,32 @@
 
 !Timestamp methodsFor:'accessing'!
 
+computeTimeInfo
+    |d t info|
+
+    "/ fake an info which the OS cannot give me
+    d := self asDate.
+    t := self asTime.
+    info := OperatingSystem timeInfoClass new.
+    info year:d year month:d month day:d day 
+         hours:t hours minutes:t minutes seconds:t seconds milliseconds:t milliseconds
+         utcOffset:(self utcOffset) dst:false dayInYear:d dayInYear dayInWeek:d dayInWeek.
+    ^ info
+!
+
+computeUtcTimeInfo
+    |d t info|
+
+    "/ fake an info which the OS cannot give me
+    d := self asUtcTimestamp asDate.
+    t := self asUtcTimestamp asTime.
+    info := OperatingSystem timeInfoClass new.
+    info year:d year month:d month day:d day 
+         hours:t hours minutes:t minutes seconds:t seconds milliseconds:t milliseconds
+         utcOffset:0 dst:false dayInYear:d dayInYear dayInWeek:d dayInWeek.
+    ^ info
+!
+
 day
     "return the day-in-month of the receiver (1..31).
      For compatibility, use instances of Date for this."
@@ -1785,10 +1811,8 @@
 
 timeInfo
     osTime < 0 ifTrue:[
-	self halt:'timestamp out of OS range'.
-	"/ TODO:
-	"/ get timeInfo of epoch,
-	"/ manually adjust d.m.y and h.m.s from the negative osTime.
+        "/ fake an info which the OS cannot give me
+        ^ self computeTimeInfo
     ].
 
     ^ OperatingSystem computeTimeAndDateFrom:osTime
@@ -1831,6 +1855,15 @@
     "Modified: 1.7.1996 / 15:21:29 / cg"
 !
 
+utcTimeInfo
+    osTime < 0 ifTrue:[
+        "/ fake an info which the OS cannot give me
+        ^ self computeUtcTimeInfo
+    ].
+
+    ^ OperatingSystem computeUTCTimeAndDateFrom:osTime
+!
+
 weekInYear
     "return the week number of the receiver - 1 for Jan, 1st."
 
@@ -1992,15 +2025,13 @@
      otherwise if you convert an utcTimestamp, you'll get the utc date."
 
     osTime < 0 ifTrue:[
-	|secondDelta dayDelta day0 time0 day time|
-
-	secondDelta := osTime // 1000.
-	self isUtcTimestamp ifFalse:[
-	    secondDelta := secondDelta - self utcOffset
-	].
-	dayDelta := secondDelta // (24 * 3600).
-	day0 := self class epoch asDate.
-	^ day0 addDays:dayDelta.
+        |secondDelta dayDelta day0 time0 day time|
+
+        secondDelta := osTime // 1000.
+        secondDelta := secondDelta - self utcOffset.
+        dayDelta := secondDelta // (24 * 3600).
+        day0 := self class epoch asDate.
+        ^ day0 addDays:dayDelta.
     ].
     ^ self timeInfo asDate
 
@@ -2072,11 +2103,9 @@
     |secondDelta|
 
     osTime < 0 ifTrue:[
-	secondDelta := osTime // 1000.
-	self isUtcTimestamp ifFalse:[
-	    secondDelta := secondDelta - self utcOffset
-	].
-	^ self class epoch asTime addSeconds:secondDelta.
+        secondDelta := osTime // 1000.
+        secondDelta := secondDelta - self utcOffset.
+        ^ self class epoch asTime addSeconds:secondDelta.
     ].
     ^ self timeInfo asTime
 
@@ -3564,11 +3593,11 @@
 !Timestamp class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.181 2014-11-07 19:04:28 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.182 2014-11-07 19:45:35 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.181 2014-11-07 19:04:28 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.182 2014-11-07 19:45:35 cg Exp $'
 ! !