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