--- a/Time.st Fri May 22 12:47:19 1998 +0200
+++ b/Time.st Fri May 22 12:55:12 1998 +0200
@@ -96,6 +96,7 @@
str := aStringOrStream readStream.
ex := [^ exceptionBlock value].
+
hour := Integer readFrom:str onError:ex.
(hour between:0 and:24) ifFalse:[ex value].
@@ -103,14 +104,16 @@
min := Integer readFrom:str onError:ex.
(min between:0 and:59) ifFalse:[ex value].
- [str peek isDigit] whileFalse:[str next].
- sec := Integer readFrom:str onError:ex.
- (sec between:0 and:59) ifFalse:[ex value].
+ str atEnd ifFalse:[
+ [str peek isDigit] whileFalse:[str next].
+ sec := Integer readFrom:str onError:ex.
+ (sec between:0 and:59) ifFalse:[ex value].
- [str peek == Character space] whileTrue:[str next].
- (str peek == $p) ifTrue:[
- "pm"
- hour := hour + 12
+ [str peek == Character space] whileTrue:[str next].
+ (str peek == $p) ifTrue:[
+ "pm"
+ hour := hour + 12
+ ].
].
^ self basicNew setHour:hour minutes:min seconds:sec
]
@@ -247,13 +250,23 @@
|h m s ampm|
+ ampm := ' am'.
h := self hours.
+
+ "/ 0 -> 12 am
+ "/ 12 -> 12 pm
+
h > 12 ifTrue:[
- h := h - 12.
+ h := h - 12.
+ ampm := ' pm'.
] ifFalse:[
- h < 1 ifTrue:[
- h := 12
- ]
+ h == 0 ifTrue:[
+ h := 12
+ ] ifFalse:[
+ h == 12 ifTrue:[
+ ampm := ' pm'
+ ]
+ ]
].
h printOn:aStream.
aStream nextPut:$:.
@@ -264,15 +277,14 @@
s := self seconds.
(s < 10) ifTrue:[aStream nextPut:$0].
s printOn:aStream.
- h >= 12 ifTrue:[
- ampm := ' am'
- ] ifFalse:[
- ampm := ' pm'
- ].
aStream nextPutAll:ampm
"
Time now print12HourFormatOn:Transcript. Transcript cr
+ (Time now subtractHours:12) print12HourFormatOn:Transcript. Transcript cr
+ (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
"
!
@@ -345,6 +357,10 @@
"Modified: 1.7.1996 / 15:21:06 / cg"
!
+getMilliseconds
+ ^ self getSeconds * 1000
+!
+
getSeconds
^ timeEncoding
!
@@ -352,13 +368,23 @@
setHour:h minutes:m seconds:s
"set my time given individual values"
- timeEncoding := ((h\\24) * 60 * 60 ) + (m * 60) + s.
+ self setSeconds:(((h\\24) * 60 * 60 ) + (m * 60) + s).
+!
+
+setMilliseconds:millis
+ "set my time given milliseconds since midnight"
+
+ self setSeconds:(millis // 1000)
!
setSeconds:secs
"set my time given seconds since midnight"
- timeEncoding := secs
+ secs < 0 ifTrue:[
+ timeEncoding := (24 * 3600) - (secs negated \\ (24 * 3600))
+ ] ifFalse:[
+ timeEncoding := secs
+ ]
!
timeEncoding
@@ -378,5 +404,5 @@
!Time class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.31 1997-06-20 15:29:38 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.32 1998-05-22 10:55:12 cg Exp $'
! !