class: Date
authorStefan Vogel <sv@exept.de>
Fri, 12 Sep 2014 17:16:00 +0200
changeset 16835 08f60ee0a4ed
parent 16834 496a11689ccd
child 16836 62f28e466c23
class: Date changed: #newDay:year: #readFrom:printFormat:language:onError:
Date.st
--- a/Date.st	Fri Sep 12 16:44:33 2014 +0200
+++ b/Date.st	Fri Sep 12 17:16:00 2014 +0200
@@ -337,12 +337,12 @@
     |monthAndDay|
 
     (dayInYear between:1 and:365) ifFalse:[
-        (dayInYear > 0 or:[(dayInYear == 366) and:[self leapYear:year]]) ifFalse:[
+        (dayInYear == 366 and:[self leapYear:year]) ifFalse:[
             "
              this error is triggered, when you try to create a
              day from an invalid day-in-year; 
              for example, 366 in a non-leap year.
-             I dont know, if ST-80 wraps to the next year(s) in this case.
+             I don't know, if ST-80 wraps to the next year(s) in this case.
             "
             ^ self conversionErrorSignal raiseErrorString:' - invalid day in year'.
         ]
@@ -488,83 +488,77 @@
      TODO: make this a general feature of all DateAndTime classes.
     "
 
-    |str day month year somePartAssoc|
+    |str|
 
     str := aStringOrStream readStream.
 
-    aFormatStringOrSqueakFormatArray isArray 
-        ifTrue:[
-            [
-                |arg|
-
-                arg := Array new:3.
-
-                1 to:3 do:[:i||v|
-                    [str peek isLetterOrDigit] whileFalse:[str next].
-
-                    v := (str peek isDigit) ifTrue:[Integer readFrom:str]
-                                           ifFalse:[str nextAlphaNumericWord].
-                    arg at:i put:v
-                ].
-                year := arg at:(aFormatStringOrSqueakFormatArray at:3).
-                day := arg at:(aFormatStringOrSqueakFormatArray at:1).
-                month := arg at:(aFormatStringOrSqueakFormatArray at:2).
-            ] on:Error do:[:ex| ^ exceptionBlock value].
+    [
+        |day month year|
+
+        aFormatStringOrSqueakFormatArray isArray ifTrue:[
+            |arg|
+
+            arg := Array new:3.
+
+            1 to:3 do:[:i||v|
+                [str peek isLetterOrDigit] whileFalse:[str next].
+
+                v := (str peek isDigit) ifTrue:[Integer readFrom:str]
+                                       ifFalse:[str nextAlphaNumericWord].
+                arg at:i put:v
+            ].
+            year := arg at:(aFormatStringOrSqueakFormatArray at:3).
+            day := arg at:(aFormatStringOrSqueakFormatArray at:1).
+            month := arg at:(aFormatStringOrSqueakFormatArray at:2).
         ] ifFalse:[
-            [
-                |formatStream fc c sel|
-
-                formatStream := aFormatStringOrSqueakFormatArray readStream.
-                
-                [formatStream atEnd] whileFalse:[
-                    fc := formatStream next.
-                    fc == $% ifTrue:[
-                        sel := ''.
-                        (fc := formatStream peek) notNil ifTrue:[
-                            fc = $( ifTrue:[
-                                formatStream next.
-                                sel := formatStream upTo:$)
-                            ] ifFalse:[
-                                sel := sel , (formatStream throughAnyForWhich:[:ch | ch isLetter])
-                            ]
-                        ].
-                        somePartAssoc := self readDatePartFrom:str format:sel language:languageOrNil.
-                        somePartAssoc key == #day ifTrue:[
-                            day := somePartAssoc value.
+            |formatStream fc c sel somePartAssoc|
+
+            formatStream := aFormatStringOrSqueakFormatArray readStream.
+            
+            [formatStream atEnd] whileFalse:[
+                fc := formatStream next.
+                fc == $% ifTrue:[
+                    sel := ''.
+                    (fc := formatStream peekOrNil) notNil ifTrue:[
+                        fc = $( ifTrue:[
+                            formatStream next.
+                            sel := formatStream upTo:$)
                         ] ifFalse:[
-                            somePartAssoc key == #month ifTrue:[
-                                month := somePartAssoc value.
-                            ] ifFalse:[
-                                somePartAssoc key == #year ifTrue:[
-                                    year := somePartAssoc value.
-                                ] ifFalse:[
-                                    self error:'unexpected date part'
-                                ]
-                            ]
+                            sel := sel , (formatStream throughAnyForWhich:[:ch | ch isLetter])
                         ]
+                    ].
+                    somePartAssoc := self readDatePartFrom:str format:sel language:languageOrNil.
+                    somePartAssoc key == #day ifTrue:[
+                        day := somePartAssoc value.
+                    ] ifFalse:[somePartAssoc key == #month ifTrue:[
+                        month := somePartAssoc value.
+                    ] ifFalse:[somePartAssoc key == #year ifTrue:[
+                        year := somePartAssoc value.
                     ] ifFalse:[
-                        fc == Character space ifTrue:[
-                            "/ Skip most possible separator characters 
-                            "/ (if not enought, should check for isNationalAlphaNumeric instead)
-                            [(c := str peek) isSeparator or:[ '-.:,;/\|?<>[]{}()#@!!$&^+=~*_"`' includes:c ] ] whileTrue:[ str next ].    
-                        ] ifFalse:[
-                            str skipSeparators.
-                            str next == fc ifFalse:[^ exceptionBlock value].
-                            str skipSeparators.
-                        ]
+                        self error:'unexpected date part'
+                    ]]].
+                ] ifFalse:[
+                    fc == Character space ifTrue:[
+                        "/ Skip most possible separator characters 
+                        "/ (if not enough, should check for isNationalAlphaNumeric instead)
+                        [(c := str peek) isSeparator 
+                         or:[ '-.:,;/\|?<>[]{}()#@!!$&^+=~*_"`' includes:c]] whileTrue:[str next].    
+                    ] ifFalse:[
+                        str skipSeparators.
+                        str next ~= fc ifTrue:[^ exceptionBlock value].
+                        str skipSeparators.
                     ]
-                ].
-            ] on:Error do:[:ex| ^ exceptionBlock value].
+                ]
+            ].
         ].
 
-    day isNil ifTrue:[ day := 1 ].
-    month isNil ifTrue:[ month := 1 ].
-    year isNil ifTrue:[ year := Date today year ].
-
-    (year between:0 and:99) ifTrue:[
-        year := UserPreferences current twoDigitDateHandler value:year.
-    ].
-    [
+        day isNil ifTrue:[ day := 1 ].
+        month isNil ifTrue:[ month := 1 ].
+        year isNil ifTrue:[ year := Date today year ].
+
+        (year between:0 and:99) ifTrue:[
+            year := UserPreferences current twoDigitDateHandler value:year.
+        ].
         ^ self newDay:day month:month year:year.
     ] on:Error do:[:ex| ^ exceptionBlock value].
 
@@ -3172,11 +3166,11 @@
 !Date class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.150 2014-09-12 14:44:33 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.151 2014-09-12 15:16:00 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.150 2014-09-12 14:44:33 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.151 2014-09-12 15:16:00 stefan Exp $'
 ! !