Timestamp.st
changeset 4378 8b93493f8d56
parent 3995 777470826394
child 4679 957773d921a8
--- a/Timestamp.st	Tue Jul 13 12:45:13 1999 +0200
+++ b/Timestamp.st	Tue Jul 13 12:46:55 1999 +0200
@@ -72,43 +72,60 @@
 
 !AbsoluteTime class methodsFor:'instance creation'!
 
-day:d month:m year:y hour:h minutes:min seconds:s
-    "return an instance of the receiver, given individual components.
-     See also `AbsoluteTime now' and other protocol inherited
-     from my superclass."
-
-    ^ self 
-	day:d month:m year:y hour:h 
-	minutes:min seconds:s milliseconds:0
-
-    "
-     AbsoluteTime day:2 month:1 year:1991 hour:12 minutes:30 seconds:0 
-     AbsoluteTime day:8 month:1 year:1995 hour:0 minutes:43 seconds:48 
-    "
-
-    "Modified: 1.7.1996 / 15:22:26 / cg"
-!
-
-day:d month:m year:y hour:h minutes:min seconds:s milliseconds:millis
+UTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis
     "return an instance of the receiver, given individual components.
      See also `AbsoluteTime now' and other protocol inherited
      from my superclass."
 
     ^ self basicNew 
-	fromOSTime:(OperatingSystem 
-			computeOSTimeFromYear:y month:m day:d 
-					 hour:h minute:min seconds:s
-				       millis:millis)
+        fromOSTime:(OperatingSystem 
+                        computeOSTimeFromUTCYear:y month:m day:d 
+                                         hour:h minute:min second:s
+                                         millisecond:millis)
 
     "
-     AbsoluteTime day:1 month:1 year:1970 hour:1 minutes:0 seconds:0 
-     AbsoluteTime day:2 month:1 year:1991 hour:12 minutes:30 seconds:0 
-     AbsoluteTime day:2 month:1 year:1991 hour:12 minutes:30 seconds:0 milliseconds:100
+     AbsoluteTime UTCYear:1970 month:1 day:1 hour:1 minute:0 second:0 millisecond:0
+     AbsoluteTime UTCYear:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:0
+     AbsoluteTime UTCYear:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100
+     AbsoluteTime UTCYear:1999 month:7 day:1 hour:1 minute:0 second:0 millisecond:0
+     AbsoluteTime UTCYear:2000 month:1 day:1 hour:1 minute:0 second:0 millisecond:0
     "
 
-    "Created: 1.7.1996 / 14:46:09 / cg"
-    "Modified: 1.7.1996 / 15:22:07 / cg"
-    "Modified: 22.10.1996 / 09:25:04 / stefan"
+    "Modified: / 1.7.1996 / 15:22:07 / cg"
+    "Created: / 13.7.1999 / 12:34:37 / stefan"
+    "Modified: / 13.7.1999 / 12:42:30 / stefan"
+!
+
+day:d month:m year:y hour:h minutes:min seconds:s
+    "This is obsolete. User #year:month:day:hour:minute:second:"
+
+    ^ self 
+        year:y month:m day:d hour:h 
+        minute:min second:s millisecond:0
+
+    "
+     AbsoluteTime day:2 month:1 year:1991 hour:12 minute:30 second:0 
+     AbsoluteTime day:8 month:1 year:1995 hour:0 minute:43 second:48 
+    "
+
+    "Modified: / 1.7.1996 / 15:22:26 / cg"
+    "Modified: / 13.7.1999 / 12:29:56 / stefan"
+!
+
+day:d month:m year:y hour:h minutes:min seconds:s milliseconds:millis
+    "This is obsolete. User #year:month:day:hour:minute:second:millisecond:"
+
+    ^ self year:y month:m day:d hour:h minute:min second:s millisecond:millis
+
+    "
+     AbsoluteTime day:1 month:1 year:1970 hour:1 minute:0 second:0 
+     AbsoluteTime day:2 month:1 year:1991 hour:12 minute:30 second:0 
+     AbsoluteTime day:2 month:1 year:1991 hour:12 minute:30 second:0 millisecond:100
+    "
+
+    "Created: / 1.7.1996 / 14:46:09 / cg"
+    "Modified: / 1.7.1996 / 15:22:07 / cg"
+    "Modified: / 13.7.1999 / 12:30:26 / stefan"
 !
 
 fromDate:aDate andTime:aTime
