1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
1
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
32
|
13 |
AbsoluteTime subclass:#Time
|
|
14 |
instanceVariableNames:''
|
1
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Magnitude-General'
|
|
18 |
!
|
|
19 |
|
|
20 |
Time comment:'
|
5
|
21 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
1
|
22 |
All Rights Reserved
|
88
|
23 |
'!
|
1
|
24 |
|
88
|
25 |
!Time class methodsFor:'documentation'!
|
|
26 |
|
|
27 |
copyright
|
|
28 |
"
|
|
29 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
30 |
All Rights Reserved
|
|
31 |
|
|
32 |
This software is furnished under a license and may be used
|
|
33 |
only in accordance with the terms of that license and with the
|
|
34 |
inclusion of the above copyright notice. This software may not
|
|
35 |
be provided or otherwise made available to, or used by, any
|
|
36 |
other person. No title to or ownership of the software is
|
|
37 |
hereby transferred.
|
|
38 |
"
|
|
39 |
!
|
|
40 |
|
|
41 |
version
|
|
42 |
"
|
|
43 |
$Header: /cvs/stx/stx/libbasic/Time.st,v 1.9 1994-06-02 16:22:29 claus Exp $
|
|
44 |
"
|
|
45 |
!
|
|
46 |
|
|
47 |
documentation
|
|
48 |
"
|
|
49 |
Instances of time represent a particular time-of-day.
|
|
50 |
"
|
|
51 |
! !
|
1
|
52 |
|
|
53 |
!Time class methodsFor:'instance creation'!
|
|
54 |
|
|
55 |
now
|
|
56 |
"return an instance of Time representing this moment"
|
|
57 |
|
|
58 |
^ self basicNew setSecondsLow:(OperatingSystem getTimeLow)
|
|
59 |
and:(OperatingSystem getTimeHi)
|
62
|
60 |
!
|
|
61 |
|
|
62 |
fromOSTime:osTime
|
|
63 |
"return a time, representing the time given by the operatingSystem time"
|
|
64 |
|
88
|
65 |
^ self basicNew setSecondsLow:(osTime at:1) and:(osTime at:2)
|
1
|
66 |
! !
|
|
67 |
|
|
68 |
!Time class methodsFor:'ST-80 compatibility'!
|
|
69 |
|
77
|
70 |
fromSeconds: seconds
|
|
71 |
"return a Time that is constructed from seconds since midnight."
|
|
72 |
|
|
73 |
^ (self new setSeconds:seconds) subtractTime: "60*60" 3600
|
|
74 |
|
|
75 |
"midnight starts at 1:00:00 in ST/X for some strange reason"
|
|
76 |
!
|
|
77 |
|
1
|
78 |
totalSeconds
|
|
79 |
^ self secondClock
|
|
80 |
! !
|
|
81 |
|
77
|
82 |
|
|
83 |
!Time methodsFor:'ST-80 compatibility'!
|
|
84 |
|
|
85 |
asSeconds
|
|
86 |
"Answer the number of seconds elapsed since midnight"
|
|
87 |
|
|
88 |
^ ( 3600 * (self hourInDay) )
|
|
89 |
+ ( 60 * (self minuteInDay) )
|
|
90 |
+ (self secondInDay)
|
|
91 |
!
|
|
92 |
|
|
93 |
hours
|
|
94 |
"Answer the number of hours"
|
|
95 |
|
|
96 |
^self hourInDay
|
|
97 |
!
|
|
98 |
|
|
99 |
minutes
|
|
100 |
"Answer the number of minutes"
|
|
101 |
|
|
102 |
^self minuteInDay
|
|
103 |
!
|
|
104 |
|
|
105 |
seconds
|
|
106 |
"Answer the number of seconds"
|
|
107 |
|
|
108 |
^self secondInDay
|
|
109 |
! !
|
|
110 |
|
1
|
111 |
!Time methodsFor:'comparing'!
|
|
112 |
|
|
113 |
> aTime
|
|
114 |
(aTime isMemberOf:Time) ifTrue:[
|
|
115 |
(secondsHi > aTime secondsHi) ifTrue:[^ true].
|
|
116 |
(secondsHi < aTime secondsHi) ifTrue:[^ false].
|
|
117 |
(secondsLow > aTime secondsLow) ifTrue:[^ true].
|
|
118 |
^ false
|
|
119 |
].
|
|
120 |
^ self getSeconds > aTime getSeconds
|
|
121 |
!
|
|
122 |
|
|
123 |
< aTime
|
|
124 |
(aTime isMemberOf:Time) ifTrue:[
|
|
125 |
(secondsHi < aTime secondsHi) ifTrue:[^ true].
|
|
126 |
(secondsHi > aTime secondsHi) ifTrue:[^ false].
|
|
127 |
(secondsLow < aTime secondsLow) ifTrue:[^ true].
|
|
128 |
^ false
|
|
129 |
].
|
|
130 |
^ self getSeconds < aTime getSeconds
|
|
131 |
!
|
|
132 |
|
|
133 |
= aTime
|
|
134 |
(aTime isMemberOf:Time) ifTrue:[
|
|
135 |
^ ((secondsLow == aTime secondsLow) and:[secondsHi == aTime secondsHi])
|
|
136 |
].
|
|
137 |
^ self getSeconds = aTime getSeconds
|
|
138 |
! !
|
|
139 |
|
|
140 |
!Time methodsFor:'printing'!
|
|
141 |
|
62
|
142 |
printOn:aStream
|
|
143 |
aStream nextPutAll:self printString
|
|
144 |
!
|
|
145 |
|
1
|
146 |
printString
|
|
147 |
|aString|
|
|
148 |
|
|
149 |
OperatingSystem computeTimePartsOf:secondsLow and:secondsHi for:[
|
|
150 |
:hours :minutes :secs |
|
|
151 |
|
|
152 |
aString := hours printString , ':' .
|
|
153 |
(minutes < 10) ifTrue:[aString := aString , '0'].
|
|
154 |
aString := aString , minutes printString.
|
|
155 |
aString := aString , ':'.
|
|
156 |
(secs < 10) ifTrue:[aString := aString , '0'].
|
|
157 |
aString := aString , secs printString
|
|
158 |
].
|
|
159 |
^ aString
|
|
160 |
! !
|