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