--- a/Time.st Thu Nov 08 16:23:13 2001 +0100
+++ b/Time.st Thu Nov 08 17:03:06 2001 +0100
@@ -10,16 +10,16 @@
hereby transferred.
"
-"{ Package: 'stx:libbasic' }"
+"{ Package: '__NoProject__' }"
-AbstractTime subclass:#Time
- instanceVariableNames:'timeEncoding'
+Time subclass:#TimeDuration
+ instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'Magnitude-General'
!
-!Time class methodsFor:'documentation'!
+!TimeDuration class methodsFor:'documentation'!
copyright
"
@@ -67,565 +67,81 @@
"
! !
-!Time class methodsFor:'instance creation'!
-
-fromSeconds:secondsSinceMidnight
- "return a new Time, which represents the number of seconds since midNight.
- Be careful, time wraps - if the number of seconds exceeds the number of seconds
- in a day, a time relative to another days midnight is returned.
- (i.e. (Time fromSeconds:0) = (Time fromSeconds:24*3600)"
-
- |s|
-
- s := secondsSinceMidnight \\ (3600 * 24).
- ^ self
- hours:(s // 3600)
- minutes:((s \\ 3600) // 60)
- seconds:((s \\ 3600) \\ 60)
-
- "
- Time fromSeconds:0
- Time fromSeconds:3675
- Time fromSeconds:36000
- Time fromSeconds:72000
- Time fromSeconds:96000
- "
-
- "Modified: 8.10.1996 / 19:32:11 / cg"
+!TimeDuration class methodsFor:'instance creation'!
-
-
-!
-
-hour:h minutes:m seconds:s
- "return an instance of Time representing the given time.
- See also Time now / Date today / AbsoluteTime now.
- Obsolete: please use #hours:minutes:seconds:"
-
- <resource:#obsolete>
-
- self obsoleteMethodWarning:'use hours:minutes:seconds:'.
-
- ^ self hours:h minutes:m seconds:s
-
- "
- Time hours:2 minutes:33 seconds:0
- Time hours:0 minutes:0 seconds:0
- Time hours:24 minutes:0 seconds:0
- Time hours23 minutes:59 seconds:59
- "
-
- "Modified: 19.4.1996 / 15:32:40 / cg"
-!
-
-hours:h minutes:m seconds:s
+hours:h minutes:m seconds:s millis:millis
"return an instance of Time representing the given time.
See also Time now / Date today / AbsoluteTime now."
- ^ self basicNew setHours:h minutes:m seconds:s
+ ^ self basicNew setHours:h minutes:m seconds:s millis:millis
"
- Time hours:2 minutes:33 seconds:0
- Time hours:0 minutes:0 seconds:0
- Time hours:24 minutes:0 seconds:0
- Time hours:23 minutes:59 seconds:59
+ TimeDuration hours:2 minutes:33 seconds:0 millis:123
"
-
- "Modified: 19.4.1996 / 15:32:40 / cg"
-!
-
-readFrom:aStringOrStream onError:exceptionBlock
- "return a new Time, reading a printed representation from aStream.
- If no am/pm follows the time, the string is interpreted as
- either 24 hour format or being am."
-
- |newTime|
-
- ErrorSignal handle:[:ex |
- ^ exceptionBlock value
- ] do:[
- |str hour min sec|
-
- str := aStringOrStream readStream.
-
- hour := Integer readFrom:str.
- (hour between:0 and:24) ifFalse:[^ exceptionBlock value].
-
- min := 0.
- sec := 0.
- str atEnd ifFalse:[
- (str peek == $:) ifTrue:[
- str next.
- min := Integer readFrom:str.
- (min between:0 and:59) ifFalse:[^ exceptionBlock value].
-
- (str peek == $:) ifTrue:[
- str next.
- sec := Integer readFrom:str.
- (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
- ].
- ].
- [str peek == Character space] whileTrue:[str next].
- (str peek == $p or:[str peek == $P]) ifTrue:[
- str next.
- (str peek == $m or:[str peek == $M]) ifTrue:[
- str next
- ].
- (hour <= 0 or:[hour > 12]) ifTrue:[^ exceptionBlock value].
-
- "pm"
- hour ~~ 12 ifTrue:[
- hour := hour + 12
- ]
- ] ifFalse:[
- (str peek == $a or:[str peek == $A]) ifTrue:[
- str next.
- (str peek == $m or:[str peek == $M]) ifTrue:[
- str next
- ].
- hour >= 12 ifTrue:[^ exceptionBlock value].
- hour == 24 ifTrue:[
- hour := 0.
- ]
- ]
- ]
- ].
- newTime := self basicNew setHours:hour minutes:min seconds:sec
- ].
- ^ newTime
-
- "
- Time readFrom:'0:00'
- Time readFrom:'2:00'
- Time readFrom:'12:00'
- Time readFrom:'14:00'
- Time readFrom:'23:00'
- Time readFrom:'24:00'
- Time readFrom:'2:30 am'
- Time readFrom:'2:30 pm'
- Time readFrom:'14'
- Time readFrom:'2 am'
- Time readFrom:'2 pm'
-
- 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"
! !
-!Time class methodsFor:'format strings'!
+!TimeDuration class methodsFor:'format strings'!
formatString12us
"return the format string used to format US times (and other areas)"
- ^ '%u:%m:%s %a'
+ ^ '%u:%m:%s.%i %a'
!
formatString24
"return the format string used to format european times (and other areas)"
- ^ '%h:%m:%s'
+ ^ '%h:%m:%s.%i'
! !
-!Time methodsFor:'Compatibility - Squeak'!
-
-intervalString
- "Treat the time as a difference.
- Give it in hours and minutes with two digits of accuracy."
-
- |hours minutes seconds hh mm ss |
-
- hours := self hours.
- minutes := self minutes.
- seconds := self seconds.
- hh := hours = 0 ifTrue: [''] ifFalse: [' ', hours printString, ' hours'].
- mm := minutes = 0 ifTrue: [''] ifFalse: [' ', minutes printString, ' minutes'].
- ss := seconds = 0 ifTrue: [''] ifFalse: [' ', seconds printString, ' seconds'].
- hh size > 0 ifTrue: [ss := ''].
- ^ hh, mm, ss
-
- "
- (Time fromSeconds:3600) intervalString
- (Time fromSeconds:3605) intervalString
- (Time fromSeconds:5) intervalString
- (Time fromSeconds:65) intervalString
- "
-!
-
-print24:prnt24Format showSeconds:doSeconds on:aStream
- "print me either US or 24hr format, optionally with
- seconds on a stream"
-
- |format|
-
- prnt24Format ifTrue:[
- doSeconds ifTrue:[
- format := '%h:%m:%s'
- ] ifFalse:[
- format := '%h:%m'
- ].
- ] ifFalse:[
- "/ US format
- doSeconds ifTrue:[
- format := '%u:%m:%s %a'
- ] ifFalse:[
- format := '%u:%m %a'
- ].
- ].
- ^ self
- printOn:aStream
- format:format.
-
- "
- Time now print24:true showSeconds:true on:Transcript. Transcript cr.
- Time now print24:false showSeconds:true on:Transcript. Transcript cr.
- Time now print24:true showSeconds:false on:Transcript. Transcript cr.
- Time now print24:false showSeconds:false on:Transcript. Transcript cr.
- "
-! !
-
-!Time methodsFor:'accessing'!
-
-day
- "catch day access - Time does not know about it"
-
- ^ self shouldNotImplement
-!
-
-hours
- "return the number of hours since midnight (i.e. 0..23)"
-
- ^ timeEncoding // 3600
-
- "
- Time now hours
- "
-!
+!TimeDuration methodsFor:'accessing'!
milliseconds
- "time does not keep milliseconds
- - for compatibility with absoluteTime"
-
- ^ 0
-!
-
-minutes
- "return the number of minutes within the hour (i.e. 0..59)"
-
- ^ (timeEncoding \\ 3600) // 60
-
- "
- Time now minutes
- "
-!
-
-month
- "catch month access - Time does not know about it"
-
- ^ self shouldNotImplement
-!
-
-seconds
- "return the number of seconds within the minute (i.e. 0..59)"
-
- ^ (timeEncoding \\ 3600) \\ 60
-
- "
- Time now seconds
- "
-!
-
-year
- "catch year access - Time does not know about it"
-
- ^ self shouldNotImplement
+ ^ timeEncoding \\ 1000
! !
-!Time methodsFor:'comparing'!
-
-< aTime
- "return true if the receiver is before the argument"
-
- ^ timeEncoding < aTime timeEncoding
-!
-
-= aTime
- "return true if the argument, aTime represents the same timeOfDay"
-
- aTime class == self class ifTrue:[
- ^ timeEncoding == aTime timeEncoding
- ].
- (aTime species == self species) ifFalse:[^ false].
- ^ self asSeconds == aTime asSeconds
-!
-
-> aTime
- "return true if the receiver is before the argument"
-
- ^ timeEncoding > aTime timeEncoding
-!
-
-hash
- "return an integer useful for hashing on times"
-
- ^ timeEncoding
-! !
-
-!Time methodsFor:'converting'!
-
-asAbsoluteTime
- "return an AbsoluteTime object from the receiver.
- The date components are taken from today."
-
- |today|
-
- today := Date today.
- ^ AbsoluteTime year:today year month:today month day:today day
- hour:self hours minute:self minutes second:self seconds
- "
- Time now asAbsoluteTime
- "
-
- "Modified: / 13.7.1999 / 12:32:08 / stefan"
-!
-
-asSeconds
- "return the number of seconds elapsed since midnight"
-
- ^ timeEncoding
-
- "
- Time now asSeconds
- "
-!
+!TimeDuration methodsFor:'converting'!
asTime
"return a Time object from the receiver - thats the receiver."
- ^ self
+ ^ Time hours:(self hours) minutes:(self minutes) seconds:(self seconds)
! !
-!Time methodsFor:'printing & storing'!
-
-print12HourFormatOn:aStream
- "append a printed representation of the receiver to aStream.
- Format is hh:mm:ss am/pm (i.e. 12-hour american format)."
-
- ^ self
- printOn:aStream
- format:(self class formatString12us)
-
-"/ |h m s ampm|
-"/
-"/ h := self hours.
-"/
-"/ "/ 0 -> 12 am
-"/ "/ 12 -> 12 pm
-"/
-"/ h // 12 == 0 ifTrue:[
-"/ ampm := ' am'.
-"/ ] ifFalse:[
-"/ ampm := ' pm'.
-"/ ].
-"/
-"/ h == 0 ifFalse:[
-"/ h := h - 1 \\ 12 + 1.
-"/ ].
-"/
-"/ h printOn:aStream.
-"/ aStream nextPut:$:.
-"/ m := self minutes.
-"/ (m < 10) ifTrue:[aStream nextPut:$0].
-"/ m printOn:aStream.
-"/ aStream nextPut:$:.
-"/ s := self seconds.
-"/ (s < 10) ifTrue:[aStream nextPut:$0].
-"/ s printOn:aStream.
-"/ 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
- 0 to:24 do:[:h |
- (Time hour:h minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
- ]
- "
-!
-
-print24HourFormatOn:aStream
- "append a printed representation of the receiver to aStream.
- Format is hh:mm:ss (i.e. 24-hour european format)."
-
- ^ self
- printOn:aStream
- format:(self class formatString24).
-
-"/ |h m s|
-"/
-"/ h := self hours.
-"/ (h < 10) ifTrue:[aStream nextPut:$0].
-"/ h printOn:aStream.
-"/ aStream nextPut:$:.
-"/ m := self minutes.
-"/ (m < 10) ifTrue:[aStream nextPut:$0].
-"/ m printOn:aStream.
-"/ aStream nextPut:$:.
-"/ s := self seconds.
-"/ (s < 10) ifTrue:[aStream nextPut:$0].
-"/ s printOn:aStream
-
- "
- Time now print24HourFormatOn:Transcript. Transcript cr
- "
-!
-
-printOn:aStream
- "append a user printed representation of the receiver to aStream.
- The format is suitable for a human - not meant to be read back.
-
- Format is hh:mm:ss either in 12-hour or 24-hour format.
- depending on the setting of LanguageTerritory.
- I dont know what ST-80 does here (12-hour format ?)"
-
- LanguageTerritory == #us ifTrue:[
- self print12HourFormatOn:aStream
- ] ifFalse:[
- self print24HourFormatOn:aStream
- ]
-
- "
- Time now printOn:Transcript. Transcript cr
- "
-
- "Modified: 22.2.1996 / 16:58:30 / cg"
-!
-
-printString12HourFormat
- "return a printed representation in 12 hour format"
-
- ^ self printStringFormat:(self class formatString12us)
-
- "
- Time now printString12HourFormat
- "
-!
-
-printString24HourFormat
- "return a printed representation in 24 hour format"
-
- ^ self printStringFormat:(self class formatString24)
-
- "
- Time now printString24HourFormat
- "
-
-!
-
-shortPrintString
- "dummy - for now"
-
- ^ self printString
-
- "Created: 20.6.1997 / 17:17:01 / cg"
-! !
-
-!Time methodsFor:'private'!
-
-fromOSTime:osTime
- "set my time, given an osTime"
-
- |h m s|
-
- OperatingSystem computeTimePartsOf:osTime for:[
- :hours :minutes :secs :millis |
-
- h := hours.
- m := minutes.
- s := secs.
- ].
- self setHours:h minutes:m seconds:s
-
- "Modified: 1.7.1996 / 15:21:06 / cg"
-!
+!TimeDuration methodsFor:'private'!
getMilliseconds
"return the number of milliseconds since midnight"
- ^ self getSeconds * 1000
+ ^ timeEncoding
!
getSeconds
"return the number of seconds since midnight"
- ^ timeEncoding
+ ^ timeEncoding // 1000
!
-setHours:h minutes:m seconds:s
+setHours:h minutes:m seconds:s millis:millis
"set my time given individual values"
- self setSeconds:(((h\\24) * 60 * 60 ) + (m * 60) + s).
+ self setMilliseconds:(((h\\24) * 60 * 60 ) + (m * 60) + s) * 1000 + millis.
!
setMilliseconds:millis
"set my time given milliseconds since midnight"
- self setSeconds:(millis // 1000)
+ timeEncoding := millis
!
setSeconds:secs
"set my time given seconds since midnight"
- secs < 0 ifTrue:[
- timeEncoding := (24 * 3600) - (secs negated \\ (24 * 3600))
- ] ifFalse:[
- timeEncoding := secs
- ].
- timeEncoding > (24 * 3600) ifTrue:[
- timeEncoding := timeEncoding \\ (24 * 3600).
- ]
-
- "
- Time now seconds
- Time now timeEncoding
- (Time now addDays:5) seconds
- (Time now addDays:5) timeEncoding
- "
-!
-
-timeEncoding
- "the internal encoding is stricktly private,
- and should not be used outside."
-
- ^ timeEncoding
-!
-
-timeEncoding:encoding
- "the internal encoding is stricktly private,
- and should not be used outside."
-
- timeEncoding := encoding
+ self setMilliseconds:(secs * 1000).
! !
-!Time class methodsFor:'documentation'!
+!TimeDuration class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.49 2001-09-26 13:10:40 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.50 2001-11-08 16:03:06 md Exp $'
! !