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