30
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
154
|
3 |
All Rights Reserved
|
30
|
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 |
|
|
13 |
Magnitude subclass:#AbsoluteTime
|
|
14 |
instanceVariableNames:'secondsLow secondsHi'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Magnitude-General'
|
|
18 |
!
|
|
19 |
|
|
20 |
AbsoluteTime comment:'
|
|
21 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
154
|
22 |
All Rights Reserved
|
92
|
23 |
|
154
|
24 |
$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.6 1994-10-10 00:19:36 claus Exp $
|
30
|
25 |
'!
|
|
26 |
|
|
27 |
!AbsoluteTime class methodsFor:'documentation'!
|
|
28 |
|
82
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
154
|
32 |
All Rights Reserved
|
82
|
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 |
"
|
154
|
45 |
$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.6 1994-10-10 00:19:36 claus Exp $
|
82
|
46 |
"
|
|
47 |
!
|
|
48 |
|
30
|
49 |
documentation
|
|
50 |
"
|
77
|
51 |
This class represents time values in seconds from 1st. Jan 1970, as
|
|
52 |
used in the Unix operating system. Its implementation is not the same
|
|
53 |
as in ST-80 (which represents Time as seconds from 1. Jan 1901.
|
92
|
54 |
Actually, the implementation does not even know which time/date the
|
|
55 |
OperatingSystem bases its time upon - it is simply keeping the value(s)
|
|
56 |
as return from the OS when asked for the time.
|
|
57 |
For conversion, these values are given back to the OS, which will know
|
|
58 |
how to convert these times.
|
|
59 |
This has the advantage, that time-stamps on files (such as last-access-
|
|
60 |
time or last-modifiaction-time) can be handled transparent to other
|
|
61 |
times (especially comparison).
|
30
|
62 |
|
77
|
63 |
Since unix-times are 32 bit which does not fit into a SmallInteger,
|
92
|
64 |
we keep low and hi 16bits of the time separately (it could have been
|
|
65 |
implemented using LargeIntegers though).
|
30
|
66 |
|
154
|
67 |
This class is typically abstract (it does not have to be, though).
|
92
|
68 |
See Time for more details.
|
30
|
69 |
"
|
|
70 |
! !
|
|
71 |
|
|
72 |
!AbsoluteTime class methodsFor:'instance creation'!
|
|
73 |
|
|
74 |
secondClock
|
|
75 |
"return seconds of now - for GNU-ST compatibility"
|
|
76 |
|
|
77 |
^ OperatingSystem getTime
|
|
78 |
!
|
|
79 |
|
|
80 |
millisecondClockValue
|
|
81 |
"return the millisecond clock - since this one overruns
|
92
|
82 |
regularly, use only for short timing deltas."
|
30
|
83 |
|
|
84 |
^ OperatingSystem getMillisecondTime.
|
|
85 |
!
|
|
86 |
|
|
87 |
fromUnixTimeLow:low and:hi
|
92
|
88 |
"return an instance of Time, given the unix time.
|
|
89 |
Internal interface - not for public use."
|
|
90 |
|
30
|
91 |
^ self basicNew setSecondsLow:low and:hi
|
|
92 |
!
|
|
93 |
|
|
94 |
dateAndTimeNow
|
|
95 |
"return an array filled with date and time"
|
|
96 |
|
|
97 |
^ Array with:(Date today) with:(Time now)
|
|
98 |
! !
|
|
99 |
|
|
100 |
!AbsoluteTime class methodsFor:'timing evaluations'!
|
|
101 |
|
|
102 |
secondsToRun:aBlock
|
|
103 |
"evaluate the argument, aBlock; return the number of seconds it took"
|
|
104 |
|
|
105 |
|startTime endTime|
|
|
106 |
|
|
107 |
startTime := self now.
|
|
108 |
aBlock value.
|
|
109 |
endTime := self now.
|
|
110 |
^ endTime - startTime
|
|
111 |
!
|
|
112 |
|
|
113 |
millisecondsToRun:aBlock
|
|
114 |
"evaluate the argument, aBlock; return the number of milliseconds it took"
|
|
115 |
|
|
116 |
|startTime endTime|
|
|
117 |
|
92
|
118 |
startTime := self millisecondClockValue.
|
30
|
119 |
aBlock value.
|
92
|
120 |
endTime := self millisecondClockValue.
|
30
|
121 |
^ endTime - startTime
|
|
122 |
! !
|
|
123 |
|
|
124 |
!AbsoluteTime methodsFor:'accessing'!
|
|
125 |
|
|
126 |
hourInDay
|
|
127 |
"return the hour-part"
|
|
128 |
|
|
129 |
|hr|
|
|
130 |
|
|
131 |
OperatingSystem computeTimePartsOf:secondsLow and:secondsHi for:[
|
154
|
132 |
:hours :minutes :secs |
|
30
|
133 |
|
154
|
134 |
hr := hours
|
30
|
135 |
].
|
|
136 |
^ hr
|
|
137 |
!
|
|
138 |
|
|
139 |
minuteInDay
|
|
140 |
"return the minute-part"
|
|
141 |
|
|
142 |
|m|
|
|
143 |
|
|
144 |
OperatingSystem computeTimePartsOf:secondsLow and:secondsHi for:[
|
154
|
145 |
:hours :minutes :secs |
|
30
|
146 |
|
154
|
147 |
m := minutes
|
30
|
148 |
].
|
|
149 |
^ m
|
|
150 |
!
|
|
151 |
|
|
152 |
secondInDay
|
|
153 |
"return the second-part"
|
|
154 |
|
|
155 |
|s|
|
|
156 |
|
|
157 |
OperatingSystem computeTimePartsOf:secondsLow and:secondsHi for:[
|
154
|
158 |
:hours :minutes :secs |
|
30
|
159 |
|
154
|
160 |
s := secs
|
30
|
161 |
].
|
|
162 |
^ s
|
|
163 |
!
|
|
164 |
|
|
165 |
day
|
92
|
166 |
"return the day-in-month of the receiver (1..31).
|
|
167 |
Obsolete; use instances of Date for this."
|
30
|
168 |
|
|
169 |
OperatingSystem computeDatePartsOf:secondsLow and:secondsHi
|
154
|
170 |
for:[:year :month :day |
|
|
171 |
^ day
|
30
|
172 |
]
|
54
|
173 |
|
92
|
174 |
"
|
|
175 |
Time now day
|
|
176 |
"
|
30
|
177 |
!
|
|
178 |
|
|
179 |
month
|
92
|
180 |
"return the month of the receiver (1..12).
|
|
181 |
Obsolete; use instances of Date for this."
|
30
|
182 |
|
|
183 |
OperatingSystem computeDatePartsOf:secondsLow and:secondsHi
|
154
|
184 |
for:[:year :month :day |
|
|
185 |
^ month
|
30
|
186 |
]
|
54
|
187 |
|
92
|
188 |
"
|
|
189 |
Time now month
|
|
190 |
"
|
30
|
191 |
!
|
|
192 |
|
|
193 |
year
|
92
|
194 |
"return the year of the receiver i.e. 1992.
|
|
195 |
Obsolete; use instances of Date for this."
|
30
|
196 |
|
|
197 |
OperatingSystem computeDatePartsOf:secondsLow and:secondsHi
|
154
|
198 |
for:[:year :month :day |
|
|
199 |
^ year
|
30
|
200 |
]
|
54
|
201 |
|
92
|
202 |
"
|
|
203 |
Time now year
|
|
204 |
"
|
30
|
205 |
! !
|
|
206 |
|
|
207 |
!AbsoluteTime methodsFor:'comparing'!
|
|
208 |
|
|
209 |
> aTime
|
|
210 |
secondsHi > aTime secondsHi ifTrue:[^ true].
|
|
211 |
secondsHi < aTime secondsHi ifTrue:[^ false].
|
|
212 |
^ secondsLow > aTime secondsLow
|
|
213 |
!
|
|
214 |
|
|
215 |
< aTime
|
|
216 |
secondsHi < aTime secondsHi ifTrue:[^ true].
|
|
217 |
secondsHi > aTime secondsHi ifTrue:[^ false].
|
|
218 |
^ secondsLow < aTime secondsLow
|
|
219 |
!
|
|
220 |
|
|
221 |
= aTime
|
154
|
222 |
(aTime species == self species) ifFalse:[^ false].
|
30
|
223 |
^ (secondsLow == aTime secondsLow) and:[secondsHi == aTime secondsHi]
|
92
|
224 |
!
|
|
225 |
|
|
226 |
hash
|
|
227 |
"return an integer useful for hashing on times"
|
|
228 |
|
154
|
229 |
^ (secondsLow bitShift:16) bitOr:secondsLow
|
30
|
230 |
! !
|
|
231 |
|
|
232 |
!AbsoluteTime methodsFor:'arithmetic'!
|
|
233 |
|
|
234 |
- aTime
|
92
|
235 |
"return delta in seconds between 2 times/dates."
|
30
|
236 |
|
|
237 |
^ self getSeconds - (aTime getSeconds)
|
|
238 |
!
|
|
239 |
|
|
240 |
addTime:timeAmount
|
|
241 |
"return a new Time/Date timeAmount seconds from myself"
|
|
242 |
|
|
243 |
^ self class new setSeconds:(self getSeconds + timeAmount)
|
|
244 |
!
|
|
245 |
|
|
246 |
subtractTime:timeAmount
|
|
247 |
"return a new Time/Date timeAmount seconds before myself"
|
|
248 |
|
|
249 |
^ self class new setSeconds:(self getSeconds - timeAmount)
|
|
250 |
! !
|
|
251 |
|
|
252 |
!AbsoluteTime methodsFor:'storing'!
|
|
253 |
|
|
254 |
storeString
|
|
255 |
|string|
|
|
256 |
|
|
257 |
string := '(' , self class name , ' new setSecondsLow:'.
|
|
258 |
string := string , secondsLow storeString.
|
|
259 |
string := string , ' and:' , secondsHi storeString.
|
|
260 |
string := string , ')'.
|
|
261 |
^ string
|
|
262 |
! !
|
|
263 |
|
|
264 |
!AbsoluteTime methodsFor:'converting'!
|
|
265 |
|
|
266 |
asSeconds
|
92
|
267 |
"return the number of seconds elapsed since whatever time the
|
|
268 |
OperatingSystem bases its time upon. Since this is totally
|
|
269 |
OS-dependent, do not use this method. (see Time>>asSeconds)"
|
|
270 |
|
30
|
271 |
^ (secondsHi * 16r10000) + secondsLow
|
92
|
272 |
|
|
273 |
"
|
|
274 |
AbsoluteTime asSeconds
|
|
275 |
"
|
30
|
276 |
!
|
|
277 |
|
|
278 |
asDate
|
54
|
279 |
"return a Date object from the receiver"
|
|
280 |
|
|
281 |
^ Date fromOSTime:(Array with:secondsLow with:secondsHi)
|
30
|
282 |
!
|
|
283 |
|
|
284 |
asTime
|
54
|
285 |
^ Time fromOSTime:(Array with:secondsLow with:secondsHi)
|
30
|
286 |
! !
|
|
287 |
|
|
288 |
!AbsoluteTime methodsFor:'private'!
|
|
289 |
|
|
290 |
secondsLow
|
|
291 |
^ secondsLow
|
|
292 |
!
|
|
293 |
|
|
294 |
secondsHi
|
|
295 |
^ secondsHi
|
|
296 |
!
|
|
297 |
|
|
298 |
getSeconds
|
|
299 |
^ (secondsHi * 16r10000) + secondsLow
|
|
300 |
!
|
|
301 |
|
|
302 |
setSeconds:secs
|
|
303 |
secondsHi := secs // 16r10000.
|
|
304 |
secondsLow := secs \\ 16r10000
|
|
305 |
!
|
|
306 |
|
|
307 |
setSecondsLow:secsLow and:secsHi
|
|
308 |
secondsHi := secsHi.
|
|
309 |
secondsLow := secsLow
|
|
310 |
! !
|