30
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
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 |
|
|
13 |
Magnitude subclass:#AbsoluteTime
|
|
14 |
instanceVariableNames:'secondsLow secondsHi'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Magnitude-General'
|
|
18 |
!
|
|
19 |
|
|
20 |
AbsoluteTime comment:'
|
|
21 |
|
|
22 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
23 |
All Rights Reserved
|
|
24 |
|
54
|
25 |
$Header: /cvs/stx/stx/libbasic/Attic/AbsoluteTime.st,v 1.2 1994-02-25 12:53:11 claus Exp $
|
30
|
26 |
'!
|
|
27 |
|
|
28 |
!AbsoluteTime class methodsFor:'documentation'!
|
|
29 |
|
|
30 |
documentation
|
|
31 |
"
|
|
32 |
This class represents time values in seconds from 1st. Jan 1970, as
|
|
33 |
used in the Unix operating system. Its implementation is not the same
|
|
34 |
as in ST-80 (which represents Time as seconds from 1. Jan 1901.
|
|
35 |
|
|
36 |
Since unix-times are 32 bit which does not fit into a SmallInteger,
|
|
37 |
we keep low and hi 16bit of the time separately (it could have been implemented
|
|
38 |
using LargeIntegers though).
|
|
39 |
|
|
40 |
This is an abstract class to support Time and Date.
|
|
41 |
"
|
|
42 |
! !
|
|
43 |
|
|
44 |
!AbsoluteTime class methodsFor:'instance creation'!
|
|
45 |
|
|
46 |
secondClock
|
|
47 |
"return seconds of now - for GNU-ST compatibility"
|
|
48 |
|
|
49 |
^ OperatingSystem getTime
|
|
50 |
!
|
|
51 |
|
|
52 |
millisecondClockValue
|
|
53 |
"return the millisecond clock - since this one overruns
|
|
54 |
regularly, use only for short timing deltas"
|
|
55 |
|
|
56 |
^ OperatingSystem getMillisecondTime.
|
|
57 |
!
|
|
58 |
|
|
59 |
fromUnixTimeLow:low and:hi
|
|
60 |
^ self basicNew setSecondsLow:low and:hi
|
|
61 |
!
|
|
62 |
|
|
63 |
dateAndTimeNow
|
|
64 |
"return an array filled with date and time"
|
|
65 |
|
|
66 |
^ Array with:(Date today) with:(Time now)
|
|
67 |
! !
|
|
68 |
|
|
69 |
!AbsoluteTime class methodsFor:'timing evaluations'!
|
|
70 |
|
|
71 |
secondsToRun:aBlock
|
|
72 |
"evaluate the argument, aBlock; return the number of seconds it took"
|
|
73 |
|
|
74 |
|startTime endTime|
|
|
75 |
|
|
76 |
startTime := self now.
|
|
77 |
aBlock value.
|
|
78 |
endTime := self now.
|
|
79 |
^ endTime - startTime
|
|
80 |
!
|
|
81 |
|
|
82 |
millisecondsToRun:aBlock
|
|
83 |
"evaluate the argument, aBlock; return the number of milliseconds it took"
|
|
84 |
|
|
85 |
|startTime endTime|
|
|
86 |
|
|
87 |
startTime := OperatingSystem getMillisecondTime.
|
|
88 |
aBlock value.
|
|
89 |
endTime := OperatingSystem getMillisecondTime.
|
|
90 |
^ endTime - startTime
|
|
91 |
! !
|
|
92 |
|
|
93 |
!AbsoluteTime methodsFor:'accessing'!
|
|
94 |
|
|
95 |
hourInDay
|
|
96 |
"return the hour-part"
|
|
97 |
|
|
98 |
|hr|
|
|
99 |
|
|
100 |
OperatingSystem computeTimePartsOf:secondsLow and:secondsHi for:[
|
|
101 |
:hours :minutes :secs |
|
|
102 |
|
|
103 |
hr := hours
|
|
104 |
].
|
|
105 |
^ hr
|
|
106 |
!
|
|
107 |
|
|
108 |
minuteInDay
|
|
109 |
"return the minute-part"
|
|
110 |
|
|
111 |
|m|
|
|
112 |
|
|
113 |
OperatingSystem computeTimePartsOf:secondsLow and:secondsHi for:[
|
|
114 |
:hours :minutes :secs |
|
|
115 |
|
|
116 |
m := minutes
|
|
117 |
].
|
|
118 |
^ m
|
|
119 |
!
|
|
120 |
|
|
121 |
secondInDay
|
|
122 |
"return the second-part"
|
|
123 |
|
|
124 |
|s|
|
|
125 |
|
|
126 |
OperatingSystem computeTimePartsOf:secondsLow and:secondsHi for:[
|
|
127 |
:hours :minutes :secs |
|
|
128 |
|
|
129 |
s := secs
|
|
130 |
].
|
|
131 |
^ s
|
|
132 |
!
|
|
133 |
|
|
134 |
day
|
|
135 |
"return the day-in-month of the receiver (1..31)"
|
|
136 |
|
|
137 |
OperatingSystem computeDatePartsOf:secondsLow and:secondsHi
|
|
138 |
for:[:year :month :day |
|
|
139 |
^ day
|
|
140 |
]
|
54
|
141 |
|
|
142 |
"Date today day"
|
30
|
143 |
!
|
|
144 |
|
|
145 |
month
|
|
146 |
"return the month of the receiver (1..12)"
|
|
147 |
|
|
148 |
OperatingSystem computeDatePartsOf:secondsLow and:secondsHi
|
|
149 |
for:[:year :month :day |
|
|
150 |
^ month
|
|
151 |
]
|
54
|
152 |
|
|
153 |
"Date today month"
|
30
|
154 |
!
|
|
155 |
|
|
156 |
year
|
|
157 |
"return the year of the receiver i.e. 1992"
|
|
158 |
|
|
159 |
OperatingSystem computeDatePartsOf:secondsLow and:secondsHi
|
|
160 |
for:[:year :month :day |
|
|
161 |
^ year
|
|
162 |
]
|
54
|
163 |
|
|
164 |
"Date today year"
|
30
|
165 |
! !
|
|
166 |
|
|
167 |
!AbsoluteTime methodsFor:'comparing'!
|
|
168 |
|
|
169 |
> aTime
|
|
170 |
secondsHi > aTime secondsHi ifTrue:[^ true].
|
|
171 |
secondsHi < aTime secondsHi ifTrue:[^ false].
|
|
172 |
^ secondsLow > aTime secondsLow
|
|
173 |
!
|
|
174 |
|
|
175 |
< aTime
|
|
176 |
secondsHi < aTime secondsHi ifTrue:[^ true].
|
|
177 |
secondsHi > aTime secondsHi ifTrue:[^ false].
|
|
178 |
^ secondsLow < aTime secondsLow
|
|
179 |
!
|
|
180 |
|
|
181 |
= aTime
|
|
182 |
^ (secondsLow == aTime secondsLow) and:[secondsHi == aTime secondsHi]
|
|
183 |
! !
|
|
184 |
|
|
185 |
!AbsoluteTime methodsFor:'arithmetic'!
|
|
186 |
|
|
187 |
- aTime
|
|
188 |
"return delta in seconds between 2 times/dates"
|
|
189 |
|
|
190 |
^ self getSeconds - (aTime getSeconds)
|
|
191 |
!
|
|
192 |
|
|
193 |
addTime:timeAmount
|
|
194 |
"return a new Time/Date timeAmount seconds from myself"
|
|
195 |
|
|
196 |
^ self class new setSeconds:(self getSeconds + timeAmount)
|
|
197 |
!
|
|
198 |
|
|
199 |
subtractTime:timeAmount
|
|
200 |
"return a new Time/Date timeAmount seconds before myself"
|
|
201 |
|
|
202 |
^ self class new setSeconds:(self getSeconds - timeAmount)
|
|
203 |
! !
|
|
204 |
|
|
205 |
!AbsoluteTime methodsFor:'storing'!
|
|
206 |
|
|
207 |
storeString
|
|
208 |
|string|
|
|
209 |
|
|
210 |
string := '(' , self class name , ' new setSecondsLow:'.
|
|
211 |
string := string , secondsLow storeString.
|
|
212 |
string := string , ' and:' , secondsHi storeString.
|
|
213 |
string := string , ')'.
|
|
214 |
^ string
|
|
215 |
! !
|
|
216 |
|
|
217 |
!AbsoluteTime methodsFor:'converting'!
|
|
218 |
|
|
219 |
asSeconds
|
|
220 |
^ (secondsHi * 16r10000) + secondsLow
|
|
221 |
!
|
|
222 |
|
|
223 |
asDate
|
54
|
224 |
"return a Date object from the receiver"
|
|
225 |
|
|
226 |
^ Date fromOSTime:(Array with:secondsLow with:secondsHi)
|
30
|
227 |
!
|
|
228 |
|
|
229 |
asTime
|
54
|
230 |
^ Time fromOSTime:(Array with:secondsLow with:secondsHi)
|
30
|
231 |
! !
|
|
232 |
|
|
233 |
!AbsoluteTime methodsFor:'private'!
|
|
234 |
|
|
235 |
secondsLow
|
|
236 |
^ secondsLow
|
|
237 |
!
|
|
238 |
|
|
239 |
secondsHi
|
|
240 |
^ secondsHi
|
|
241 |
!
|
|
242 |
|
|
243 |
getSeconds
|
|
244 |
^ (secondsHi * 16r10000) + secondsLow
|
|
245 |
!
|
|
246 |
|
|
247 |
setSeconds:secs
|
|
248 |
secondsHi := secs // 16r10000.
|
|
249 |
secondsLow := secs \\ 16r10000
|
|
250 |
!
|
|
251 |
|
|
252 |
setSecondsLow:secsLow and:secsHi
|
|
253 |
secondsHi := secsHi.
|
|
254 |
secondsLow := secsLow
|
|
255 |
! !
|