author | Claus Gittinger <cg@exept.de> |
Mon, 10 Dec 2001 17:30:04 +0100 | |
changeset 6267 | 10016cc16511 |
parent 6165 | 0ac589c3d92a |
child 6467 | f200ac48f2a8 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
6165 | 3 |
All Rights Reserved |
1 | 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 |
||
6165 | 13 |
"{ Package: 'stx:libbasic' }" |
5390 | 14 |
|
6165 | 15 |
AbstractTime subclass:#Time |
16 |
instanceVariableNames:'timeEncoding' |
|
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Magnitude-General' |
|
1 | 20 |
! |
21 |
||
6165 | 22 |
!Time class methodsFor:'documentation'! |
88 | 23 |
|
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
6165 | 27 |
All Rights Reserved |
88 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
Instances of time represent a particular time-of-day. |
|
409 | 41 |
Since they only store hours, minutes and seconds within a day, |
42 |
they cannot be used to compare times across midnight |
|
43 |
(i.e. they should not be used as timeStamps). |
|
1228 | 44 |
|
241 | 45 |
Use instances of AbsoluteTime (and read the comment there) to do this. |
46 |
||
47 |
Examples: |
|
1228 | 48 |
|t| |
241 | 49 |
|
1228 | 50 |
t := Time now. |
1422 | 51 |
Transcript showCR:t. |
241 | 52 |
|
53 |
||
1228 | 54 |
|t1 t2| |
241 | 55 |
|
1228 | 56 |
t1 := Time now. |
57 |
(Delay forSeconds:10) wait. |
|
58 |
t2 := Time now. |
|
59 |
t2 - t1 |
|
1295 | 60 |
|
61 |
[author:] |
|
62 |
Claus Gittinger |
|
63 |
||
64 |
[see also:] |
|
1302 | 65 |
Date AbsoluteTime AbstractTime OperatingSystem |
1295 | 66 |
Filename |
88 | 67 |
" |
68 |
! ! |
|
1 | 69 |
|
6165 | 70 |
!Time class methodsFor:'instance creation'! |
71 |
||
72 |
fromSeconds:secondsSinceMidnight |
|
73 |
"return a new Time, which represents the number of seconds since midNight. |
|
74 |
Be careful, time wraps - if the number of seconds exceeds the number of seconds |
|
75 |
in a day, a time relative to another days midnight is returned. |
|
76 |
(i.e. (Time fromSeconds:0) = (Time fromSeconds:24*3600)" |
|
77 |
||
78 |
|s| |
|
79 |
||
80 |
s := secondsSinceMidnight \\ (3600 * 24). |
|
81 |
^ self |
|
82 |
hours:(s // 3600) |
|
83 |
minutes:((s \\ 3600) // 60) |
|
84 |
seconds:((s \\ 3600) \\ 60) |
|
85 |
||
86 |
" |
|
87 |
Time fromSeconds:0 |
|
88 |
Time fromSeconds:3675 |
|
89 |
Time fromSeconds:36000 |
|
90 |
Time fromSeconds:72000 |
|
91 |
Time fromSeconds:96000 |
|
92 |
" |
|
93 |
||
94 |
"Modified: 8.10.1996 / 19:32:11 / cg" |
|
4411
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
95 |
|
6165 | 96 |
|
97 |
||
98 |
! |
|
99 |
||
100 |
hour:h minutes:m seconds:s |
|
101 |
"return an instance of Time representing the given time. |
|
102 |
See also Time now / Date today / AbsoluteTime now. |
|
103 |
Obsolete: please use #hours:minutes:seconds:" |
|
104 |
||
105 |
<resource:#obsolete> |
|
106 |
||
107 |
self obsoleteMethodWarning:'use hours:minutes:seconds:'. |
|
108 |
||
109 |
^ self hours:h minutes:m seconds:s |
|
110 |
||
111 |
" |
|
112 |
Time hours:2 minutes:33 seconds:0 |
|
113 |
Time hours:0 minutes:0 seconds:0 |
|
114 |
Time hours:24 minutes:0 seconds:0 |
|
115 |
Time hours23 minutes:59 seconds:59 |
|
116 |
" |
|
117 |
||
118 |
"Modified: 19.4.1996 / 15:32:40 / cg" |
|
119 |
! |
|
120 |
||
121 |
hours:h minutes:m seconds:s |
|
4031 | 122 |
"return an instance of Time representing the given time. |
123 |
See also Time now / Date today / AbsoluteTime now." |
|
124 |
||
6165 | 125 |
^ self basicNew setHours:h minutes:m seconds:s |
4031 | 126 |
|
127 |
" |
|
6165 | 128 |
Time hours:2 minutes:33 seconds:0 |
129 |
Time hours:0 minutes:0 seconds:0 |
|
130 |
Time hours:24 minutes:0 seconds:0 |
|
131 |
Time hours:23 minutes:59 seconds:59 |
|
95 | 132 |
" |
6165 | 133 |
|
134 |
"Modified: 19.4.1996 / 15:32:40 / cg" |
|
135 |
! |
|
136 |
||
137 |
readFrom:aStringOrStream onError:exceptionBlock |
|
138 |
"return a new Time, reading a printed representation from aStream. |
|
139 |
If no am/pm follows the time, the string is interpreted as |
|
140 |
either 24 hour format or being am." |
|
141 |
||
142 |
|newTime| |
|
143 |
||
144 |
ErrorSignal handle:[:ex | |
|
145 |
^ exceptionBlock value |
|
146 |
] do:[ |
|
147 |
|str hour min sec| |
|
148 |
||
149 |
str := aStringOrStream readStream. |
|
150 |
||
151 |
hour := Integer readFrom:str. |
|
152 |
(hour between:0 and:24) ifFalse:[^ exceptionBlock value]. |
|
153 |
||
154 |
min := 0. |
|
155 |
sec := 0. |
|
156 |
str atEnd ifFalse:[ |
|
157 |
(str peek == $:) ifTrue:[ |
|
158 |
str next. |
|
159 |
min := Integer readFrom:str. |
|
160 |
(min between:0 and:59) ifFalse:[^ exceptionBlock value]. |
|
161 |
||
162 |
(str peek == $:) ifTrue:[ |
|
163 |
str next. |
|
164 |
sec := Integer readFrom:str. |
|
165 |
(sec between:0 and:59) ifFalse:[^ exceptionBlock value]. |
|
166 |
]. |
|
167 |
]. |
|
168 |
[str peek == Character space] whileTrue:[str next]. |
|
169 |
(str peek == $p or:[str peek == $P]) ifTrue:[ |
|
170 |
str next. |
|
171 |
(str peek == $m or:[str peek == $M]) ifTrue:[ |
|
172 |
str next |
|
173 |
]. |
|
174 |
(hour <= 0 or:[hour > 12]) ifTrue:[^ exceptionBlock value]. |
|
175 |
||
176 |
"pm" |
|
177 |
hour ~~ 12 ifTrue:[ |
|
178 |
hour := hour + 12 |
|
179 |
] |
|
180 |
] ifFalse:[ |
|
181 |
(str peek == $a or:[str peek == $A]) ifTrue:[ |
|
182 |
str next. |
|
183 |
(str peek == $m or:[str peek == $M]) ifTrue:[ |
|
184 |
str next |
|
185 |
]. |
|
186 |
hour >= 12 ifTrue:[^ exceptionBlock value]. |
|
187 |
hour == 24 ifTrue:[ |
|
188 |
hour := 0. |
|
189 |
] |
|
190 |
] |
|
191 |
] |
|
192 |
]. |
|
193 |
newTime := self basicNew setHours:hour minutes:min seconds:sec |
|
194 |
]. |
|
195 |
^ newTime |
|
196 |
||
197 |
" |
|
198 |
Time readFrom:'0:00' |
|
199 |
Time readFrom:'2:00' |
|
200 |
Time readFrom:'12:00' |
|
201 |
Time readFrom:'14:00' |
|
202 |
Time readFrom:'23:00' |
|
203 |
Time readFrom:'24:00' |
|
204 |
Time readFrom:'2:30 am' |
|
205 |
Time readFrom:'2:30 pm' |
|
206 |
Time readFrom:'14' |
|
207 |
Time readFrom:'2 am' |
|
208 |
Time readFrom:'2 pm' |
|
209 |
||
210 |
Time readFrom:'18:22:00' |
|
211 |
Time readFrom:'14:00:11' |
|
212 |
Time readFrom:'7:00:11' |
|
213 |
Time readFrom:'24:00:00' |
|
214 |
Time readFrom:'0:00:00' |
|
215 |
Time readFrom:'12:00:00' |
|
216 |
Time readFrom:'0:00:00' |
|
217 |
Time readFrom:'6:22:00 pm' |
|
218 |
Time readFrom:'2:00:11 pm' |
|
219 |
Time readFrom:'7:00:11 am' |
|
220 |
Time readFrom:'12:00:00 am' |
|
221 |
Time readFrom:'0:00:00 am' |
|
222 |
Time readFrom:'24:00:00 am' |
|
223 |
Time readFrom:'12:00:00 pm' |
|
224 |
Time readFrom:'0:00:00 pm' - invalid |
|
225 |
Time readFrom:'24:00:00 pm' |
|
226 |
" |
|
227 |
||
228 |
"Modified: 8.10.1996 / 19:32:11 / cg" |
|
1 | 229 |
! ! |
230 |
||
6165 | 231 |
!Time class methodsFor:'format strings'! |
4411
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
232 |
|
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
233 |
formatString12us |
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
234 |
"return the format string used to format US times (and other areas)" |
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
235 |
|
6165 | 236 |
^ '%u:%m:%s %a' |
4411
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
237 |
! |
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
238 |
|
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
239 |
formatString24 |
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
240 |
"return the format string used to format european times (and other areas)" |
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
241 |
|
6164 | 242 |
^ '%h:%m:%s' |
243 |
! ! |
|
244 |
||
245 |
!Time methodsFor:'Compatibility - Squeak'! |
|
246 |
||
247 |
intervalString |
|
248 |
"Treat the time as a difference. |
|
249 |
Give it in hours and minutes with two digits of accuracy." |
|
250 |
||
251 |
|hours minutes seconds hh mm ss | |
|
252 |
||
253 |
hours := self hours. |
|
254 |
minutes := self minutes. |
|
255 |
seconds := self seconds. |
|
256 |
hh := hours = 0 ifTrue: [''] ifFalse: [' ', hours printString, ' hours']. |
|
257 |
mm := minutes = 0 ifTrue: [''] ifFalse: [' ', minutes printString, ' minutes']. |
|
258 |
ss := seconds = 0 ifTrue: [''] ifFalse: [' ', seconds printString, ' seconds']. |
|
259 |
hh size > 0 ifTrue: [ss := '']. |
|
260 |
^ hh, mm, ss |
|
261 |
||
262 |
" |
|
263 |
(Time fromSeconds:3600) intervalString |
|
264 |
(Time fromSeconds:3605) intervalString |
|
265 |
(Time fromSeconds:5) intervalString |
|
266 |
(Time fromSeconds:65) intervalString |
|
267 |
" |
|
268 |
! |
|
269 |
||
270 |
print24:prnt24Format showSeconds:doSeconds on:aStream |
|
271 |
"print me either US or 24hr format, optionally with |
|
272 |
seconds on a stream" |
|
273 |
||
274 |
|format| |
|
275 |
||
276 |
prnt24Format ifTrue:[ |
|
277 |
doSeconds ifTrue:[ |
|
278 |
format := '%h:%m:%s' |
|
279 |
] ifFalse:[ |
|
280 |
format := '%h:%m' |
|
281 |
]. |
|
282 |
] ifFalse:[ |
|
283 |
"/ US format |
|
284 |
doSeconds ifTrue:[ |
|
285 |
format := '%u:%m:%s %a' |
|
286 |
] ifFalse:[ |
|
287 |
format := '%u:%m %a' |
|
288 |
]. |
|
289 |
]. |
|
290 |
^ self |
|
291 |
printOn:aStream |
|
292 |
format:format. |
|
293 |
||
294 |
" |
|
295 |
Time now print24:true showSeconds:true on:Transcript. Transcript cr. |
|
296 |
Time now print24:false showSeconds:true on:Transcript. Transcript cr. |
|
297 |
Time now print24:true showSeconds:false on:Transcript. Transcript cr. |
|
298 |
Time now print24:false showSeconds:false on:Transcript. Transcript cr. |
|
299 |
" |
|
4411
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
300 |
! ! |
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
301 |
|
6164 | 302 |
!Time methodsFor:'accessing'! |
303 |
||
304 |
day |
|
305 |
"catch day access - Time does not know about it" |
|
306 |
||
307 |
^ self shouldNotImplement |
|
308 |
! |
|
309 |
||
310 |
hours |
|
311 |
"return the number of hours since midnight (i.e. 0..23)" |
|
312 |
||
313 |
^ self getSeconds // 3600 |
|
314 |
||
315 |
" |
|
316 |
Time now hours |
|
317 |
" |
|
318 |
! |
|
275 | 319 |
|
4845 | 320 |
milliseconds |
6164 | 321 |
"time does not keep milliseconds |
322 |
- for compatibility with absoluteTime" |
|
323 |
||
324 |
^ 0 |
|
325 |
! |
|
326 |
||
327 |
minutes |
|
328 |
"return the number of minutes within the hour (i.e. 0..59)" |
|
329 |
||
330 |
^ (self getSeconds \\ 3600) // 60 |
|
331 |
||
332 |
" |
|
333 |
Time now minutes |
|
334 |
" |
|
335 |
! |
|
336 |
||
337 |
month |
|
338 |
"catch month access - Time does not know about it" |
|
339 |
||
340 |
^ self shouldNotImplement |
|
341 |
! |
|
342 |
||
343 |
seconds |
|
344 |
"return the number of seconds within the minute (i.e. 0..59)" |
|
345 |
||
346 |
^ (self getSeconds \\ 3600) \\ 60 |
|
347 |
||
348 |
" |
|
349 |
Time now seconds |
|
350 |
" |
|
351 |
! |
|
352 |
||
353 |
year |
|
354 |
"catch year access - Time does not know about it" |
|
355 |
||
356 |
^ self shouldNotImplement |
|
1 | 357 |
! ! |
358 |
||
6164 | 359 |
!Time methodsFor:'comparing'! |
360 |
||
361 |
< aTime |
|
362 |
"return true if the receiver is before the argument" |
|
363 |
||
6165 | 364 |
^ self getSeconds < aTime getSeconds |
6164 | 365 |
! |
366 |
||
367 |
= aTime |
|
368 |
"return true if the argument, aTime represents the same timeOfDay" |
|
369 |
||
370 |
aTime class == self class ifTrue:[ |
|
371 |
^ timeEncoding == aTime timeEncoding |
|
372 |
]. |
|
373 |
(aTime species == self species) ifFalse:[^ false]. |
|
6165 | 374 |
^ self getSeconds == aTime getSeconds |
6164 | 375 |
! |
376 |
||
377 |
> aTime |
|
378 |
"return true if the receiver is before the argument" |
|
379 |
||
6165 | 380 |
^ self getSeconds > aTime getSeconds |
6164 | 381 |
! |
382 |
||
383 |
hash |
|
384 |
"return an integer useful for hashing on times" |
|
385 |
||
6165 | 386 |
^ self getSeconds |
6164 | 387 |
! ! |
388 |
||
389 |
!Time methodsFor:'converting'! |
|
390 |
||
391 |
asAbsoluteTime |
|
392 |
"return an AbsoluteTime object from the receiver. |
|
393 |
The date components are taken from today." |
|
394 |
||
395 |
|today| |
|
396 |
||
397 |
today := Date today. |
|
398 |
^ AbsoluteTime year:today year month:today month day:today day |
|
399 |
hour:(self hours) minute:(self minutes) second:(self seconds) |
|
400 |
millisecond:(self milliseconds) |
|
401 |
" |
|
402 |
Time now asAbsoluteTime |
|
403 |
" |
|
404 |
||
405 |
"Modified: / 13.7.1999 / 12:32:08 / stefan" |
|
406 |
! |
|
407 |
||
408 |
asSeconds |
|
409 |
"return the number of seconds elapsed since midnight" |
|
410 |
||
411 |
^ self getSeconds |
|
412 |
||
413 |
" |
|
414 |
Time now asSeconds |
|
415 |
" |
|
416 |
! |
|
95 | 417 |
|
699 | 418 |
asTime |
419 |
"return a Time object from the receiver - thats the receiver." |
|
420 |
||
6164 | 421 |
^ self |
699 | 422 |
! ! |
423 |
||
6164 | 424 |
!Time methodsFor:'printing & storing'! |
425 |
||
426 |
print12HourFormatOn:aStream |
|
427 |
"append a printed representation of the receiver to aStream. |
|
428 |
Format is hh:mm:ss am/pm (i.e. 12-hour american format)." |
|
429 |
||
430 |
^ self |
|
431 |
printOn:aStream |
|
432 |
format:(self class formatString12us) |
|
433 |
||
434 |
"/ |h m s ampm| |
|
435 |
"/ |
|
436 |
"/ h := self hours. |
|
437 |
"/ |
|
438 |
"/ "/ 0 -> 12 am |
|
439 |
"/ "/ 12 -> 12 pm |
|
440 |
"/ |
|
441 |
"/ h // 12 == 0 ifTrue:[ |
|
442 |
"/ ampm := ' am'. |
|
443 |
"/ ] ifFalse:[ |
|
444 |
"/ ampm := ' pm'. |
|
445 |
"/ ]. |
|
446 |
"/ |
|
447 |
"/ h == 0 ifFalse:[ |
|
448 |
"/ h := h - 1 \\ 12 + 1. |
|
449 |
"/ ]. |
|
450 |
"/ |
|
451 |
"/ h printOn:aStream. |
|
452 |
"/ aStream nextPut:$:. |
|
453 |
"/ m := self minutes. |
|
454 |
"/ (m < 10) ifTrue:[aStream nextPut:$0]. |
|
455 |
"/ m printOn:aStream. |
|
456 |
"/ aStream nextPut:$:. |
|
457 |
"/ s := self seconds. |
|
458 |
"/ (s < 10) ifTrue:[aStream nextPut:$0]. |
|
459 |
"/ s printOn:aStream. |
|
460 |
"/ aStream nextPutAll:ampm |
|
461 |
||
462 |
" |
|
463 |
Time now print12HourFormatOn:Transcript. Transcript cr |
|
464 |
(Time now subtractHours:12) print12HourFormatOn:Transcript. Transcript cr |
|
465 |
(Time hour:24 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr |
|
466 |
(Time hour:12 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr |
|
467 |
(Time hour:0 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr |
|
468 |
0 to:24 do:[:h | |
|
469 |
(Time hour:h minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr |
|
470 |
] |
|
471 |
" |
|
472 |
! |
|
473 |
||
474 |
print24HourFormatOn:aStream |
|
475 |
"append a printed representation of the receiver to aStream. |
|
476 |
Format is hh:mm:ss (i.e. 24-hour european format)." |
|
477 |
||
478 |
^ self |
|
479 |
printOn:aStream |
|
480 |
format:(self class formatString24). |
|
481 |
||
482 |
"/ |h m s| |
|
483 |
"/ |
|
484 |
"/ h := self hours. |
|
485 |
"/ (h < 10) ifTrue:[aStream nextPut:$0]. |
|
486 |
"/ h printOn:aStream. |
|
487 |
"/ aStream nextPut:$:. |
|
488 |
"/ m := self minutes. |
|
489 |
"/ (m < 10) ifTrue:[aStream nextPut:$0]. |
|
490 |
"/ m printOn:aStream. |
|
491 |
"/ aStream nextPut:$:. |
|
492 |
"/ s := self seconds. |
|
493 |
"/ (s < 10) ifTrue:[aStream nextPut:$0]. |
|
494 |
"/ s printOn:aStream |
|
495 |
||
496 |
" |
|
497 |
Time now print24HourFormatOn:Transcript. Transcript cr |
|
498 |
" |
|
499 |
! |
|
500 |
||
501 |
printOn:aStream |
|
502 |
"append a user printed representation of the receiver to aStream. |
|
503 |
The format is suitable for a human - not meant to be read back. |
|
504 |
||
505 |
Format is hh:mm:ss either in 12-hour or 24-hour format. |
|
506 |
depending on the setting of LanguageTerritory. |
|
507 |
I dont know what ST-80 does here (12-hour format ?)" |
|
508 |
||
509 |
LanguageTerritory == #us ifTrue:[ |
|
510 |
self print12HourFormatOn:aStream |
|
511 |
] ifFalse:[ |
|
512 |
self print24HourFormatOn:aStream |
|
513 |
] |
|
514 |
||
515 |
" |
|
516 |
Time now printOn:Transcript. Transcript cr |
|
517 |
" |
|
518 |
||
519 |
"Modified: 22.2.1996 / 16:58:30 / cg" |
|
520 |
! |
|
521 |
||
522 |
printString12HourFormat |
|
523 |
"return a printed representation in 12 hour format" |
|
524 |
||
525 |
^ self printStringFormat:(self class formatString12us) |
|
526 |
||
527 |
" |
|
528 |
Time now printString12HourFormat |
|
529 |
" |
|
530 |
! |
|
531 |
||
532 |
printString24HourFormat |
|
533 |
"return a printed representation in 24 hour format" |
|
534 |
||
535 |
^ self printStringFormat:(self class formatString24) |
|
536 |
||
537 |
" |
|
538 |
Time now printString24HourFormat |
|
539 |
" |
|
540 |
||
541 |
! |
|
542 |
||
543 |
shortPrintString |
|
544 |
"dummy - for now" |
|
545 |
||
546 |
^ self printString |
|
547 |
||
548 |
"Created: 20.6.1997 / 17:17:01 / cg" |
|
549 |
! ! |
|
550 |
||
551 |
!Time methodsFor:'private'! |
|
552 |
||
553 |
fromOSTime:osTime |
|
554 |
"set my time, given an osTime" |
|
555 |
||
556 |
|h m s| |
|
557 |
||
558 |
OperatingSystem computeTimePartsOf:osTime for:[ |
|
559 |
:hours :minutes :secs :millis | |
|
560 |
||
561 |
h := hours. |
|
562 |
m := minutes. |
|
563 |
s := secs. |
|
564 |
]. |
|
565 |
self setHours:h minutes:m seconds:s |
|
566 |
||
567 |
"Modified: 1.7.1996 / 15:21:06 / cg" |
|
568 |
! |
|
275 | 569 |
|
3477 | 570 |
getMilliseconds |
6046 | 571 |
"return the number of milliseconds since midnight" |
572 |
||
6165 | 573 |
^ self getSeconds * 1000 |
3477 | 574 |
! |
575 |
||
275 | 576 |
getSeconds |
6046 | 577 |
"return the number of seconds since midnight" |
578 |
||
6165 | 579 |
^ timeEncoding |
275 | 580 |
! |
581 |
||
6165 | 582 |
setHours:h minutes:m seconds:s |
699 | 583 |
"set my time given individual values" |
584 |
||
6165 | 585 |
self setSeconds:(((h\\24) * 60 * 60 ) + (m * 60) + s). |
3477 | 586 |
! |
587 |
||
588 |
setMilliseconds:millis |
|
589 |
"set my time given milliseconds since midnight" |
|
590 |
||
6165 | 591 |
self setSeconds:(millis // 1000) |
699 | 592 |
! |
593 |
||
275 | 594 |
setSeconds:secs |
595 |
"set my time given seconds since midnight" |
|
596 |
||
6165 | 597 |
secs < 0 ifTrue:[ |
598 |
timeEncoding := (24 * 3600) - (secs negated \\ (24 * 3600)) |
|
599 |
] ifFalse:[ |
|
600 |
timeEncoding := secs |
|
601 |
]. |
|
602 |
timeEncoding > (24 * 3600) ifTrue:[ |
|
603 |
timeEncoding := timeEncoding \\ (24 * 3600). |
|
604 |
] |
|
605 |
||
606 |
" |
|
607 |
Time now seconds |
|
608 |
Time now timeEncoding |
|
609 |
(Time now addDays:5) seconds |
|
610 |
(Time now addDays:5) timeEncoding |
|
611 |
" |
|
612 |
! |
|
613 |
||
614 |
timeEncoding |
|
615 |
"the internal encoding is stricktly private, |
|
616 |
and should not be used outside." |
|
617 |
||
618 |
^ timeEncoding |
|
619 |
! |
|
620 |
||
621 |
timeEncoding:encoding |
|
622 |
"the internal encoding is stricktly private, |
|
623 |
and should not be used outside." |
|
624 |
||
625 |
timeEncoding := encoding |
|
699 | 626 |
! ! |
627 |
||
6165 | 628 |
!Time class methodsFor:'documentation'! |
241 | 629 |
|
699 | 630 |
version |
6165 | 631 |
^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.52 2001-11-08 16:07:36 md Exp $' |
241 | 632 |
! ! |