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