1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
159
|
3 |
All Rights Reserved
|
1
|
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
|
159
|
22 |
All Rights Reserved
|
95
|
23 |
|
239
|
24 |
$Header: /cvs/stx/stx/libbasic/Time.st,v 1.13 1995-02-06 02:56:44 claus Exp $
|
88
|
25 |
'!
|
1
|
26 |
|
88
|
27 |
!Time class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
159
|
32 |
All Rights Reserved
|
88
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
239
|
45 |
$Header: /cvs/stx/stx/libbasic/Time.st,v 1.13 1995-02-06 02:56:44 claus Exp $
|
88
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
Instances of time represent a particular time-of-day.
|
|
52 |
"
|
|
53 |
! !
|
1
|
54 |
|
|
55 |
!Time class methodsFor:'instance creation'!
|
|
56 |
|
|
57 |
now
|
|
58 |
"return an instance of Time representing this moment"
|
|
59 |
|
216
|
60 |
^ self fromOSTime:(OperatingSystem getTimeParts)
|
95
|
61 |
|
|
62 |
"
|
|
63 |
Time now
|
|
64 |
"
|
62
|
65 |
!
|
|
66 |
|
239
|
67 |
hour:h minutes:m seconds:s
|
|
68 |
"return an instance of Time representing the given values"
|
|
69 |
|
|
70 |
| seconds |
|
|
71 |
|
|
72 |
"have to subtract 3600; unix time starts at 1'o clock"
|
|
73 |
seconds := (h * 60 * 60 ) + (m * 60) + s - 3600.
|
62
|
74 |
|
239
|
75 |
^ self basicNew setSeconds:seconds.
|
1
|
76 |
|
239
|
77 |
"
|
|
78 |
Time hour:2 minutes:33 seconds:0
|
|
79 |
"
|
|
80 |
!
|
1
|
81 |
|
239
|
82 |
fromSeconds:seconds
|
77
|
83 |
"return a Time that is constructed from seconds since midnight."
|
|
84 |
|
239
|
85 |
"have to subtract 3600; unix time starts at 1'o clock"
|
|
86 |
^ self basicNew setSeconds:seconds-3600
|
95
|
87 |
|
|
88 |
"
|
|
89 |
Time fromSeconds:0
|
|
90 |
"
|
77
|
91 |
!
|
|
92 |
|
239
|
93 |
fromOSTime:osTime
|
|
94 |
"return a time, representing the time given by the operatingSystem time"
|
216
|
95 |
|
239
|
96 |
^ self basicNew setSecondsLow:(osTime at:1) and:(osTime at:2)
|
|
97 |
!
|
|
98 |
|
|
99 |
readFrom:aStream onError:exceptionBlock
|
|
100 |
"return a new Time, reading a printed representation from aStream."
|
|
101 |
|
|
102 |
|hour min sec|
|
216
|
103 |
|
239
|
104 |
hour := Integer readFrom:aStream onError:[^ exceptionBlock value].
|
|
105 |
[aStream peek isDigit] whileFalse:[aStream next].
|
|
106 |
min := Integer readFrom:aStream onError:[^ exceptionBlock value].
|
|
107 |
[aStream peek isDigit] whileFalse:[aStream next].
|
|
108 |
sec := Integer readFrom:aStream onError:[^ exceptionBlock value].
|
|
109 |
[aStream peek == Character space] whileTrue:[aStream next].
|
|
110 |
(aStream peek == $p) ifTrue:[
|
|
111 |
"pm"
|
|
112 |
hour := hour + 12
|
|
113 |
].
|
|
114 |
^ self hour:hour minutes:min seconds:sec
|
216
|
115 |
|
239
|
116 |
"
|
|
117 |
Time readFromString:'18:22:00'
|
|
118 |
Time readFromString:'14:00:11'
|
|
119 |
Time readFromString:'7:00:11'
|
|
120 |
Time readFromString:'6:22:00 pm'
|
|
121 |
Time readFromString:'2:00:11 pm'
|
|
122 |
Time readFromString:'7:00:11 am'
|
|
123 |
"
|
|
124 |
|
|
125 |
! !
|
|
126 |
|
|
127 |
!Time class methodsFor:'ST-80 compatibility'!
|
216
|
128 |
|
1
|
129 |
totalSeconds
|
|
130 |
^ self secondClock
|
|
131 |
! !
|
|
132 |
|
77
|
133 |
|
95
|
134 |
!Time methodsFor:'accessing'!
|
77
|
135 |
|
|
136 |
asSeconds
|
95
|
137 |
"return the number of seconds elapsed since midnight"
|
|
138 |
|
|
139 |
OperatingSystem computeTimePartsOf:secondsLow and:secondsHi for:[
|
159
|
140 |
:hours :minutes :seconds |
|
77
|
141 |
|
159
|
142 |
^ ( 3600 * hours )
|
|
143 |
+ ( 60 * minutes )
|
|
144 |
+ seconds
|
95
|
145 |
]
|
|
146 |
|
|
147 |
"
|
|
148 |
Time now asSeconds
|
|
149 |
"
|
77
|
150 |
!
|
|
151 |
|
|
152 |
hours
|
95
|
153 |
"return the number of hours since midnight (i.e. 0..23)"
|
|
154 |
|
|
155 |
^ self hourInDay
|
77
|
156 |
|
95
|
157 |
"
|
|
158 |
Time now hours
|
|
159 |
"
|
77
|
160 |
!
|
|
161 |
|
|
162 |
minutes
|
95
|
163 |
"return the number of minutes within the hour (i.e. 0..59)"
|
|
164 |
|
|
165 |
^self minuteInDay
|
77
|
166 |
|
95
|
167 |
"
|
|
168 |
Time now minutes
|
|
169 |
"
|
77
|
170 |
!
|
|
171 |
|
|
172 |
seconds
|
95
|
173 |
"return the number of seconds within the minute (i.e. 0..59)"
|
|
174 |
|
|
175 |
^self secondInDay
|
77
|
176 |
|
95
|
177 |
"
|
|
178 |
Time now seconds
|
|
179 |
"
|
77
|
180 |
! !
|
|
181 |
|
1
|
182 |
!Time methodsFor:'comparing'!
|
|
183 |
|
|
184 |
> aTime
|
95
|
185 |
"return true if the argument, aTime is after the receiver"
|
|
186 |
|
159
|
187 |
(aTime respondsTo:#secondsLow) ifTrue:[
|
|
188 |
(secondsHi > aTime secondsHi) ifTrue:[^ true].
|
|
189 |
(secondsHi < aTime secondsHi) ifTrue:[^ false].
|
|
190 |
(secondsLow > aTime secondsLow) ifTrue:[^ true].
|
|
191 |
^ false
|
1
|
192 |
].
|
|
193 |
^ self getSeconds > aTime getSeconds
|
|
194 |
!
|
|
195 |
|
|
196 |
< aTime
|
95
|
197 |
"return true if the argument, aTime is before the receiver"
|
|
198 |
|
159
|
199 |
(aTime respondsTo:#secondsLow) ifTrue:[
|
|
200 |
(secondsHi < aTime secondsHi) ifTrue:[^ true].
|
|
201 |
(secondsHi > aTime secondsHi) ifTrue:[^ false].
|
|
202 |
(secondsLow < aTime secondsLow) ifTrue:[^ true].
|
|
203 |
^ false
|
1
|
204 |
].
|
|
205 |
^ self getSeconds < aTime getSeconds
|
|
206 |
! !
|
|
207 |
|
95
|
208 |
!Time methodsFor:'printing & storing'!
|
1
|
209 |
|
62
|
210 |
printOn:aStream
|
95
|
211 |
"append a printed representation of the receiver to aStream.
|
|
212 |
Format is hh:mm:ss either in 12-hour or 24-hour format.
|
|
213 |
depending on the setting of LanguageTerritory.
|
|
214 |
I dont know what ST-80 does here (12-hour format ?)"
|
|
215 |
|
|
216 |
LanguageTerritory = 'usa' ifTrue:[
|
|
217 |
self print12HourFormatOn:aStream
|
|
218 |
] ifFalse:[
|
|
219 |
self print24HourFormatOn:aStream
|
|
220 |
]
|
|
221 |
|
|
222 |
"
|
216
|
223 |
Time now printOn:Transcript. Transcript cr
|
95
|
224 |
"
|
62
|
225 |
!
|
|
226 |
|
95
|
227 |
print24HourFormatOn:aStream
|
|
228 |
"append a printed representation of the receiver to aStream.
|
|
229 |
Format is hh:mm:ss in 24-hour format."
|
1
|
230 |
|
|
231 |
OperatingSystem computeTimePartsOf:secondsLow and:secondsHi for:[
|
159
|
232 |
:hours :minutes :secs |
|
1
|
233 |
|
159
|
234 |
hours printOn:aStream.
|
|
235 |
aStream nextPut:$:.
|
|
236 |
(minutes < 10) ifTrue:[aStream nextPut:$0].
|
|
237 |
minutes printOn:aStream.
|
|
238 |
aStream nextPut:$:.
|
|
239 |
(secs < 10) ifTrue:[aStream nextPut:$0].
|
|
240 |
secs printOn:aStream
|
95
|
241 |
]
|
|
242 |
|
|
243 |
"
|
216
|
244 |
Time now print24HourFormatOn:Transcript. Transcript cr
|
95
|
245 |
"
|
|
246 |
!
|
|
247 |
|
|
248 |
print12HourFormatOn:aStream
|
|
249 |
"append a printed representation of the receiver to aStream.
|
|
250 |
Format is hh:mm:ss am/pm (i.e. 12-hour format)."
|
|
251 |
|
|
252 |
OperatingSystem computeTimePartsOf:secondsLow and:secondsHi for:[
|
159
|
253 |
:hours :minutes :secs | |h|
|
95
|
254 |
|
|
255 |
h := hours.
|
|
256 |
h > 12 ifTrue:[
|
|
257 |
h := h - 12.
|
|
258 |
] ifFalse:[
|
|
259 |
h < 1 ifTrue:[
|
|
260 |
h := 12
|
|
261 |
]
|
159
|
262 |
].
|
|
263 |
h printOn:aStream.
|
|
264 |
aStream nextPut:$:.
|
|
265 |
(minutes < 10) ifTrue:[aStream nextPut:$0].
|
|
266 |
minutes printOn:aStream.
|
|
267 |
aStream nextPut:$:.
|
|
268 |
(secs < 10) ifTrue:[aStream nextPut:$0].
|
|
269 |
secs printOn:aStream.
|
95
|
270 |
hours >= 12 ifTrue:[
|
|
271 |
aStream nextPutAll:' pm'
|
|
272 |
] ifFalse:[
|
|
273 |
aStream nextPutAll:' am'
|
|
274 |
]
|
|
275 |
]
|
|
276 |
|
|
277 |
"
|
216
|
278 |
Time now print12HourFormatOn:Transcript. Transcript cr
|
95
|
279 |
"
|
1
|
280 |
! !
|