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