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