#BUGFIX
authorStefan Vogel <sv@exept.de>
Thu, 24 Sep 2015 14:41:52 +0200
changeset 18761 2358ffda3751
parent 18760 9b0b0c157e4c
child 18762 4b2d5801f66c
#BUGFIX class: Timestamp comment/format in: #literalArrayEncoding #printGeneralizedOn: #printGeneralizedOn:isLocal: changed: #printGeneralizedOn:isLocal:short: #readGeneralizedFrom:short:onError: Fix writing of non-Local Timestamps (as used by Timestamp>>#literalArrayEncoding) This bug broke PCS-MD.
Timestamp.st
--- a/Timestamp.st	Wed Sep 23 18:16:53 2015 +0200
+++ b/Timestamp.st	Thu Sep 24 14:41:52 2015 +0200
@@ -1108,13 +1108,13 @@
 readGeneralizedFrom:aStringOrStream short:shortFormat onError:exceptionBlock
     "return a new Timestamp, reading a printed representation from aStream.
      The long format read here is either
-	    yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
-	or:
-	    yyyy-mm-dd HH:MM:SS.iii +uuuu.
+            yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
+        or:
+            yyyy-mm-dd HH:MM:SS.iii +uuuu.
      The (not recommended) short forms are:
-	    yymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
-	or:
-	    yy-mm-dd HH:MM:SS.iii +uuuu.
+            yymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format.
+        or:
+            yy-mm-dd HH:MM:SS.iii +uuuu.
      The string is interpreted as 24 hour format, as printed.
 
      This format is used for BER specification of the ASN.1 GeneralizedTime and
