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