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 |
|
241
|
13 |
'From Smalltalk/X, Version:2.10.4 on 8-feb-1995 at 12:46:45 pm'!
|
|
14 |
|
|
15 |
AbstractTime subclass:#AbsoluteTime
|
|
16 |
instanceVariableNames:'secondsLow secondsHi'
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Magnitude-General'
|
30
|
20 |
!
|
|
21 |
|
|
22 |
AbsoluteTime comment:'
|
|
23 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
154
|
24 |
All Rights Reserved
|
92
|
25 |
|
241
|
26 |
$Header: /cvs/stx/stx/libbasic/Attic/AbsTime.st,v 1.8 1995-02-08 03:10:47 claus Exp $
|
30
|
27 |
'!
|
|
28 |
|
|
29 |
!AbsoluteTime class methodsFor:'documentation'!
|
|
30 |
|
82
|
31 |
copyright
|
|
32 |
"
|
|
33 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
154
|
34 |
All Rights Reserved
|
82
|
35 |
|
|
36 |
This software is furnished under a license and may be used
|
|
37 |
only in accordance with the terms of that license and with the
|
|
38 |
inclusion of the above copyright notice. This software may not
|
|
39 |
be provided or otherwise made available to, or used by, any
|
|
40 |
other person. No title to or ownership of the software is
|
|
41 |
hereby transferred.
|
|
42 |
"
|
|
43 |
!
|
|
44 |
|
|
45 |
version
|
|
46 |
"
|
241
|
47 |
$Header: /cvs/stx/stx/libbasic/Attic/AbsTime.st,v 1.8 1995-02-08 03:10:47 claus Exp $
|
82
|
48 |
"
|
|
49 |
!
|
|
50 |
|
30
|
51 |
documentation
|
|
52 |
"
|
77
|
53 |
This class represents time values in seconds from 1st. Jan 1970, as
|
|
54 |
used in the Unix operating system. Its implementation is not the same
|
|
55 |
as in ST-80 (which represents Time as seconds from 1. Jan 1901.
|
241
|
56 |
|
|
57 |
Actually, the implementation does not depend or even know which time/date
|
|
58 |
the OperatingSystem bases its time upon - it is simply keeping the value(s)
|
|
59 |
as return from the OS.
|
92
|
60 |
For conversion, these values are given back to the OS, which will know
|
|
61 |
how to convert these times.
|
|
62 |
This has the advantage, that time-stamps on files (such as last-access-
|
|
63 |
time or last-modifiaction-time) can be handled transparent to other
|
|
64 |
times (especially comparison).
|
30
|
65 |
|
77
|
66 |
Since unix-times are 32 bit which does not fit into a SmallInteger,
|
92
|
67 |
we keep low and hi 16bits of the time separately (it could have been
|
|
68 |
implemented using LargeIntegers though).
|
30
|
69 |
|
241
|
70 |
This class should not be confused with Time (which only represents the
|
|
71 |
time within one day). Time instances cannot be used to compare times across
|
|
72 |
midnight; instances of AbsoluteTime can.
|
|
73 |
|
92
|
74 |
See Time for more details.
|
30
|
75 |
"
|
|
76 |
! !
|
|
77 |
|
|
78 |
!AbsoluteTime class methodsFor:'instance creation'!
|
|
79 |
|
241
|
80 |
day:d month:m year:y hour:h minutes:min seconds:s
|
|
81 |
"return an instance of the receiver"
|
30
|
82 |
|
241
|
83 |
^ self fromOSTime:(OperatingSystem
|
|
84 |
computeTimePartsFromYear:y month:m day:d
|
|
85 |
hour:h minute:min seconds:s)
|
30
|
86 |
|
241
|
87 |
"
|
|
88 |
AbsoluteTime day:2 month:1 year:1991 hour:12 minutes:30 seconds:0
|
|
89 |
AbsoluteTime day:8 month:1 year:1995 hour:0 minutes:43 seconds:48
|
|
90 |
"
|
|
91 |
! !
|
30
|
92 |
|
241
|
93 |
!AbsoluteTime methodsFor:'private'!
|
30
|
94 |
|
241
|
95 |
secondsLow
|
|
96 |
^ secondsLow
|
30
|
97 |
!
|
|
98 |
|
241
|
99 |
setSecondsLow:secsLow and:secsHi
|
|
100 |
secondsHi := secsHi.
|
|
101 |
secondsLow := secsLow
|
|
102 |
!
|
30
|
103 |
|
241
|
104 |
fromOSTimeLow:secsLow and:secsHi
|
|
105 |
secondsHi := secsHi.
|
|
106 |
secondsLow := secsLow
|
30
|
107 |
!
|
|
108 |
|
241
|
109 |
secondsHi
|
|
110 |
^ secondsHi
|
|
111 |
!
|
30
|
112 |
|
241
|
113 |
setSeconds:secs
|
|
114 |
secondsHi := secs // 16r10000.
|
|
115 |
secondsLow := secs \\ 16r10000
|
|
116 |
!
|
|
117 |
|
|
118 |
getSeconds
|
|
119 |
^ (secondsHi * 16r10000) + secondsLow
|
|
120 |
!
|
|
121 |
|
|
122 |
fromOSTime:secs
|
|
123 |
secondsHi := secs // 16r10000.
|
|
124 |
secondsLow := secs \\ 16r10000
|
30
|
125 |
! !
|
|
126 |
|
|
127 |
!AbsoluteTime methodsFor:'accessing'!
|
|
128 |
|
|
129 |
hourInDay
|
241
|
130 |
"return the hours (0..23)"
|
30
|
131 |
|
241
|
132 |
^ self hours
|
30
|
133 |
|
241
|
134 |
"
|
|
135 |
AbsoluteTime now hours
|
|
136 |
"
|
30
|
137 |
|
|
138 |
!
|
|
139 |
|
|
140 |
minuteInDay
|
|
141 |
"return the minute-part"
|
|
142 |
|
|
143 |
|m|
|
|
144 |
|
|
145 |
OperatingSystem computeTimePartsOf:secondsLow and:secondsHi for:[
|
241
|
146 |
:hours :minutes :secs |
|
30
|
147 |
|
241
|
148 |
m := minutes
|
30
|
149 |
].
|
|
150 |
^ m
|
241
|
151 |
|
|
152 |
"
|
|
153 |
AbsoluteTime now minuteInDay
|
|
154 |
"
|
|
155 |
|
30
|
156 |
!
|
|
157 |
|
|
158 |
secondInDay
|
|
159 |
"return the second-part"
|
|
160 |
|
|
161 |
|s|
|
|
162 |
|
|
163 |
OperatingSystem computeTimePartsOf:secondsLow and:secondsHi for:[
|
241
|
164 |
:hours :minutes :secs |
|
30
|
165 |
|
241
|
166 |
s := secs
|
30
|
167 |
].
|
|
168 |
^ s
|
241
|
169 |
|
|
170 |
"
|
|
171 |
AbsoluteTime now secondInDay
|
|
172 |
"
|
|
173 |
|
30
|
174 |
!
|
|
175 |
|
|
176 |
day
|
92
|
177 |
"return the day-in-month of the receiver (1..31).
|
|
178 |
Obsolete; use instances of Date for this."
|
30
|
179 |
|
241
|
180 |
|d|
|
|
181 |
|
30
|
182 |
OperatingSystem computeDatePartsOf:secondsLow and:secondsHi
|
241
|
183 |
for:[:year :month :day |
|
|
184 |
d := day
|
|
185 |
].
|
|
186 |
^ d
|
54
|
187 |
|
92
|
188 |
"
|
241
|
189 |
AbsoluteTime now day
|
92
|
190 |
"
|
30
|
191 |
!
|
|
192 |
|
|
193 |
month
|
92
|
194 |
"return the month of the receiver (1..12).
|
|
195 |
Obsolete; use instances of Date for this."
|
30
|
196 |
|
241
|
197 |
|m|
|
|
198 |
|
30
|
199 |
OperatingSystem computeDatePartsOf:secondsLow and:secondsHi
|
241
|
200 |
for:[:year :month :day |
|
|
201 |
m := month
|
|
202 |
].
|
|
203 |
^ m
|
54
|
204 |
|
92
|
205 |
"
|
241
|
206 |
AbsoluteTime now month
|
92
|
207 |
"
|
30
|
208 |
!
|
|
209 |
|
|
210 |
year
|
92
|
211 |
"return the year of the receiver i.e. 1992.
|
|
212 |
Obsolete; use instances of Date for this."
|
30
|
213 |
|
241
|
214 |
|y|
|
|
215 |
|
30
|
216 |
OperatingSystem computeDatePartsOf:secondsLow and:secondsHi
|
241
|
217 |
for:[:year :month :day |
|
|
218 |
y := year
|
|
219 |
].
|
|
220 |
^ y
|
|
221 |
|
|
222 |
"
|
|
223 |
AbsoluteTime now year
|
|
224 |
"
|
|
225 |
!
|
|
226 |
|
|
227 |
hours
|
|
228 |
"return the hours (0..23)"
|
|
229 |
|
|
230 |
|hr|
|
|
231 |
|
|
232 |
OperatingSystem computeTimePartsOf:secondsLow and:secondsHi for:[
|
|
233 |
:hours :minutes :secs |
|
|
234 |
|
|
235 |
hr := hours
|
|
236 |
].
|
|
237 |
^ hr
|
54
|
238 |
|
92
|
239 |
"
|
241
|
240 |
AbsoluteTime now hours
|
|
241 |
"
|
|
242 |
|
|
243 |
!
|
|
244 |
|
|
245 |
minutes
|
|
246 |
"return the minutes (0..59)"
|
|
247 |
|
|
248 |
|m|
|
|
249 |
|
|
250 |
OperatingSystem computeTimePartsOf:secondsLow and:secondsHi for:[
|
|
251 |
:hours :minutes :secs |
|
|
252 |
|
|
253 |
m := minutes
|
|
254 |
].
|
|
255 |
^ m
|
|
256 |
|
|
257 |
"
|
|
258 |
AbsoluteTime now minutes
|
92
|
259 |
"
|
241
|
260 |
|
|
261 |
!
|
|
262 |
|
|
263 |
seconds
|
|
264 |
"return the seconds (0..59)"
|
|
265 |
|
|
266 |
|s|
|
|
267 |
|
|
268 |
OperatingSystem computeTimePartsOf:secondsLow and:secondsHi for:[
|
|
269 |
:hours :minutes :secs |
|
|
270 |
|
|
271 |
s := secs
|
|
272 |
].
|
|
273 |
^ s
|
|
274 |
|
|
275 |
"
|
|
276 |
AbsoluteTime now seconds
|
|
277 |
"
|
|
278 |
|
30
|
279 |
! !
|
|
280 |
|
|
281 |
!AbsoluteTime methodsFor:'comparing'!
|
|
282 |
|
|
283 |
> aTime
|
|
284 |
secondsHi > aTime secondsHi ifTrue:[^ true].
|
|
285 |
secondsHi < aTime secondsHi ifTrue:[^ false].
|
|
286 |
^ secondsLow > aTime secondsLow
|
|
287 |
!
|
|
288 |
|
|
289 |
< aTime
|
|
290 |
secondsHi < aTime secondsHi ifTrue:[^ true].
|
|
291 |
secondsHi > aTime secondsHi ifTrue:[^ false].
|
|
292 |
^ secondsLow < aTime secondsLow
|
|
293 |
!
|
|
294 |
|
|
295 |
= aTime
|
154
|
296 |
(aTime species == self species) ifFalse:[^ false].
|
30
|
297 |
^ (secondsLow == aTime secondsLow) and:[secondsHi == aTime secondsHi]
|
92
|
298 |
!
|
|
299 |
|
|
300 |
hash
|
|
301 |
"return an integer useful for hashing on times"
|
|
302 |
|
154
|
303 |
^ (secondsLow bitShift:16) bitOr:secondsLow
|
30
|
304 |
! !
|
|
305 |
|
241
|
306 |
!AbsoluteTime methodsFor:'converting'!
|
|
307 |
|
|
308 |
asSeconds
|
|
309 |
"return the number of seconds elapsed since whatever time the
|
|
310 |
OperatingSystem bases its time upon. Since this is totally
|
|
311 |
OS-dependent, do not interpret the value returned by this method.
|
|
312 |
You can use it to add/subtract seconds or get time deltas, though."
|
|
313 |
|
|
314 |
^ (secondsHi * 16r10000) + secondsLow
|
|
315 |
|
|
316 |
"
|
|
317 |
AbsoluteTime now asSeconds
|
|
318 |
AbsoluteTime fromSeconds:(AbsoluteTime now asSeconds + 3600)
|
|
319 |
Time hour:23 minutes:33 seconds:0
|
|
320 |
Time fromSeconds:((Time hour:23 minutes:33 seconds:0) asSeconds + 3600)
|
|
321 |
"
|
|
322 |
!
|
|
323 |
|
|
324 |
asDate
|
|
325 |
"return a Date object from the receiver"
|
|
326 |
|
|
327 |
^ Date fromOSTime:(Array with:secondsLow with:secondsHi)
|
|
328 |
|
|
329 |
"
|
|
330 |
AbsoluteTime now
|
|
331 |
AbsoluteTime now asDate
|
|
332 |
(AbsoluteTime now addTime:3600) asDate
|
|
333 |
(AbsoluteTime now addTime:3600) asTime
|
|
334 |
AbsoluteTime fromSeconds:(AbsoluteTime now asSeconds + 3600)
|
|
335 |
(AbsoluteTime fromSeconds:(AbsoluteTime now asSeconds + 3600)) asDate
|
|
336 |
"
|
|
337 |
|
|
338 |
!
|
|
339 |
|
|
340 |
asTime
|
|
341 |
^ Time fromOSTime:(Array with:secondsLow with:secondsHi)
|
|
342 |
|
|
343 |
"
|
|
344 |
AbsoluteTime now
|
|
345 |
AbsoluteTime now asTime
|
|
346 |
(AbsoluteTime now addTime:3600) asTime
|
|
347 |
"
|
|
348 |
|
|
349 |
! !
|
|
350 |
|
30
|
351 |
!AbsoluteTime methodsFor:'arithmetic'!
|
|
352 |
|
|
353 |
- aTime
|
92
|
354 |
"return delta in seconds between 2 times/dates."
|
30
|
355 |
|
|
356 |
^ self getSeconds - (aTime getSeconds)
|
|
357 |
!
|
|
358 |
|
|
359 |
addTime:timeAmount
|
241
|
360 |
"return a new instance of myself, timeAmount seconds afterwards"
|
30
|
361 |
|
|
362 |
^ self class new setSeconds:(self getSeconds + timeAmount)
|
|
363 |
!
|
|
364 |
|
|
365 |
subtractTime:timeAmount
|
241
|
366 |
"return a new instance opf myself, timeAmount seconds before myself"
|
30
|
367 |
|
|
368 |
^ self class new setSeconds:(self getSeconds - timeAmount)
|
|
369 |
! !
|
|
370 |
|
213
|
371 |
!AbsoluteTime methodsFor:'printing & storing'!
|
30
|
372 |
|
241
|
373 |
printOn:aStream
|
|
374 |
|h min s d m y|
|
30
|
375 |
|
241
|
376 |
OperatingSystem computeDatePartsOf:secondsLow and:secondsHi for:[
|
|
377 |
:year :month :day | d := day. m := month. y := year.
|
|
378 |
].
|
|
379 |
OperatingSystem computeTimePartsOf:secondsLow and:secondsHi for:[
|
|
380 |
:hours :minutes :secs | h := hours. min := minutes. s := secs.
|
|
381 |
].
|
|
382 |
d printOn:aStream.
|
|
383 |
aStream nextPut:$-.
|
|
384 |
m printOn:aStream.
|
|
385 |
aStream nextPut:$-.
|
|
386 |
y printOn:aStream.
|
|
387 |
aStream space.
|
|
388 |
h printOn:aStream leftPaddedTo:2 with:$0.
|
|
389 |
aStream nextPut:$:.
|
|
390 |
min printOn:aStream leftPaddedTo:2 with:$0.
|
|
391 |
aStream nextPut:$:.
|
|
392 |
s printOn:aStream leftPaddedTo:2 with:$0.
|
92
|
393 |
|
|
394 |
"
|
241
|
395 |
AbsoluteTime now
|
|
396 |
AbsoluteTime fromSeconds:0
|
|
397 |
Time now
|
|
398 |
Date today
|
92
|
399 |
"
|
30
|
400 |
!
|
|
401 |
|
241
|
402 |
storeOn:aStream
|
|
403 |
aStream nextPut:$(;
|
|
404 |
nextPutAll:self class name;
|
|
405 |
nextPutAll:' new setSecondsLow:'.
|
|
406 |
secondsLow storeOn:aStream.
|
|
407 |
aStream nextPutAll:' and:'.
|
|
408 |
secondsHi storeOn:aStream.
|
|
409 |
aStream nextPut:$).
|
54
|
410 |
|
241
|
411 |
"
|
|
412 |
AbsoluteTime now storeString '(AbsoluteTime new setSecondsLow:39757 and:12087)'
|
30
|
413 |
|
241
|
414 |
AbsoluteTime readFromString:(AbsoluteTime now storeString)
|
|
415 |
"
|
30
|
416 |
! !
|
|
417 |
|