@@ -1129,75 +1129,74 @@
 
 
     ^ [
-	|newTime str day month year hour min sec millis c|
-
-	sec := millis := 0.
-	str := aStringOrStream readStream.
-
-	shortFormat ifTrue:[
-	    year := Integer readFrom:(str next:2).
-	    year < 50 ifTrue:[
-		year := year + 2000.
-	    ] ifFalse:[
-		year := year + 1900.
-	    ].
-	] ifFalse:[
-	    year := Integer readFrom:(str next:4).
-	].
-	str peek == $- ifTrue:[ str next].
-	month := Integer readFrom:(str next:2).
-	(month between:1 and:12) ifFalse:[^ exceptionBlock value].
-	str peek == $- ifTrue:[ str next].
-	day := Integer readFrom:(str next:2).
-	(day between:1 and:31) ifFalse:[^ exceptionBlock value].
-
-	str skipSeparators.
-	hour:= Integer readFrom:(str next:2).
-	(hour between:0 and:24) ifFalse:[^ exceptionBlock value].
-	str peek == $: ifTrue:[ str next].
-	min:= Integer readFrom:(str next:2).
-	(min between:0 and:59) ifFalse:[^ exceptionBlock value].
-	str atEnd ifFalse:[
-	    str peek == $: ifTrue:[ str next].
-	    sec := Integer readFrom:(str next:2).
-	    (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
-	    str atEnd ifFalse:[
-		str peek == $. ifTrue:[
-		    str next.
-		    millis := Integer readFrom:str.
-		].
-		str skipSeparators.
-	    ].
-	].
-
-	str atEnd ifTrue:[
-	    "/ this is local time
-	    newTime := self year:year month:month day:day
-			    hour:hour minute:min second:sec millisecond:millis.
-	] ifFalse:[
-	    c := str next.
-	    c ~~ $Z ifTrue:[
-		|tzh tzmin|
-		tzh := Integer readFrom:(str next:2).
-		tzmin := Integer readFrom:(str next:2).
-		c == $+ ifTrue:[
-		    "the timezone is ahead of UTC or EAST from Greenwich: subtract hours and minutes"
-		    hour := hour - tzh.
-		    min := min - tzmin.
-		] ifFalse:[
-		    c ~~ $- ifTrue:[
-			^ exceptionBlock value.
-		    ].
-		    "the timezone is behind of UTC or WEST from Greenwich: add hours and minutes"
-		    hour := hour + tzh.
-		    min := min + tzmin.
-		].
-	    ].
-	    "this is UTC time"
-	    newTime := self UTCYear:year month:month day:day
-			      hour:hour minute:min second:sec millisecond:millis.
-	].
-	newTime
+        |newTime str day month year hour min sec millis c|
+
+        sec := millis := 0.
+        str := aStringOrStream readStream.
+
+        shortFormat ifTrue:[
+            year := Integer readFrom:(str next:2).
+            year < 50 ifTrue:[
+                year := year + 2000.
+            ] ifFalse:[
+                year := year + 1900.
+            ].
+        ] ifFalse:[
+            year := Integer readFrom:(str next:4).
+        ].
+        str peek == $- ifTrue:[ str next].
+        month := Integer readFrom:(str next:2).
+        (month between:1 and:12) ifFalse:[^ exceptionBlock value].
+        str peek == $- ifTrue:[ str next].
+        day := Integer readFrom:(str next:2).
+        (day between:1 and:31) ifFalse:[^ exceptionBlock value].
+
+        str skipSeparators.
+        hour:= Integer readFrom:(str next:2).
+        (hour between:0 and:24) ifFalse:[^ exceptionBlock value].
+        str peek == $: ifTrue:[ str next].
+        min:= Integer readFrom:(str next:2).
+        (min between:0 and:59) ifFalse:[^ exceptionBlock value].
+        str atEnd ifFalse:[
+            str peek == $: ifTrue:[ str next].
+            sec := Integer readFrom:(str next:2).
+            (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
+            str atEnd ifFalse:[
+                str peek == $. ifTrue:[
+                    str next.
+                    millis := Integer readFrom:str.
+                ].
+                str skipSeparators.
+            ].
+        ].
+
+        str atEnd ifTrue:[
+            "/ this is local time
+            newTime := self year:year month:month day:day
+                            hour:hour minute:min second:sec millisecond:millis.
+        ] ifFalse:[
+            c := str next.
+            c ~~ $Z ifTrue:[
+                |tzh tzmin|
+                tzh := Integer readFrom:(str next:2).
+                tzmin := Integer readFrom:(str next:2).
+                c == $+ ifTrue:[
+                    "the timezone is ahead of UTC or EAST from Greenwich: subtract hours and minutes"
+                    hour := hour - tzh.
+                    min := min - tzmin.
+                ] ifFalse:[
+                    c == $- ifTrue:[
+                        "the timezone is behind of UTC or WEST from Greenwich: add hours and minutes"
+                        hour := hour + tzh.
+                        min := min + tzmin.
+                    ] ifFalse:exceptionBlock
+                ].
+            ].
+            "this is UTC time"
+            newTime := self UTCYear:year month:month day:day
+                              hour:hour minute:min second:sec millisecond:millis.
+        ].
+        newTime
     ] on:Error do:exceptionBlock.
 
     "
@@ -2309,7 +2308,7 @@
     "encode myself as an array, from which a copy of the receiver
      can be reconstructed with #decodeAsLiteralArray.
      The encoding is:
-	(#Timestamp YYYYMMDDhhmmss.iii)
+        (#Timestamp YYYYMMDDhhmmss.iiiZ)
     "
 
     |s|
@@ -2318,14 +2317,14 @@
     self printGeneralizedOn:s isLocal:false.
 
     ^ Array
-	with:self class name
-	with:s contents
+        with:self class name
+        with:s contents
 
     "
       Timestamp now literalArrayEncoding
-	decodeAsLiteralArray
+        decodeAsLiteralArray
       UtcTimestamp now literalArrayEncoding
-	decodeAsLiteralArray
+        decodeAsLiteralArray
     "
 !
 
@@ -2444,7 +2443,7 @@
 
 printGeneralizedOn:aStream
     "append a representation of the receiver to aStream in a general format,
-     top-down, without separators: 'yyyymmddHHMMSS.mmm+0100'
+     top-down, without separators: 'yyyymmddHHMMSS.mmmZ'
 
      This format is used for the ASN.1 GeneralizedTime as defined in X.208 Sec. 33,
      so read this before changing the output format."
@@ -2459,7 +2458,8 @@
      This format is used for the ASN.1 GeneralizedTime as defined in X.208 Sec. 33,
      so read this before changing the output format.
 
-     If isLocal is true, represent as local time, otherwise add UTC time offset."
+     If isLocal is true, represent as local time (Local 'yyyymmddHHMMSS.mmm+0100'), 
+     otherwise as UTC time (UTC 'yyyymmddHHMMSS.mmmZ')."
 
     self printGeneralizedOn:aStream isLocal:isLocal short:false
 
@@ -2471,28 +2471,31 @@
 printGeneralizedOn:aStream isLocal:isLocal short:shortFormat
     "append a representation of the receiver to aStream in a general format,
      top-down, without separators;
-	long format:  'yyyymmddHHMMSS.mmm+0100'
-	short format: 'yymmddHHMMSS.mmm+0100'
+        long format:  'yyyymmddHHMMSS.mmm+0100'
+        short format: 'yymmddHHMMSS.mmm+0100'
+     Using the short format is strictly discouraged!!
 
      This format is used for the ASN.1 GeneralizedTime and UTCTime
      as defined in X.208 Sec. 33, so read this before changing the output format.
-     The short format is no longer recommended.
-
-     If isLocal is true, represent as local time, otherwise add UTC time offset."
+
+     If isLocal is true, represent as local time (Local 'yyyymmddHHMMSS.mmm+0100'), 
+     otherwise as UTC time (UTC 'yyyymmddHHMMSS.mmmZ')."
 
     |t off|
 
     isLocal ifTrue:[
-	t := self timeInfo.
+        t := self timeInfo.
+        off := t utcOffset.
     ] ifFalse:[
-	t := self asUtcTimestamp timeInfo.
+        t := self asUtcTimestamp timeInfo.
+        off := 0.
     ].
 
     shortFormat ifTrue:[
-	self assert:(t year between:1951 and:2049).
-	(t year \\ 100) printOn:aStream leftPaddedTo:2 with:$0.
+        self assert:(t year between:1951 and:2049).
+        (t year \\ 100) printOn:aStream leftPaddedTo:2 with:$0.
     ] ifFalse:[
-	t year    printOn:aStream leftPaddedTo:4 with:$0.
+        t year    printOn:aStream leftPaddedTo:4 with:$0.
     ].
     t month   printOn:aStream leftPaddedTo:2 with:$0.
     t day     printOn:aStream leftPaddedTo:2 with:$0.
@@ -2502,23 +2505,18 @@
     aStream nextPut:$..
     t milliseconds printOn:aStream leftPaddedTo:3 with:$0.
 
-    isLocal ifFalse:[
-	"/ this should be printed as non-local-time
-
-	off := t utcOffset.
-	(self isUtcTimestamp or:[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.
-	].
+    (self isUtcTimestamp or:[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.
     ].
 
     "
@@ -2529,7 +2527,9 @@
      Date today printOn:Transcript. Transcript cr.
 
      Timestamp now printGeneralizedOn:Transcript isLocal:false short:false. Transcript cr.
+     Timestamp now printGeneralizedOn:Transcript isLocal:true short:false. Transcript cr.
      UtcTimestamp now printGeneralizedOn:Transcript isLocal:false short:false. Transcript cr.
+     UtcTimestamp now printGeneralizedOn:Transcript isLocal:true short:false. Transcript cr.
 
      Date today asTimestamp printGeneralizedOn:Transcript. Transcript cr.
      Date today printOn:Transcript. Transcript cr.
@@ -2980,6 +2980,7 @@
     "
 ! !
 
+
 !Timestamp methodsFor:'testing'!
 
 isLocalTimestamp
@@ -3958,11 +3959,11 @@
 !Timestamp class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.220 2015-06-06 12:57:00 cg Exp $'
+    ^ '$Header$'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.220 2015-06-06 12:57:00 cg Exp $'
+    ^ '$Header$'
 ! !