@@ -118,12 +135,12 @@
      from my superclass."
 
     ^ self 
-	day:aDate day 
-	month:aDate month 
-	year:aDate year 
-	hour:aTime hours 
-	minutes:aTime minutes 
-	seconds:aTime seconds 
+        year:aDate year 
+        month:aDate month 
+        day:aDate day 
+        hour:aTime hours 
+        minute:aTime minutes 
+        second:aTime seconds 
 
     "
      AbsoluteTime fromDate:(Date today) andTime:(Time now)  
@@ -131,8 +148,9 @@
      AbsoluteTime now 
     "
 
-    "Modified: 8.9.1995 / 15:07:30 / claus"
-    "Modified: 19.4.1996 / 15:25:46 / cg"
+    "Modified: / 8.9.1995 / 15:07:30 / claus"
+    "Modified: / 19.4.1996 / 15:25:46 / cg"
+    "Modified: / 13.7.1999 / 12:30:47 / stefan"
 !
 
 newDay:dayInYear year:year
@@ -196,7 +214,7 @@
         hour == 24 ifTrue:[
             (min ~~ 0 or:[sec ~~ 0]) ifTrue:[^ exceptionBlock value].
         ].
-        newTime := self day:day month:month year:year hour:hour minutes:min seconds:sec.
+        newTime := self year:year month:month day:day hour:hour minute:min second:sec.
     ].
     ^ newTime
 
@@ -208,22 +226,64 @@
      AbsoluteTime readFrom:'foo' onError:'wrong'                     
     "
 
-    "Modified: 8.10.1996 / 19:25:59 / cg"
+    "Modified: / 8.10.1996 / 19:25:59 / cg"
+    "Modified: / 13.7.1999 / 12:31:14 / stefan"
 !
 
 secondsSince1970:sec
     "set time from elapsed seconds since 1-1-1970, 0:0:0.
      This is the format used in the UNIX world"
 
-    ^ self day:1 month:1 year:1970 hour:0 minutes:0 seconds:sec.
+    ^ self year:1970 month:1 day:1 hour:0 minute:0 second:sec.
+
+    "
+        AbsoluteTime secondsSince1970:0
+        AbsoluteTime secondsSince1970:3600
+    "
+
+    "Created: / 21.10.1996 / 17:48:30 / stefan"
+    "Modified: / 13.7.1999 / 12:31:22 / stefan"
+!
+
+year:y month:m day:d hour:h minute:min second:s
+    "return an instance of the receiver, given individual components.
+     See also `AbsoluteTime now' and other protocol inherited
+     from my superclass."
+
+    ^ self year:y month:m day:d hour:h minute:min second:s millisecond:0
 
     "
-	AbsoluteTime secondsSince1970:0
-	AbsoluteTime secondsSince1970:3600
+     AbsoluteTime year:1970 month:1 day:1 hour:1 minute:0 second:0 
+     AbsoluteTime year:1991 month:1 day:2 hour:12 minute:30 second:0 
+     AbsoluteTime year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100
+     AbsoluteTime year:2000 month:1 day:1 hour:1 minutes:0 second:0 
     "
 
-    "Created: 21.10.1996 / 17:48:30 / stefan"
-    "Modified: 22.10.1996 / 11:07:45 / stefan"
+    "Modified: / 1.7.1996 / 15:22:07 / cg"
+    "Created: / 13.7.1999 / 12:06:39 / stefan"
+    "Modified: / 13.7.1999 / 12:27:47 / stefan"
+!
+
+year:y month:m day:d hour:h minute:min second:s millisecond:millis
+    "return an instance of the receiver, given individual components.
+     See also `AbsoluteTime now' and other protocol inherited
+     from my superclass."
+
+    ^ self basicNew 
+        fromOSTime:(OperatingSystem 
+                        computeOSTimeFromYear:y month:m day:d 
+                                         hour:h minute:min seconds:s millis:millis)
+
+    "
+     AbsoluteTime year:1970 month:1 day:1 hour:1 minute:0 seconds:0 
+     AbsoluteTime year:1991 month:1 day:2 hour:12 minute:30 second:0 
+     AbsoluteTime year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100
+     AbsoluteTime year:2000 month:1 day:1 hour:1 minute:0 second:0 
+    "
+
+    "Modified: / 1.7.1996 / 15:22:07 / cg"
+    "Created: / 13.7.1999 / 12:28:44 / stefan"
+    "Modified: / 13.7.1999 / 12:37:57 / stefan"
 ! !
 
 !AbsoluteTime methodsFor:'accessing'!
