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