author | Claus Gittinger <cg@exept.de> |
Fri, 22 May 1998 12:47:19 +0200 | |
changeset 3476 | f2ebb76a952d |
parent 2310 | 2cb1366e0eb3 |
child 4649 | 3eaf75dd8973 |
permissions | -rw-r--r-- |
240 | 1 |
" |
2 |
COPYRIGHT (c) 1995 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:#AbstractTime |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
14 |
instanceVariableNames:'' |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
15 |
classVariableNames:'' |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
16 |
poolDictionaries:'' |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
17 |
category:'Magnitude-General' |
240 | 18 |
! |
19 |
||
2310
2cb1366e0eb3
Correct name: #secondDay --> #secondInDay.
Stefan Vogel <sv@exept.de>
parents:
1500
diff
changeset
|
20 |
!AbstractTime class methodsFor:'documentation'! |
240 | 21 |
|
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
25 |
All Rights Reserved |
|
26 |
||
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
38 |
This is an abstract class providing common protocol for Time (time in day) |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
39 |
and AbsoluteTime (time plus day). |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
40 |
There are no instances of this class in the system. |
275 | 41 |
It is meant as a home for methods common to time handling classes. |
1282 | 42 |
|
1295 | 43 |
[author:] |
44 |
Claus Gittinger |
|
45 |
||
1282 | 46 |
[See also:] |
47 |
Time Date AbsoluteTime |
|
48 |
Delay ProcessorScheduler |
|
240 | 49 |
" |
50 |
! ! |
|
51 |
||
2310
2cb1366e0eb3
Correct name: #secondDay --> #secondInDay.
Stefan Vogel <sv@exept.de>
parents:
1500
diff
changeset
|
52 |
!AbstractTime class methodsFor:'instance creation'! |
240 | 53 |
|
699 | 54 |
dateAndTimeNow |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
55 |
"return an array filled with the current date and time. |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
56 |
See also: Date today / Time now / AbsoluteTime now." |
240 | 57 |
|
699 | 58 |
^ Array with:(Date today) with:(Time now) |
240 | 59 |
|
60 |
" |
|
699 | 61 |
Time dateAndTimeNow |
240 | 62 |
" |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
63 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
64 |
"Modified: 19.4.1996 / 15:23:37 / cg" |
275 | 65 |
! |
240 | 66 |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
67 |
now |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
68 |
"return an instance of myself representing this moment." |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
69 |
|
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
70 |
^ self basicNew fromOSTime:(OperatingSystem getOSTime) |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
71 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
72 |
" |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
73 |
AbsoluteTime now |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
74 |
Time now |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
75 |
" |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
76 |
|
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
77 |
"Modified: 1.7.1996 / 15:20:10 / cg" |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
78 |
! ! |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
79 |
|
2310
2cb1366e0eb3
Correct name: #secondDay --> #secondInDay.
Stefan Vogel <sv@exept.de>
parents:
1500
diff
changeset
|
80 |
!AbstractTime class methodsFor:'ST-80 compatibility'! |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
81 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
82 |
totalSeconds |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
83 |
"returns an internal second clock. Dont interpret the returned |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
84 |
value - if at all, use it to compute time deltas, by subtracting |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
85 |
returned values." |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
86 |
|
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
87 |
^ self secondClock |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
88 |
! ! |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
89 |
|
2310
2cb1366e0eb3
Correct name: #secondDay --> #secondInDay.
Stefan Vogel <sv@exept.de>
parents:
1500
diff
changeset
|
90 |
!AbstractTime class methodsFor:'private instance creation'! |
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
91 |
|
275 | 92 |
fromOSTime:osTime |
93 |
"return a time, representing the time given by the operatingSystem time. |
|
94 |
Not meant for public use." |
|
95 |
||
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
96 |
^ self basicNew fromOSTime:osTime. |
418 | 97 |
|
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
98 |
"Modified: 1.7.1996 / 15:09:54 / cg" |
240 | 99 |
! |
100 |
||
699 | 101 |
fromSeconds:seconds |
102 |
"return an instance that is constructed from seconds. |
|
103 |
This method is only allowed for second values as returned by |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
104 |
getSeconds, possibly adding/subtracting to that. |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
105 |
Never depend on any specific interpretation of the seconds, |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
106 |
since it depends on how the OperatingSystem counts time |
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
107 |
(some start at 1900, others with 1970 ...)" |
240 | 108 |
|
699 | 109 |
^ self basicNew setSeconds:seconds |
240 | 110 |
|
111 |
" |
|
699 | 112 |
Time fromSeconds:0 should return midnight |
113 |
AbsoluteTime fromSeconds:0 on UNIX: returns 1st. Jan 1970 |
|
1227
e89b39909085
commentary & category changes
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
114 |
on others: dont know |
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
115 |
(AbsoluteTime day:1 month:1 year:1970 hour:1 minutes:0 seconds:0) |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
116 |
getSeconds on UNIX: returns 0 |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
117 |
on others: dont know |
699 | 118 |
" |
119 |
||
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
120 |
"Modified: 1.7.1996 / 13:39:30 / cg" |
240 | 121 |
! ! |
122 |
||
2310
2cb1366e0eb3
Correct name: #secondDay --> #secondInDay.
Stefan Vogel <sv@exept.de>
parents:
1500
diff
changeset
|
123 |
!AbstractTime class methodsFor:'queries'! |
275 | 124 |
|
699 | 125 |
millisecondClockValue |
126 |
"return the millisecond clock - since this one overruns |
|
127 |
regularly, use the value only for short timing deltas. |
|
128 |
Also remember that it wraps when compares these values." |
|
275 | 129 |
|
699 | 130 |
^ OperatingSystem getMillisecondTime. |
131 |
||
132 |
" |
|
133 |
Time millisecondClockValue |
|
134 |
" |
|
275 | 135 |
! |
136 |
||
699 | 137 |
secondClock |
138 |
"return seconds of now - for GNU-ST compatibility" |
|
139 |
||
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
140 |
^ OperatingSystem getOSTime // 1000 |
699 | 141 |
|
142 |
" |
|
143 |
AbstractTime secondClock |
|
144 |
" |
|
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
145 |
|
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
146 |
"Modified: 1.7.1996 / 15:20:14 / cg" |
699 | 147 |
! ! |
148 |
||
2310
2cb1366e0eb3
Correct name: #secondDay --> #secondInDay.
Stefan Vogel <sv@exept.de>
parents:
1500
diff
changeset
|
149 |
!AbstractTime class methodsFor:'timing evaluations'! |
275 | 150 |
|
699 | 151 |
millisecondsToRun:aBlock |
152 |
"evaluate the argument, aBlock; return the number of milliseconds it took" |
|
153 |
||
154 |
|startTime endTime| |
|
155 |
||
1476 | 156 |
startTime := OperatingSystem getMillisecondTime. |
699 | 157 |
aBlock value. |
1476 | 158 |
endTime := OperatingSystem getMillisecondTime. |
699 | 159 |
^ endTime - startTime |
160 |
||
161 |
" |
|
162 |
Time millisecondsToRun:[100 factorial] |
|
163 |
" |
|
1476 | 164 |
|
165 |
"Modified: 17.6.1996 / 16:57:37 / cg" |
|
275 | 166 |
! |
167 |
||
699 | 168 |
secondsToRun:aBlock |
169 |
"evaluate the argument, aBlock; return the number of seconds it took" |
|
170 |
||
171 |
|startTime endTime| |
|
360 | 172 |
|
699 | 173 |
startTime := self secondClock. |
174 |
aBlock value. |
|
175 |
endTime := self secondClock. |
|
176 |
^ endTime - startTime |
|
275 | 177 |
|
699 | 178 |
" |
179 |
Time secondsToRun:[1000 factorial] |
|
180 |
" |
|
275 | 181 |
! ! |
182 |
||
183 |
!AbstractTime methodsFor:'accessing'! |
|
184 |
||
185 |
hourInDay |
|
186 |
"return the hours (0..23)" |
|
187 |
||
188 |
^ self hours |
|
189 |
||
190 |
" |
|
191 |
AbsoluteTime now hourInDay |
|
192 |
Time now hourInDay |
|
193 |
" |
|
194 |
! |
|
195 |
||
196 |
minuteInDay |
|
197 |
"return the minutes (0..59)" |
|
198 |
||
199 |
^ self minutes. |
|
200 |
||
201 |
" |
|
202 |
AbsoluteTime now minuteInDay |
|
203 |
Time now minuteInDay |
|
204 |
" |
|
205 |
! |
|
206 |
||
2310
2cb1366e0eb3
Correct name: #secondDay --> #secondInDay.
Stefan Vogel <sv@exept.de>
parents:
1500
diff
changeset
|
207 |
secondInDay |
275 | 208 |
"return the seconds (0..59)" |
209 |
||
210 |
^ self seconds |
|
211 |
||
212 |
" |
|
213 |
AbsoluteTime now secondInDay |
|
214 |
Time now seconds |
|
215 |
" |
|
2310
2cb1366e0eb3
Correct name: #secondDay --> #secondInDay.
Stefan Vogel <sv@exept.de>
parents:
1500
diff
changeset
|
216 |
|
2cb1366e0eb3
Correct name: #secondDay --> #secondInDay.
Stefan Vogel <sv@exept.de>
parents:
1500
diff
changeset
|
217 |
"Created: 22.10.1996 / 09:27:47 / stefan" |
275 | 218 |
! ! |
219 |
||
220 |
!AbstractTime methodsFor:'arithmetic'! |
|
221 |
||
222 |
- aTime |
|
223 |
"return the delta in seconds between 2 times." |
|
224 |
||
225 |
^ self getSeconds - (aTime getSeconds) |
|
226 |
||
227 |
" |
|
228 |
|t1 t2| |
|
229 |
||
230 |
t1 := AbsoluteTime now. |
|
231 |
(Delay forSeconds:5) wait. |
|
232 |
t2 := AbsoluteTime now. |
|
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
233 |
Transcript showCR:('seconds passed: ' , (t2 - t1) printString). |
275 | 234 |
" |
235 |
! |
|
236 |
||
699 | 237 |
addHours:numberOfHours |
238 |
"return a new instance of myself, numberOfHours afterwards." |
|
275 | 239 |
|
699 | 240 |
^ self addSeconds:(numberOfHours * (60 * 60)) |
275 | 241 |
|
242 |
" |
|
243 |
|t| |
|
244 |
||
699 | 245 |
t := AbsoluteTime now. |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
246 |
Transcript showCR:t. |
699 | 247 |
t printNL. |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
248 |
Transcript showCR:(t addHours:12). |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
249 |
" |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
250 |
|
275 | 251 |
" |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
252 |
|t| |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
253 |
|
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
254 |
t := Time now. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
255 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
256 |
t printNL. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
257 |
Transcript showCR:(t addHours:12). |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
258 |
" |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
259 |
|
275 | 260 |
! |
261 |
||
262 |
addMinutes:numberOfMinutes |
|
263 |
"return a new instance of myself, numberOfMinutes afterwards." |
|
264 |
||
265 |
^ self addSeconds:(numberOfMinutes * 60) |
|
266 |
||
267 |
" |
|
268 |
|t| |
|
269 |
||
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
270 |
t := AbsoluteTime now. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
271 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
272 |
t printNL. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
273 |
Transcript showCR:(t addMinutes:60). |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
274 |
" |
275 | 275 |
|
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
276 |
" |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
277 |
|t| |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
278 |
|
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
279 |
t := Time now. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
280 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
281 |
t printNL. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
282 |
Transcript showCR:(t addMinutes:60). |
275 | 283 |
" |
284 |
! |
|
285 |
||
699 | 286 |
addSeconds:numberOfSeconds |
287 |
"return a new instance of myself, numberOfSeconds afterwards." |
|
288 |
||
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
289 |
^ self species basicNew |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
290 |
setMilliseconds:(self getMilliseconds + (numberOfSeconds * 1000)) |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
291 |
|
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
292 |
" |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
293 |
|t| |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
294 |
|
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
295 |
t := AbsoluteTime now. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
296 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
297 |
t printNL. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
298 |
Transcript showCR:(t addSeconds:60). |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
299 |
" |
699 | 300 |
|
301 |
" |
|
302 |
|t| |
|
303 |
||
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
304 |
t := Time now. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
305 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
306 |
t printNL. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
307 |
Transcript showCR:(t addSeconds:60). |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
308 |
" |
275 | 309 |
|
699 | 310 |
! |
311 |
||
312 |
addTime:timeAmount |
|
313 |
"return a new instance of myself, timeAmount seconds afterwards. |
|
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
314 |
Provided for ST-80 compatibility. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
315 |
WARNING: |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
316 |
AddTime is a bad name - it does not add a time, but expects |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
317 |
a numberOfSeconds as argument. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
318 |
Use any of addSeconds/addHours etc. to make things clear" |
699 | 319 |
|
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
320 |
^ self addSeconds:timeAmount |
699 | 321 |
! |
322 |
||
323 |
subtractHours:numberOfHours |
|
324 |
"return a new instance of myself, numberOfHours before." |
|
325 |
||
326 |
^ self subtractSeconds:(numberOfHours * (60 * 60)) |
|
275 | 327 |
|
328 |
" |
|
329 |
|t| |
|
330 |
||
331 |
t := AbsoluteTime now. |
|
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
332 |
Transcript showCR:t. |
275 | 333 |
t printNL. |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
334 |
Transcript showCR:(t subtractHours:12). |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
335 |
" |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
336 |
|
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
337 |
" |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
338 |
|t| |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
339 |
|
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
340 |
t := Time now. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
341 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
342 |
t printNL. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
343 |
Transcript showCR:(t subtractHours:12). |
275 | 344 |
" |
345 |
! |
|
346 |
||
347 |
subtractMinutes:numberOfMinutes |
|
348 |
"return a new instance of myself, numberOfMinutes before." |
|
349 |
||
350 |
^ self subtractSeconds:(numberOfMinutes * 60) |
|
351 |
||
352 |
" |
|
353 |
|t| |
|
354 |
||
355 |
t := AbsoluteTime now. |
|
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
356 |
Transcript showCR:t. |
275 | 357 |
t printNL. |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
358 |
Transcript showCR:(t subtractMinutes:60). |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
359 |
" |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
360 |
|
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
361 |
" |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
362 |
|t| |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
363 |
|
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
364 |
t := Time now. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
365 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
366 |
t printNL. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
367 |
Transcript showCR:(t subtractMinutes:60). |
275 | 368 |
" |
369 |
! |
|
370 |
||
699 | 371 |
subtractSeconds:numberOfSeconds |
372 |
"return a new instance of myself, numberOfSeconds before." |
|
275 | 373 |
|
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
374 |
^ self species basicNew |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
375 |
setMilliseconds:(self getMilliseconds - (numberOfSeconds * 1000)) |
275 | 376 |
|
377 |
" |
|
378 |
|t| |
|
379 |
||
380 |
t := AbsoluteTime now. |
|
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
381 |
Transcript showCR:t. |
275 | 382 |
t printNL. |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
383 |
Transcript showCR:(t subtractSeconds:60). |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
384 |
" |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
385 |
|
275 | 386 |
" |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
387 |
|t| |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
388 |
|
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
389 |
t := Time now. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
390 |
Transcript showCR:t. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
391 |
t printNL. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
392 |
Transcript showCR:(t subtractSeconds:60). |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
393 |
" |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
394 |
|
275 | 395 |
! |
396 |
||
397 |
subtractTime:timeAmount |
|
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
398 |
"return a new instance of myself, timeAmount seconds before myself. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
399 |
Provided for ST-80 compatibility. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
400 |
WARNING: |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
401 |
SubtractTime is a bad name - it does not add a time, but expects |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
402 |
a numberOfSeconds as argument. |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
403 |
Use any of addSeconds/addHours etc. to make things clear" |
275 | 404 |
|
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
405 |
^ self subtractSeconds:timeAmount |
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
406 |
|
275 | 407 |
! ! |
408 |
||
699 | 409 |
!AbstractTime methodsFor:'private'! |
240 | 410 |
|
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
411 |
fromOSTime:osTime |
699 | 412 |
"set my time, from operatingSystems time parts" |
240 | 413 |
|
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
414 |
^ self subclassResponsibility |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
415 |
|
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
416 |
"Modified: 1.7.1996 / 15:09:44 / cg" |
240 | 417 |
! |
418 |
||
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
419 |
getMilliseconds |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
420 |
"get the milliseconds. |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
421 |
Since I am abstract (not knowing how the time is actually |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
422 |
represented), this must be done by a concrete class." |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
423 |
|
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
424 |
^ self subclassResponsibility |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
425 |
|
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
426 |
"Created: 1.7.1996 / 14:16:49 / cg" |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
427 |
! |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
428 |
|
699 | 429 |
getSeconds |
430 |
"get the seconds. |
|
431 |
Since I am abstract (not knowing how the time is actually |
|
432 |
represented), this must be done by a concrete class." |
|
240 | 433 |
|
699 | 434 |
^ self subclassResponsibility |
435 |
! |
|
436 |
||
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
437 |
setMilliseconds:millis |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
438 |
"set the milliseconds. |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
439 |
Since I am abstract (not knowing how the time is actually |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
440 |
represented), this must be done by a concrete class." |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
441 |
|
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
442 |
^ self subclassResponsibility |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
443 |
|
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
444 |
"Created: 1.7.1996 / 14:17:00 / cg" |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
445 |
! |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
446 |
|
699 | 447 |
setSeconds:secs |
448 |
"set the seconds. |
|
449 |
Since I am abstract (not knowing how the time is actually |
|
450 |
represented), this must be done by a concrete class." |
|
451 |
||
452 |
^ self subclassResponsibility |
|
240 | 453 |
! ! |
454 |
||
2310
2cb1366e0eb3
Correct name: #secondDay --> #secondInDay.
Stefan Vogel <sv@exept.de>
parents:
1500
diff
changeset
|
455 |
!AbstractTime class methodsFor:'documentation'! |
240 | 456 |
|
699 | 457 |
version |
3476
f2ebb76a952d
dont loose milliseconds when adding seconds to a Timestamp.
Claus Gittinger <cg@exept.de>
parents:
2310
diff
changeset
|
458 |
^ '$Header: /cvs/stx/stx/libbasic/AbstractTime.st,v 1.15 1998-05-22 10:47:19 cg Exp $' |
240 | 459 |
! ! |