@@ -702,8 +762,70 @@
     "Modified: 1.7.1996 / 14:34:10 / cg"
 ! !
 
+!AbsoluteTime methodsFor:'queries - asn1'!
+
+asn1PrintOn:aStream
+    "append a representation of the receiver to aStream in
+     ASN.1 GeneralizedTime format."
+
+    |t mil off|
+
+    t := OperatingSystem computeTimeAndDateFrom:osTime.
+
+    (t at:1) printOn:aStream leftPaddedTo:4 with:$0.
+    (t at:2) printOn:aStream leftPaddedTo:2 with:$0.
+    (t at:3) printOn:aStream leftPaddedTo:2 with:$0.
+    (t at:4) printOn:aStream leftPaddedTo:2 with:$0. 
+    (t at:5) printOn:aStream leftPaddedTo:2 with:$0.
+    (t at:6) printOn:aStream leftPaddedTo:2 with:$0.
+    mil := t at:9.
+    mil ~~ 0 ifTrue:[
+        aStream nextPut:$..
+        mil printOn:aStream leftPaddedTo:3 with:$0.
+    ].
+    off := t at:7.
+    off == 0 ifTrue:[
+        aStream nextPut:$Z.
+    ] ifFalse:[ |min|
+        off < 0 ifTrue:[
+            aStream nextPut:$+.
+            off := off negated.
+        ] ifFalse:[
+            aStream nextPut:$-.
+        ].
+        min := off // 60.
+        min // 60 printOn:aStream leftPaddedTo:2 with:$0.
+        min \\ 60 printOn:aStream leftPaddedTo:2 with:$0.
+    ].
+
+
+
+    "
+     AbsoluteTime now asn1PrintOn:Transcript. Transcript cr. 
+     (AbsoluteTime fromSeconds:0) asn1PrintOn:Transcript. Transcript cr.
+     Time now printOn:Transcript. Transcript cr.           
+     Date today printOn:Transcript. Transcript cr.        
+
+     Time now asAbsoluteTime asn1PrintOn:Transcript. Transcript cr.           
+     AbsoluteTime now asn1PrintOn:Transcript. Transcript cr. 
+
+     Date today asAbsoluteTime asn1PrintOn:Transcript. Transcript cr.           
+     Date today printOn:Transcript. Transcript cr.           
+    "
+
+    "Modified: / 1.7.1996 / 15:20:59 / cg"
+    "Modified: / 13.7.1999 / 11:04:45 / stefan"
+!
+
+asn1Type
+
+    ^ OSI::ASN1_GeneralizedTime primitiveType
+
+    "Created: / 12.7.1999 / 18:21:51 / stefan"
+! !
+
 !AbsoluteTime class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.37 1999-02-22 20:39:06 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.38 1999-07-13 10:46:55 stefan Exp $'
 ! !