Time.st
changeset 11308 fa79c438bb34
parent 11151 61a33963c219
child 11809 efca8cccc66b
child 17711 39faaaf888b4
equal deleted inserted replaced
11307:98d31040610f 11308:fa79c438bb34
   149     "return a new Time, reading a printed representation from aStream.
   149     "return a new Time, reading a printed representation from aStream.
   150      If no am/pm follows the time, the string is interpreted as 
   150      If no am/pm follows the time, the string is interpreted as 
   151      either 24 hour format or being am."
   151      either 24 hour format or being am."
   152 
   152 
   153     ^ [
   153     ^ [
   154         |str hour min sec|
   154         |str hour min sec peekC|
   155 
   155 
   156         str := aStringOrStream readStream.
   156         str := aStringOrStream readStream.
   157 
   157 
   158         hour := Integer readFrom:str.
   158         hour := Integer readFrom:str.
   159         (hour between:0 and:24) ifFalse:[^ exceptionBlock value].
   159         (hour between:0 and:24) ifFalse:[^ exceptionBlock value].
   160 
   160 
   161         min := 0.
   161         min := 0.
   162         sec := 0.
   162         sec := 0.
   163         str atEnd ifFalse:[
   163         str atEnd ifFalse:[
   164             (str peek == $:) ifTrue:[
   164             peekC := str peek.
       
   165             (peekC == $:) ifTrue:[
   165                 str next.
   166                 str next.
   166                 min := Integer readFrom:str.
   167                 min := Integer readFrom:str.
   167                 (min between:0 and:59) ifFalse:[^ exceptionBlock value].
   168                 (min between:0 and:59) ifFalse:[^ exceptionBlock value].
   168 
   169 
   169                 (str peek == $:) ifTrue:[
   170                 (str peek == $:) ifTrue:[
   170                     str next.
   171                     str next.
   171                     sec := Integer readFrom:str.
   172                     sec := Integer readFrom:str.
   172                     (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
   173                     (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
   173                 ].
   174                 ].
       
   175                 peekC := str peek.
   174             ].
   176             ].
   175             [str peek == Character space] whileTrue:[str next].
   177             [peekC == Character space] whileTrue:[str next. peekC := str peek].
   176             (str peek == $p or:[str peek == $P]) ifTrue:[
   178             (peekC == $p or:[peekC == $P]) ifTrue:[
   177                 str next.
   179                 str next.
   178                 (str peek == $m or:[str peek == $M]) ifTrue:[
   180                 (str peek == $m or:[str peek == $M]) ifTrue:[
   179                     str next
   181                     str next
   180                 ].
   182                 ].
   181                 (hour <= 0 or:[hour > 12]) ifTrue:[^ exceptionBlock value].
   183                 (hour <= 0 or:[hour > 12]) ifTrue:[^ exceptionBlock value].
   182 
   184 
   183                 "pm"
   185                 "pm"
   184                 hour ~~ 12 ifTrue:[
   186                 hour ~~ 12 ifTrue:[
   185                     hour := hour + 12
   187                     hour := hour + 12
   186                 ]
   188                 ].
       
   189                 peekC := str peek
   187             ] ifFalse:[
   190             ] ifFalse:[
   188                 (str peek == $a or:[str peek == $A]) ifTrue:[
   191                 (peekC == $a or:[peekC == $A]) ifTrue:[
   189                     str next.
   192                     str next.
   190                     (str peek == $m or:[str peek == $M]) ifTrue:[
   193                     (str peek == $m or:[str peek == $M]) ifTrue:[
   191                         str next
   194                         str next
   192                     ].
   195                     ].
   193                     hour == 12 ifTrue:[
   196                     hour == 12 ifTrue:[
   194                         hour := 0.
   197                         hour := 0.
   195                     ].
   198                     ].
   196                     hour > 12 ifTrue:[^ exceptionBlock value].
   199                     hour > 12 ifTrue:[^ exceptionBlock value].
   197                 ]
   200                     peekC := str peek
       
   201                 ] ifFalse:[
       
   202                     peekC notNil ifTrue:[
       
   203                         peekC isSeparator ifFalse:[^ exceptionBlock value].
       
   204                     ]
       
   205                 ].
   198             ]
   206             ]
   199         ].
   207         ].
   200         self basicNew setHours:hour minutes:min seconds:sec
   208         self basicNew setHours:hour minutes:min seconds:sec
   201     ] on:Error do:exceptionBlock.
   209     ] on:Error do:exceptionBlock.
   202 
   210 
   714 ! !
   722 ! !
   715 
   723 
   716 !Time class methodsFor:'documentation'!
   724 !Time class methodsFor:'documentation'!
   717 
   725 
   718 version
   726 version
   719     ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.83 2008-09-06 10:45:31 cg Exp $'
   727     ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.84 2008-11-04 13:51:21 cg Exp $'
   720 ! !
   728 ! !