Time.st
changeset 3478 3f1a83b35865
parent 3477 ac8613ab02c9
child 3481 1da093bda862
--- a/Time.st	Fri May 22 12:55:12 1998 +0200
+++ b/Time.st	Fri May 22 13:12:09 1998 +0200
@@ -111,9 +111,21 @@
 
             [str peek == Character space] whileTrue:[str next].
             (str peek == $p) ifTrue:[
+                hour > 12 ifTrue:[ex value].
+                hour == 0 ifTrue:[ex value].
+
                 "pm"
-                hour := hour + 12
-            ].
+                hour ~~ 12 ifTrue:[
+                    hour := hour + 12
+                ]
+            ] ifFalse:[
+                (str peek == $a) ifTrue:[
+                    hour >= 12 ifTrue:[ex value].
+                    hour == 24 ifTrue:[
+                        hour := 0.
+                    ]
+                ]
+            ]
         ].
         ^ self basicNew setHour:hour minutes:min seconds:sec
     ]
@@ -122,9 +134,19 @@
      Time readFrom:'18:22:00'    
      Time readFrom:'14:00:11'    
      Time readFrom:'7:00:11'     
+     Time readFrom:'24:00:00'     
+     Time readFrom:'0:00:00'     
+     Time readFrom:'12:00:00'     
+     Time readFrom:'0:00:00'     
      Time readFrom:'6:22:00 pm'   
      Time readFrom:'2:00:11 pm'  
      Time readFrom:'7:00:11 am'  
+     Time readFrom:'12:00:00 am'  
+     Time readFrom:'0:00:00 am'  
+     Time readFrom:'24:00:00 am'  
+     Time readFrom:'12:00:00 pm'  
+     Time readFrom:'0:00:00 pm'   - invalid
+     Time readFrom:'24:00:00 pm'  
     "
 
     "Modified: 8.10.1996 / 19:32:11 / cg"
@@ -250,24 +272,21 @@
 
     |h m s ampm|
 
-    ampm := ' am'.
     h := self hours.
 
     "/ 0 -> 12 am
     "/ 12 -> 12 pm
 
-    h > 12 ifTrue:[
-        h := h - 12.
-        ampm := ' pm'.
+    h // 12 == 0 ifTrue:[
+        ampm := ' am'.
     ] ifFalse:[
-        h == 0 ifTrue:[
-            h := 12
-        ] ifFalse:[
-            h == 12 ifTrue:[
-                ampm := ' pm'
-            ]
-        ]
+        ampm := ' pm'.
     ].
+
+    h == 0 ifFalse:[
+        h := h - 1 \\ 12 + 1.
+    ].
+
     h printOn:aStream.
     aStream nextPut:$:.
     m := self minutes.
@@ -285,6 +304,9 @@
      (Time hour:24 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
      (Time hour:12 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
      (Time hour:0 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
+     0 to:24 do:[:h |
+         (Time hour:h minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
+     ]
     "
 !
 
@@ -404,5 +426,5 @@
 !Time class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.32 1998-05-22 10:55:12 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.33 1998-05-22 11:12:09 cg Exp $'
 ! !