TZTimestamp.st
changeset 16966 7d549c75105f
parent 16954 e13618117ebc
child 16976 34cb1703d013
--- a/TZTimestamp.st	Fri Nov 07 13:23:34 2014 +0100
+++ b/TZTimestamp.st	Fri Nov 07 18:49:14 2014 +0100
@@ -47,6 +47,19 @@
         However, timestamp instances can now hold negative osTime values (which are timestamps
         before 1.1.1970 and greater than 4294967295 (2^32-1) for timestamps after 2038-01-19.
 
+    [example:]
+      the current time as local time:
+        Transcript showCR:Timestamp now
+
+      the current time as utc time:       
+        Transcript showCR:UtcTimestamp now
+
+      same:
+        Transcript showCR:Timestamp now asUtcTimestamp
+
+      the current time in NewYork:         
+        Transcript showCR:( Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'EST') negated ) 
+
     [author:]
         Claus Gittinger
 
@@ -57,6 +70,21 @@
 
 !TZTimestamp methodsFor:'accessing'!
 
+isLocalTimestamp
+    ^ false
+!
+
+timeInfo
+    "fake it"
+
+    |ti|
+
+    "/ utcOffset negative: east of GMT
+    ti := OperatingSystem computeUTCTimeAndDateFrom:(osTime - (utcOffset * 1000)).
+    ti utcOffset:utcOffset.
+    ^ ti
+!
+
 utcOffset
     "return the difference between UTC (Greenwich Mean Time) and the local time in seconds.
      If daylight saving time applies to ourself, take that into account.
@@ -83,13 +111,30 @@
     utcOffset := seconds
 ! !
 
+!TZTimestamp methodsFor:'converting'!
+
+asLocalTimestamp
+    "return a local timestamp, representing the same time as the receiver"
+
+    ^ Timestamp fromOSTime:osTime.
+!
+
+asTZTimestamp:utcOffsetArg
+    "return a timestamp in a given timezone, representing the same time as the receiver"
+
+    utcOffset = utcOffsetArg ifTrue:[
+        ^ self.
+    ].
+    ^ super asTZTimestamp:utcOffsetArg
+! !
+
 !TZTimestamp class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/TZTimestamp.st,v 1.1 2014-11-07 12:12:01 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/TZTimestamp.st,v 1.2 2014-11-07 17:49:14 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/TZTimestamp.st,v 1.1 2014-11-07 12:12:01 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/TZTimestamp.st,v 1.2 2014-11-07 17:49:14 cg Exp $'
 ! !