author | Stefan Vogel <sv@exept.de> |
Tue, 13 Jul 1999 12:49:22 +0200 | |
changeset 4379 | 20ba95273826 |
parent 4031 | de8ae1bf2827 |
child 4392 | 26fb48f04e1b |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
159 | 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 |
||
275 | 13 |
AbstractTime subclass:#Time |
993
feaa62827c41
check for territory being #us (instead of #usa) when printing
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
14 |
instanceVariableNames:'timeEncoding' |
feaa62827c41
check for territory being #us (instead of #usa) when printing
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
15 |
classVariableNames:'' |
feaa62827c41
check for territory being #us (instead of #usa) when printing
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
16 |
poolDictionaries:'' |
feaa62827c41
check for territory being #us (instead of #usa) when printing
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
17 |
category:'Magnitude-General' |
1 | 18 |
! |
19 |
||
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
20 |
!Time class methodsFor:'documentation'! |
88 | 21 |
|
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
159 | 25 |
All Rights Reserved |
88 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
Instances of time represent a particular time-of-day. |
|
409 | 39 |
Since they only store hours, minutes and seconds within a day, |
40 |
they cannot be used to compare times across midnight |
|
41 |
(i.e. they should not be used as timeStamps). |
|
1228 | 42 |
|
241 | 43 |
Use instances of AbsoluteTime (and read the comment there) to do this. |
44 |
||
45 |
Examples: |
|
1228 | 46 |
|t| |
241 | 47 |
|
1228 | 48 |
t := Time now. |
1422 | 49 |
Transcript showCR:t. |
241 | 50 |
|
51 |
||
1228 | 52 |
|t1 t2| |
241 | 53 |
|
1228 | 54 |
t1 := Time now. |
55 |
(Delay forSeconds:10) wait. |
|
56 |
t2 := Time now. |
|
57 |
t2 - t1 |
|
1295 | 58 |
|
59 |
[author:] |
|
60 |
Claus Gittinger |
|
61 |
||
62 |
[see also:] |
|
1302 | 63 |
Date AbsoluteTime AbstractTime OperatingSystem |
1295 | 64 |
Filename |
88 | 65 |
" |
66 |
! ! |
|
1 | 67 |
|
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
68 |
!Time class methodsFor:'instance creation'! |
1 | 69 |
|
239 | 70 |
hour:h minutes:m seconds:s |
1228 | 71 |
"return an instance of Time representing the given time. |
4031 | 72 |
See also Time now / Date today / AbsoluteTime now. |
73 |
Obsolete: please use #hours:minutes:seconds:" |
|
239 | 74 |
|
4031 | 75 |
self obsoleteMethodWarning:'use hours:minutes:seconds:'. |
76 |
||
77 |
^ self hours:h minutes:m seconds:s |
|
1 | 78 |
|
239 | 79 |
" |
4031 | 80 |
Time hours:2 minutes:33 seconds:0 |
81 |
Time hours:0 minutes:0 seconds:0 |
|
82 |
Time hours:24 minutes:0 seconds:0 |
|
83 |
Time hours23 minutes:59 seconds:59 |
|
84 |
" |
|
85 |
||
86 |
"Modified: 19.4.1996 / 15:32:40 / cg" |
|
87 |
! |
|
88 |
||
89 |
hours:h minutes:m seconds:s |
|
90 |
"return an instance of Time representing the given time. |
|
91 |
See also Time now / Date today / AbsoluteTime now." |
|
92 |
||
93 |
^ self basicNew setHours:h minutes:m seconds:s |
|
94 |
||
95 |
" |
|
96 |
Time hours:2 minutes:33 seconds:0 |
|
97 |
Time hours:0 minutes:0 seconds:0 |
|
98 |
Time hours:24 minutes:0 seconds:0 |
|
99 |
Time hours:23 minutes:59 seconds:59 |
|
95 | 100 |
" |
1228 | 101 |
|
102 |
"Modified: 19.4.1996 / 15:32:40 / cg" |
|
77 | 103 |
! |
104 |
||
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
105 |
readFrom:aStringOrStream onError:exceptionBlock |
241 | 106 |
"return a new Time, reading a printed representation from aStream. |
3481
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
107 |
If no am/pm follows the time, the string is interpreted as |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
108 |
either 24 hour format or being am." |
239 | 109 |
|
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3709
diff
changeset
|
110 |
|newTime| |
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3709
diff
changeset
|
111 |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1502
diff
changeset
|
112 |
ErrorSignal handle:[:ex | |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1502
diff
changeset
|
113 |
^ exceptionBlock value |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1502
diff
changeset
|
114 |
] do:[ |
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3709
diff
changeset
|
115 |
|str hour min sec| |
216 | 116 |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1502
diff
changeset
|
117 |
str := aStringOrStream readStream. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1502
diff
changeset
|
118 |
|
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3709
diff
changeset
|
119 |
hour := Integer readFrom:str. |
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3709
diff
changeset
|
120 |
(hour between:0 and:24) ifFalse:[^ exceptionBlock value]. |
275 | 121 |
|
3481
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
122 |
min := 0. |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
123 |
sec := 0. |
3477 | 124 |
str atEnd ifFalse:[ |
3481
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
125 |
(str peek == $:) ifTrue:[ |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
126 |
str next. |
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3709
diff
changeset
|
127 |
min := Integer readFrom:str. |
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3709
diff
changeset
|
128 |
(min between:0 and:59) ifFalse:[^ exceptionBlock value]. |
275 | 129 |
|
3481
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
130 |
(str peek == $:) ifTrue:[ |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
131 |
str next. |
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3709
diff
changeset
|
132 |
sec := Integer readFrom:str. |
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3709
diff
changeset
|
133 |
(sec between:0 and:59) ifFalse:[^ exceptionBlock value]. |
3481
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
134 |
]. |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
135 |
]. |
3477 | 136 |
[str peek == Character space] whileTrue:[str next]. |
3481
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
137 |
(str peek == $p or:[str peek == $P]) ifTrue:[ |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
138 |
str next. |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
139 |
(str peek == $m or:[str peek == $M]) ifTrue:[ |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
140 |
str next |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
141 |
]. |
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3709
diff
changeset
|
142 |
(hour <= 0 or:[hour > 12]) ifTrue:[^ exceptionBlock value]. |
3478 | 143 |
|
3477 | 144 |
"pm" |
3478 | 145 |
hour ~~ 12 ifTrue:[ |
146 |
hour := hour + 12 |
|
147 |
] |
|
148 |
] ifFalse:[ |
|
3481
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
149 |
(str peek == $a or:[str peek == $A]) ifTrue:[ |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
150 |
str next. |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
151 |
(str peek == $m or:[str peek == $M]) ifTrue:[ |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
152 |
str next |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
153 |
]. |
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3709
diff
changeset
|
154 |
hour >= 12 ifTrue:[^ exceptionBlock value]. |
3478 | 155 |
hour == 24 ifTrue:[ |
156 |
hour := 0. |
|
157 |
] |
|
158 |
] |
|
159 |
] |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1502
diff
changeset
|
160 |
]. |
4031 | 161 |
newTime := self basicNew setHours:hour minutes:min seconds:sec |
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3709
diff
changeset
|
162 |
]. |
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3709
diff
changeset
|
163 |
^ newTime |
216 | 164 |
|
239 | 165 |
" |
3481
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
166 |
Time readFrom:'0:00' |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
167 |
Time readFrom:'2:00' |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
168 |
Time readFrom:'12:00' |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
169 |
Time readFrom:'14:00' |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
170 |
Time readFrom:'23:00' |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
171 |
Time readFrom:'24:00' |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
172 |
Time readFrom:'2:30 am' |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
173 |
Time readFrom:'2:30 pm' |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
174 |
Time readFrom:'14' |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
175 |
Time readFrom:'2 am' |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
176 |
Time readFrom:'2 pm' |
1da093bda862
allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents:
3478
diff
changeset
|
177 |
|
409 | 178 |
Time readFrom:'18:22:00' |
179 |
Time readFrom:'14:00:11' |
|
180 |
Time readFrom:'7:00:11' |
|
3478 | 181 |
Time readFrom:'24:00:00' |
182 |
Time readFrom:'0:00:00' |
|
183 |
Time readFrom:'12:00:00' |
|
184 |
Time readFrom:'0:00:00' |
|
409 | 185 |
Time readFrom:'6:22:00 pm' |
186 |
Time readFrom:'2:00:11 pm' |
|
187 |
Time readFrom:'7:00:11 am' |
|
3478 | 188 |
Time readFrom:'12:00:00 am' |
189 |
Time readFrom:'0:00:00 am' |
|
190 |
Time readFrom:'24:00:00 am' |
|
191 |
Time readFrom:'12:00:00 pm' |
|
192 |
Time readFrom:'0:00:00 pm' - invalid |
|
193 |
Time readFrom:'24:00:00 pm' |
|
239 | 194 |
" |
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
195 |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1502
diff
changeset
|
196 |
"Modified: 8.10.1996 / 19:32:11 / cg" |
1 | 197 |
! ! |
198 |
||
95 | 199 |
!Time methodsFor:'accessing'! |
77 | 200 |
|
699 | 201 |
day |
202 |
"catch day access - Time does not know about it" |
|
77 | 203 |
|
699 | 204 |
^ self shouldNotImplement |
1 | 205 |
! |
206 |
||
241 | 207 |
hours |
208 |
"return the number of hours since midnight (i.e. 0..23)" |
|
95 | 209 |
|
241 | 210 |
^ timeEncoding // 3600 |
211 |
||
212 |
" |
|
213 |
Time now hours |
|
214 |
" |
|
275 | 215 |
! |
216 |
||
699 | 217 |
minutes |
218 |
"return the number of minutes within the hour (i.e. 0..59)" |
|
275 | 219 |
|
699 | 220 |
^ (timeEncoding \\ 3600) // 60 |
221 |
||
222 |
" |
|
223 |
Time now minutes |
|
224 |
" |
|
275 | 225 |
! |
226 |
||
227 |
month |
|
228 |
"catch month access - Time does not know about it" |
|
229 |
||
230 |
^ self shouldNotImplement |
|
231 |
! |
|
232 |
||
699 | 233 |
seconds |
234 |
"return the number of seconds within the minute (i.e. 0..59)" |
|
235 |
||
236 |
^ (timeEncoding \\ 3600) \\ 60 |
|
237 |
||
238 |
" |
|
239 |
Time now seconds |
|
240 |
" |
|
241 |
! |
|
242 |
||
275 | 243 |
year |
244 |
"catch year access - Time does not know about it" |
|
245 |
||
246 |
^ self shouldNotImplement |
|
1 | 247 |
! ! |
248 |
||
699 | 249 |
!Time methodsFor:'comparing'! |
250 |
||
251 |
< aTime |
|
252 |
"return true if the argument, aTime is before the receiver" |
|
253 |
||
254 |
^ timeEncoding < aTime timeEncoding |
|
255 |
! |
|
1 | 256 |
|
699 | 257 |
= aTime |
258 |
"return true if the argument, aTime represents the same timeOfDay" |
|
259 |
||
260 |
aTime class == self class ifTrue:[ |
|
261 |
^ timeEncoding == aTime timeEncoding |
|
262 |
]. |
|
263 |
(aTime species == self species) ifFalse:[^ false]. |
|
264 |
^ self asSeconds == aTime asSeconds |
|
265 |
! |
|
266 |
||
267 |
> aTime |
|
268 |
"return true if the argument, aTime is after the receiver" |
|
95 | 269 |
|
699 | 270 |
^ timeEncoding > aTime timeEncoding |
271 |
! |
|
272 |
||
273 |
hash |
|
274 |
"return an integer useful for hashing on times" |
|
275 |
||
276 |
^ timeEncoding |
|
277 |
! ! |
|
278 |
||
279 |
!Time methodsFor:'converting'! |
|
95 | 280 |
|
699 | 281 |
asAbsoluteTime |
282 |
"return an AbsoluteTime object from the receiver. |
|
283 |
The date components are taken from today." |
|
284 |
||
285 |
|today| |
|
286 |
||
287 |
today := Date today. |
|
4379 | 288 |
^ AbsoluteTime year:today year month:today month day:today day |
289 |
hour:self hours minute:self minutes second:self seconds |
|
95 | 290 |
" |
699 | 291 |
Time now asAbsoluteTime |
95 | 292 |
" |
4379 | 293 |
|
294 |
"Modified: / 13.7.1999 / 12:32:08 / stefan" |
|
62 | 295 |
! |
296 |
||
699 | 297 |
asSeconds |
298 |
"return the number of seconds elapsed since midnight" |
|
1 | 299 |
|
699 | 300 |
^ timeEncoding |
95 | 301 |
|
302 |
" |
|
699 | 303 |
Time now asSeconds |
95 | 304 |
" |
305 |
! |
|
306 |
||
699 | 307 |
asTime |
308 |
"return a Time object from the receiver - thats the receiver." |
|
309 |
||
310 |
^ self |
|
311 |
! ! |
|
312 |
||
313 |
!Time methodsFor:'printing & storing'! |
|
314 |
||
95 | 315 |
print12HourFormatOn:aStream |
316 |
"append a printed representation of the receiver to aStream. |
|
241 | 317 |
Format is hh:mm:ss am/pm (i.e. 12-hour american format)." |
95 | 318 |
|
409 | 319 |
|h m s ampm| |
95 | 320 |
|
241 | 321 |
h := self hours. |
3477 | 322 |
|
323 |
"/ 0 -> 12 am |
|
324 |
"/ 12 -> 12 pm |
|
325 |
||
3478 | 326 |
h // 12 == 0 ifTrue:[ |
327 |
ampm := ' am'. |
|
241 | 328 |
] ifFalse:[ |
3478 | 329 |
ampm := ' pm'. |
241 | 330 |
]. |
3478 | 331 |
|
332 |
h == 0 ifFalse:[ |
|
333 |
h := h - 1 \\ 12 + 1. |
|
334 |
]. |
|
335 |
||
241 | 336 |
h printOn:aStream. |
337 |
aStream nextPut:$:. |
|
338 |
m := self minutes. |
|
339 |
(m < 10) ifTrue:[aStream nextPut:$0]. |
|
340 |
m printOn:aStream. |
|
341 |
aStream nextPut:$:. |
|
342 |
s := self seconds. |
|
343 |
(s < 10) ifTrue:[aStream nextPut:$0]. |
|
409 | 344 |
s printOn:aStream. |
345 |
aStream nextPutAll:ampm |
|
95 | 346 |
|
347 |
" |
|
216 | 348 |
Time now print12HourFormatOn:Transcript. Transcript cr |
3477 | 349 |
(Time now subtractHours:12) print12HourFormatOn:Transcript. Transcript cr |
350 |
(Time hour:24 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr |
|
351 |
(Time hour:12 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr |
|
352 |
(Time hour:0 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr |
|
3478 | 353 |
0 to:24 do:[:h | |
354 |
(Time hour:h minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr |
|
355 |
] |
|
95 | 356 |
" |
699 | 357 |
! |
241 | 358 |
|
699 | 359 |
print24HourFormatOn:aStream |
360 |
"append a printed representation of the receiver to aStream. |
|
361 |
Format is hh:mm:ss (i.e. 24-hour european format)." |
|
362 |
||
363 |
|h m s| |
|
241 | 364 |
|
699 | 365 |
h := self hours. |
366 |
(h < 10) ifTrue:[aStream nextPut:$0]. |
|
367 |
h printOn:aStream. |
|
368 |
aStream nextPut:$:. |
|
369 |
m := self minutes. |
|
370 |
(m < 10) ifTrue:[aStream nextPut:$0]. |
|
371 |
m printOn:aStream. |
|
372 |
aStream nextPut:$:. |
|
373 |
s := self seconds. |
|
374 |
(s < 10) ifTrue:[aStream nextPut:$0]. |
|
375 |
s printOn:aStream |
|
241 | 376 |
|
377 |
" |
|
699 | 378 |
Time now print24HourFormatOn:Transcript. Transcript cr |
241 | 379 |
" |
275 | 380 |
! |
381 |
||
699 | 382 |
printOn:aStream |
383 |
"append a printed representation of the receiver to aStream. |
|
384 |
Format is hh:mm:ss either in 12-hour or 24-hour format. |
|
385 |
depending on the setting of LanguageTerritory. |
|
386 |
I dont know what ST-80 does here (12-hour format ?)" |
|
241 | 387 |
|
993
feaa62827c41
check for territory being #us (instead of #usa) when printing
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
388 |
LanguageTerritory == #us ifTrue:[ |
feaa62827c41
check for territory being #us (instead of #usa) when printing
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
389 |
self print12HourFormatOn:aStream |
699 | 390 |
] ifFalse:[ |
993
feaa62827c41
check for territory being #us (instead of #usa) when printing
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
391 |
self print24HourFormatOn:aStream |
699 | 392 |
] |
275 | 393 |
|
699 | 394 |
" |
395 |
Time now printOn:Transcript. Transcript cr |
|
396 |
" |
|
993
feaa62827c41
check for territory being #us (instead of #usa) when printing
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
397 |
|
feaa62827c41
check for territory being #us (instead of #usa) when printing
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
398 |
"Modified: 22.2.1996 / 16:58:30 / cg" |
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
399 |
! |
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
400 |
|
3709 | 401 |
printString12HourFormat |
402 |
"return a printed representation in 12 hour format" |
|
403 |
||
404 |
|s| |
|
405 |
||
406 |
s := WriteStream on:(String new:11). |
|
407 |
self print12HourFormatOn:s. |
|
408 |
^ s contents |
|
409 |
! |
|
410 |
||
411 |
printString24HourFormat |
|
412 |
"return a printed representation in 24 hour format" |
|
413 |
||
414 |
|s| |
|
415 |
||
416 |
s := WriteStream on:(String new:8). |
|
417 |
self print24HourFormatOn:s. |
|
418 |
^ s contents |
|
419 |
! |
|
420 |
||
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
421 |
shortPrintString |
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
422 |
"dummy - for now" |
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
423 |
|
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
424 |
^ self printString |
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
425 |
|
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
426 |
"Created: 20.6.1997 / 17:17:01 / cg" |
241 | 427 |
! ! |
428 |
||
429 |
!Time methodsFor:'private'! |
|
430 |
||
1502 | 431 |
fromOSTime:osTime |
432 |
"set my time, given an osTime" |
|
275 | 433 |
|
434 |
|h m s| |
|
1502 | 435 |
|
436 |
OperatingSystem computeTimePartsOf:osTime for:[ |
|
437 |
:hours :minutes :secs :millis | |
|
275 | 438 |
|
1502 | 439 |
h := hours. |
440 |
m := minutes. |
|
441 |
s := secs. |
|
275 | 442 |
]. |
4031 | 443 |
self setHours:h minutes:m seconds:s |
275 | 444 |
|
1502 | 445 |
"Modified: 1.7.1996 / 15:21:06 / cg" |
275 | 446 |
! |
447 |
||
3477 | 448 |
getMilliseconds |
449 |
^ self getSeconds * 1000 |
|
450 |
! |
|
451 |
||
275 | 452 |
getSeconds |
453 |
^ timeEncoding |
|
454 |
! |
|
455 |
||
4031 | 456 |
setHours:h minutes:m seconds:s |
699 | 457 |
"set my time given individual values" |
458 |
||
3477 | 459 |
self setSeconds:(((h\\24) * 60 * 60 ) + (m * 60) + s). |
460 |
! |
|
461 |
||
462 |
setMilliseconds:millis |
|
463 |
"set my time given milliseconds since midnight" |
|
464 |
||
465 |
self setSeconds:(millis // 1000) |
|
699 | 466 |
! |
467 |
||
275 | 468 |
setSeconds:secs |
469 |
"set my time given seconds since midnight" |
|
470 |
||
3477 | 471 |
secs < 0 ifTrue:[ |
472 |
timeEncoding := (24 * 3600) - (secs negated \\ (24 * 3600)) |
|
473 |
] ifFalse:[ |
|
474 |
timeEncoding := secs |
|
475 |
] |
|
275 | 476 |
! |
477 |
||
699 | 478 |
timeEncoding |
479 |
"the internal encoding is stricktly private, |
|
480 |
and should not be used outside." |
|
275 | 481 |
|
699 | 482 |
^ timeEncoding |
275 | 483 |
! |
484 |
||
241 | 485 |
timeEncoding:encoding |
486 |
"the internal encoding is stricktly private, |
|
487 |
and should not be used outside." |
|
488 |
||
489 |
timeEncoding := encoding |
|
699 | 490 |
! ! |
491 |
||
2706
878723bc99fc
added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
1701
diff
changeset
|
492 |
!Time class methodsFor:'documentation'! |
241 | 493 |
|
699 | 494 |
version |
4379 | 495 |
^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.38 1999-07-13 10:49:22 stefan Exp $' |
241 | 496 |
! ! |