author | Claus Gittinger <cg@exept.de> |
Mon, 17 Jan 2000 12:28:05 +0100 | |
changeset 5191 | 3da2c7f61745 |
parent 4929 | ac174b74d54e |
child 5548 | eead51e4752e |
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 |
|
5191 | 80 |
!AbstractTime class methodsFor:'Compatibility - ST80'! |
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 |
||
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
409 |
!AbstractTime methodsFor:'printing & storing'! |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
410 |
|
4844 | 411 |
addPrintBindingsTo:aDictionary |
412 |
"add bindings for printing to aDictionary." |
|
413 |
||
414 |
|hours minutes seconds millis usHours ampm s| |
|
415 |
||
416 |
hours := self hours. |
|
417 |
minutes := self minutes. |
|
418 |
seconds := self seconds. |
|
419 |
millis := self milliseconds. |
|
420 |
||
421 |
hours // 12 == 0 ifTrue:[ |
|
422 |
ampm := 'am'. |
|
423 |
] ifFalse:[ |
|
424 |
ampm := 'pm'. |
|
425 |
]. |
|
426 |
usHours := hours. |
|
427 |
usHours ~~ 0 ifTrue:[ |
|
428 |
usHours := usHours - 1 \\ 12 + 1. |
|
429 |
]. |
|
430 |
||
431 |
aDictionary at:$H put:(s := hours printString). |
|
432 |
aDictionary at:$h put:(s leftPaddedTo:2 with:$0). |
|
433 |
aDictionary at:$U put:(s := usHours printString). |
|
434 |
aDictionary at:$u put:(s leftPaddedTo:2 with:$0). |
|
435 |
aDictionary at:$M put:(s := minutes printString). |
|
436 |
aDictionary at:$m put:(s leftPaddedTo:2 with:$0). |
|
437 |
aDictionary at:$S put:(s := seconds printString). |
|
438 |
aDictionary at:$s put:(s leftPaddedTo:2 with:$0). |
|
439 |
aDictionary at:$I put:(s := millis printString). |
|
440 |
aDictionary at:$i put:(s leftPaddedTo:3 with:$0). |
|
4904
33d322c419ba
more format strings for milliseconds.
Claus Gittinger <cg@exept.de>
parents:
4844
diff
changeset
|
441 |
aDictionary at:#milli1 put:((millis // 100) printString). |
33d322c419ba
more format strings for milliseconds.
Claus Gittinger <cg@exept.de>
parents:
4844
diff
changeset
|
442 |
aDictionary at:#milli2 put:((millis // 10) printStringLeftPaddedTo:2 with:$0). |
4844 | 443 |
aDictionary at:$t put:(seconds * minutes) printString. |
444 |
aDictionary at:$T put:(seconds * minutes * hours) printString. |
|
445 |
aDictionary at:$a put:ampm. |
|
446 |
aDictionary at:$A put:ampm asUppercase. |
|
447 |
! |
|
448 |
||
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
449 |
printOn:aStream format:aFormatString |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
450 |
"print using a format string; |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
451 |
valid format items are: |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
452 |
%h hours, 00..23 (i.e. european) 0-padded to length 2 |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
453 |
%u hours, 00..12 (i.e. us) 0-padded to length 2 |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
454 |
%m minutes, 00..59 0-padded to length 2 |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
455 |
%s seconds, 00..59 0-padded to length 2 |
4841 | 456 |
%i milliseconds, 000..999 0-padded to length 3 |
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
457 |
%a am/pm |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
458 |
|
4844 | 459 |
AbsoluteTime only: |
460 |
%day day, 00..31 0-padded to length 2 |
|
461 |
%mon month, 00..12 0-padded to length 2 |
|
462 |
%yr year, 4 digits 0-padded to length 4 |
|
463 |
||
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
464 |
special: |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
465 |
%H 24-hours - unpadded |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
466 |
%U 12-hours - unpadded |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
467 |
%M minutes - unpadded |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
468 |
%S seconds - unpadded |
4844 | 469 |
%I milliseconds - unpadded |
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
470 |
%A AM/PM - uppercase |
4841 | 471 |
|
472 |
%t seconds within hour (unpadded) |
|
473 |
%T seconds from midNight (unpadded) |
|
4844 | 474 |
|
475 |
AbsoluteTime only: |
|
476 |
%Day day - unpadded |
|
477 |
%Mon month - unpadded |
|
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
478 |
" |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
479 |
|
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
480 |
aStream nextPutAll:(self printStringFormat:aFormatString) |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
481 |
|
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
482 |
" |
4650 | 483 |
AbsoluteTime now printOn:Transcript format:'%h:%m:%s' . Transcript cr. |
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
484 |
Time now printOn:Transcript format:'%h:%m:%s' . Transcript cr. |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
485 |
Time now printOn:Transcript format:'%H:%m:%s' . Transcript cr. |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
486 |
Time now printOn:Transcript format:'%u:%m:%s %a'. Transcript cr. |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
487 |
Time now printOn:Transcript format:'%h:%m' . Transcript cr. |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
488 |
Time now printOn:Transcript format:'%H:%m %A' . Transcript cr. |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
489 |
Time now printOn:Transcript format:'minutes:%M seconds:%S' . Transcript cr. |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
490 |
" |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
491 |
|
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
492 |
"Modified: 22.2.1996 / 16:58:30 / cg" |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
493 |
! |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
494 |
|
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
495 |
printStringFormat:aFormatString |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
496 |
"print using a format string; |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
497 |
valid format items are: |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
498 |
%h hours, 00..23 (i.e. european) 0-padded to length 2 |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
499 |
%u hours, 00..12 (i.e. us) 0-padded to length 2 |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
500 |
%m minutes, 00..59 0-padded to length 2 |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
501 |
%s seconds, 00..59 0-padded to length 2 |
4840
e97f4f2339d9
added milliseconds in printFormat
Claus Gittinger <cg@exept.de>
parents:
4835
diff
changeset
|
502 |
%i milliseconds, 000..999 0-padded to length 3 |
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
503 |
%a am/pm |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
504 |
|
4844 | 505 |
AbsoluteTime only: |
506 |
%day day, 00..31 0-padded to length 2 |
|
4929 | 507 |
%month month, 00..12 0-padded to length 2 |
508 |
%year year, 4 digits 0-padded to length 4 |
|
4844 | 509 |
|
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
510 |
special: |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
511 |
%H 24-hours - unpadded |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
512 |
%U 12-hours - unpadded |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
513 |
%M minutes - unpadded |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
514 |
%S seconds - unpadded |
4840
e97f4f2339d9
added milliseconds in printFormat
Claus Gittinger <cg@exept.de>
parents:
4835
diff
changeset
|
515 |
%I milliseconds, unpadded |
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
516 |
%A AM/PM - uppercase |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
517 |
|
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
518 |
%t seconds within hour (unpadded) |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
519 |
%T seconds from midNight (unpadded) |
4844 | 520 |
|
4904
33d322c419ba
more format strings for milliseconds.
Claus Gittinger <cg@exept.de>
parents:
4844
diff
changeset
|
521 |
%milli1 milliseconds, truncated to 1/10th of a second 0..9 |
33d322c419ba
more format strings for milliseconds.
Claus Gittinger <cg@exept.de>
parents:
4844
diff
changeset
|
522 |
%milli2 milliseconds, truncated to 1/100th of a second 00..99 0-padded to length 2 |
33d322c419ba
more format strings for milliseconds.
Claus Gittinger <cg@exept.de>
parents:
4844
diff
changeset
|
523 |
|
4844 | 524 |
AbsoluteTime only: |
525 |
%Day day - unpadded |
|
4929 | 526 |
%Month month - unpadded |
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
527 |
" |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
528 |
|
4844 | 529 |
|dict| |
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
530 |
|
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
531 |
dict := IdentityDictionary new. |
4844 | 532 |
self addPrintBindingsTo:dict. |
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
533 |
|
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
534 |
^ (aFormatString expandPlaceholdersWith:dict) |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
535 |
|
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
536 |
" |
4650 | 537 |
AbsoluteTime now printStringFormat:'%U:%m:%s %a' |
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
538 |
Time now printStringFormat:'%U:%m:%s %a' |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
539 |
|
4844 | 540 |
Time now printStringFormat:'%h:%m:%s' |
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
541 |
Time now printStringFormat:'%H:%m:%s' |
4844 | 542 |
Time now printStringFormat:'%H:%m:%s.%i' |
4905
a18c448021d2
more format strings for milliseconds.
Claus Gittinger <cg@exept.de>
parents:
4904
diff
changeset
|
543 |
AbsoluteTime now printStringFormat:'%H:%m:%s.%i' |
4904
33d322c419ba
more format strings for milliseconds.
Claus Gittinger <cg@exept.de>
parents:
4844
diff
changeset
|
544 |
AbsoluteTime now printStringFormat:'%H:%m:%s.%(milli1)' |
33d322c419ba
more format strings for milliseconds.
Claus Gittinger <cg@exept.de>
parents:
4844
diff
changeset
|
545 |
AbsoluteTime now printStringFormat:'%H:%m:%s.%(milli2)' |
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
546 |
Time now printStringFormat:'%u:%m:%s %a' |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
547 |
Time now printStringFormat:'%h:%m' |
4844 | 548 |
Time now printStringFormat:'%h:%m' |
4649
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
549 |
Time now printStringFormat:'%H:%m %A' |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
550 |
Time now printStringFormat:'%m minutes after %U %a' |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
551 |
Time now printStringFormat:'%t seconds after %U %a' |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
552 |
Time now printStringFormat:'%T seconds from midNight' |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
553 |
" |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
554 |
|
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
555 |
"Modified: 22.2.1996 / 16:58:30 / cg" |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
556 |
! ! |
3eaf75dd8973
Move printOn:format: to AbstractTime
Stefan Vogel <sv@exept.de>
parents:
3476
diff
changeset
|
557 |
|
699 | 558 |
!AbstractTime methodsFor:'private'! |
240 | 559 |
|
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
560 |
fromOSTime:osTime |
699 | 561 |
"set my time, from operatingSystems time parts" |
240 | 562 |
|
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
563 |
^ self subclassResponsibility |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
564 |
|
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
565 |
"Modified: 1.7.1996 / 15:09:44 / cg" |
240 | 566 |
! |
567 |
||
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
568 |
getMilliseconds |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
569 |
"get the milliseconds. |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
570 |
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
|
571 |
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
|
572 |
|
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
573 |
^ self subclassResponsibility |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
574 |
|
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
575 |
"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
|
576 |
! |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
577 |
|
699 | 578 |
getSeconds |
579 |
"get the seconds. |
|
580 |
Since I am abstract (not knowing how the time is actually |
|
581 |
represented), this must be done by a concrete class." |
|
240 | 582 |
|
699 | 583 |
^ self subclassResponsibility |
584 |
! |
|
585 |
||
1500
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
586 |
setMilliseconds:millis |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
587 |
"set the milliseconds. |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
588 |
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
|
589 |
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
|
590 |
|
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
591 |
^ self subclassResponsibility |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
592 |
|
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
593 |
"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
|
594 |
! |
d42e61e53cee
changed osTime to a largeInt, which includes the milliseconds
Claus Gittinger <cg@exept.de>
parents:
1476
diff
changeset
|
595 |
|
699 | 596 |
setSeconds:secs |
597 |
"set the seconds. |
|
598 |
Since I am abstract (not knowing how the time is actually |
|
599 |
represented), this must be done by a concrete class." |
|
600 |
||
601 |
^ self subclassResponsibility |
|
240 | 602 |
! ! |
603 |
||
2310
2cb1366e0eb3
Correct name: #secondDay --> #secondInDay.
Stefan Vogel <sv@exept.de>
parents:
1500
diff
changeset
|
604 |
!AbstractTime class methodsFor:'documentation'! |
240 | 605 |
|
699 | 606 |
version |
5191 | 607 |
^ '$Header: /cvs/stx/stx/libbasic/AbstractTime.st,v 1.25 2000-01-17 11:27:20 cg Exp $' |
240 | 608 |
! ! |