readFrom; houtr:minutes:seconds: fixed
authorclaus
Mon, 06 Feb 1995 03:56:44 +0100
changeset 239 472f810ecccf
parent 238 a4a50c67aeae
child 240 f5ff68fffb92
readFrom; houtr:minutes:seconds: fixed
Time.st
--- a/Time.st	Mon Feb 06 03:27:23 1995 +0100
+++ b/Time.st	Mon Feb 06 03:56:44 1995 +0100
@@ -21,7 +21,7 @@
 COPYRIGHT (c) 1989 by Claus Gittinger
 	      All Rights Reserved
 
-$Header: /cvs/stx/stx/libbasic/Time.st,v 1.12 1995-02-02 12:22:51 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Time.st,v 1.13 1995-02-06 02:56:44 claus Exp $
 '!
 
 !Time class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libbasic/Time.st,v 1.12 1995-02-02 12:22:51 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Time.st,v 1.13 1995-02-06 02:56:44 claus Exp $
 "
 !
 
@@ -64,35 +64,67 @@
     "
 !
 
-fromOSTime:osTime
-    "return a time, representing the time given by the operatingSystem time"
+hour:h minutes:m seconds:s
+    "return an instance of Time representing the given values"
+
+    | seconds |
+
+    "have to subtract 3600; unix time starts at 1'o clock"
+    seconds := (h * 60 * 60 ) + (m * 60) + s - 3600.
 
-    ^ self basicNew setSecondsLow:(osTime at:1) and:(osTime at:2)
-! !
+    ^ self basicNew setSeconds:seconds.
 
-!Time class methodsFor:'ST-80 compatibility'!
+    "
+     Time hour:2 minutes:33 seconds:0 
+    "
+!
 
-fromSeconds: seconds
+fromSeconds:seconds
     "return a Time that is constructed from seconds since midnight."
 
-   ^ (self new setSeconds:seconds) subtractTime:60*60
-
-    "midnight starts at 1:00:00 in ST/X for some strange reason"
+    "have to subtract 3600; unix time starts at 1'o clock"
+   ^ self basicNew setSeconds:seconds-3600
 
     "
      Time fromSeconds:0
     "
 !
 
-hour:h minutes:m seconds:s
-    "return an instance of Time representing the given values"
+fromOSTime:osTime
+    "return a time, representing the time given by the operatingSystem time"
 
-    | seconds |
+    ^ self basicNew setSecondsLow:(osTime at:1) and:(osTime at:2)
+!
+
+readFrom:aStream onError:exceptionBlock
+    "return a new Time, reading a printed representation from aStream."
+
+    |hour min sec|
 
-    seconds := (h * 60 * 60 )+ (m * 60) + s.
+    hour := Integer readFrom:aStream onError:[^ exceptionBlock value].
+    [aStream peek isDigit] whileFalse:[aStream next].
+    min := Integer readFrom:aStream onError:[^ exceptionBlock value].
+    [aStream peek isDigit] whileFalse:[aStream next].
+    sec := Integer readFrom:aStream onError:[^ exceptionBlock value].
+    [aStream peek == Character space] whileTrue:[aStream next].
+    (aStream peek == $p) ifTrue:[
+	"pm"
+	hour := hour + 12
+    ].
+    ^ self hour:hour minutes:min seconds:sec
 
-    ^ self basicNew setSeconds:seconds.
-!
+    "
+     Time readFromString:'18:22:00'    
+     Time readFromString:'14:00:11'    
+     Time readFromString:'7:00:11'     
+     Time readFromString:'6:22:00 pm'   
+     Time readFromString:'2:00:11 pm'  
+     Time readFromString:'7:00:11 am'  
+    "
+
+! !
+
+!Time class methodsFor:'ST-80 compatibility'!
 
 totalSeconds
     ^ self secondClock