author | Claus Gittinger <cg@exept.de> |
Thu, 13 Oct 2016 00:39:10 +0200 | |
changeset 20614 | 0a5744a1f46c |
parent 19922 | e0d6d301a4dc |
child 20727 | fb8c5591428b |
child 20818 | efa2de8569f6 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
6165 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
6165 | 12 |
"{ Package: 'stx:libbasic' }" |
5390 | 13 |
|
17641 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
6165 | 16 |
AbstractTime subclass:#Time |
17 |
instanceVariableNames:'timeEncoding' |
|
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
7672 | 20 |
category:'Magnitude-Time' |
1 | 21 |
! |
22 |
||
6165 | 23 |
!Time class methodsFor:'documentation'! |
88 | 24 |
|
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
6165 | 28 |
All Rights Reserved |
88 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
41 |
Instances of time represent a particular time-of-day. |
|
409 | 42 |
Since they only store hours, minutes and seconds within a day, |
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
43 |
they cannot be used to compare times across midnight |
409 | 44 |
(i.e. they should not be used as timeStamps). |
1228 | 45 |
|
8249
bdcae1232e6d
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8231
diff
changeset
|
46 |
Use instances of Timestamp (and read the comment there) to do this. |
241 | 47 |
|
13235 | 48 |
Time now returns the time in the local timezone. |
49 |
Use Time utcNow to get the time in the UTC zone. |
|
50 |
||
16940 | 51 |
Note: time was changed recently to keep the number of milliseconds since midnight. |
17641 | 52 |
However, all existing instance creators so far only create time instances with 0-millis. |
53 |
I.e. Time now still returns a time with second precision. |
|
16940 | 54 |
|
17641 | 55 |
It is not done currently, to remain backward compatible, as users may get confused |
56 |
to see t1 > t2 although they print the same (as long as the printed representation does not |
|
57 |
include the milli seconds). |
|
58 |
On the other side: a change of the default printformat is not done now, |
|
59 |
as it may affect many existing applications. |
|
16937 | 60 |
|
17641 | 61 |
Any application which needs the millisecond precision time should call the new |
62 |
Time nowWithMilliseconds. |
|
16940 | 63 |
|
241 | 64 |
Examples: |
17641 | 65 |
|t| |
241 | 66 |
|
17641 | 67 |
t := Time now. |
68 |
Transcript showCR:t. |
|
241 | 69 |
|
70 |
||
17641 | 71 |
|t1 t2| |
241 | 72 |
|
17641 | 73 |
t1 := Time now. |
74 |
(Delay forSeconds:10) wait. |
|
75 |
t2 := Time now. |
|
76 |
t2 - t1 |
|
1295 | 77 |
|
78 |
[author:] |
|
17641 | 79 |
Claus Gittinger |
1295 | 80 |
|
81 |
[see also:] |
|
17641 | 82 |
Date Timestamp AbstractTime OperatingSystem |
83 |
Filename |
|
88 | 84 |
" |
85 |
! ! |
|
1 | 86 |
|
6165 | 87 |
!Time class methodsFor:'instance creation'! |
88 |
||
13603
d9baa85cd3ba
comment/format in: #fromString:
Claus Gittinger <cg@exept.de>
parents:
13235
diff
changeset
|
89 |
fromString: aString |
d9baa85cd3ba
comment/format in: #fromString:
Claus Gittinger <cg@exept.de>
parents:
13235
diff
changeset
|
90 |
^ self readFrom: (ReadStream on: aString). |
d9baa85cd3ba
comment/format in: #fromString:
Claus Gittinger <cg@exept.de>
parents:
13235
diff
changeset
|
91 |
|
d9baa85cd3ba
comment/format in: #fromString:
Claus Gittinger <cg@exept.de>
parents:
13235
diff
changeset
|
92 |
"Modified (format): / 20-08-2011 / 16:46:39 / cg" |
d9baa85cd3ba
comment/format in: #fromString:
Claus Gittinger <cg@exept.de>
parents:
13235
diff
changeset
|
93 |
! |
d9baa85cd3ba
comment/format in: #fromString:
Claus Gittinger <cg@exept.de>
parents:
13235
diff
changeset
|
94 |
|
8749 | 95 |
hour:h minute:m |
96 |
"compatibility" |
|
97 |
||
98 |
^ self hours:h minutes:m seconds:0 |
|
99 |
||
100 |
" |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
101 |
Time hour:2 minute:33 |
8749 | 102 |
" |
103 |
! |
|
104 |
||
7818 | 105 |
hour:h minute:m second:s |
106 |
"compatibility" |
|
107 |
||
108 |
^ self hours:h minutes:m seconds:s |
|
109 |
||
110 |
" |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
111 |
Time hour:2 minute:33 second:0 |
7818 | 112 |
" |
113 |
! |
|
114 |
||
6165 | 115 |
hour:h minutes:m seconds:s |
116 |
"return an instance of Time representing the given time. |
|
8249
bdcae1232e6d
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8231
diff
changeset
|
117 |
See also Time now / Date today / Timestamp now. |
6165 | 118 |
Obsolete: please use #hours:minutes:seconds:" |
119 |
||
120 |
<resource:#obsolete> |
|
121 |
||
9061 | 122 |
self obsoleteMethodWarning:'use #hours:minutes:seconds:'. |
6165 | 123 |
|
124 |
^ self hours:h minutes:m seconds:s |
|
125 |
||
126 |
" |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
127 |
Time hours:2 minutes:33 seconds:0 |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
128 |
Time hours:0 minutes:0 seconds:0 |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
129 |
Time hours:24 minutes:0 seconds:0 |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
130 |
Time hours23 minutes:59 seconds:59 |
6165 | 131 |
" |
132 |
||
133 |
"Modified: 19.4.1996 / 15:32:40 / cg" |
|
134 |
! |
|
135 |
||
136 |
hours:h minutes:m seconds:s |
|
4031 | 137 |
"return an instance of Time representing the given time. |
8249
bdcae1232e6d
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8231
diff
changeset
|
138 |
See also Time now / Date today / Timestamp now." |
4031 | 139 |
|
6165 | 140 |
^ self basicNew setHours:h minutes:m seconds:s |
4031 | 141 |
|
142 |
" |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
143 |
Time hours:2 minutes:33 seconds:0 |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
144 |
Time hours:0 minutes:0 seconds:0 |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
145 |
Time hours:24 minutes:0 seconds:0 |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
146 |
Time hours:23 minutes:59 seconds:59 |
95 | 147 |
" |
6165 | 148 |
|
149 |
"Modified: 19.4.1996 / 15:32:40 / cg" |
|
150 |
! |
|
151 |
||
16937 | 152 |
hours:h minutes:m seconds:s milliseconds:ms |
153 |
"return an instance of Time representing the given time. |
|
154 |
See also Time now / Date today / Timestamp now." |
|
155 |
||
156 |
^ self basicNew setHours:h minutes:m seconds:s milliseconds:ms |
|
157 |
||
158 |
" |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
159 |
Time hours:2 minutes:33 seconds:0 |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
160 |
Time hours:0 minutes:0 seconds:0 |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
161 |
Time hours:24 minutes:0 seconds:0 |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
162 |
Time hours:23 minutes:59 seconds:59 |
16937 | 163 |
" |
164 |
||
165 |
"Modified: 19.4.1996 / 15:32:40 / cg" |
|
166 |
! |
|
167 |
||
7293 | 168 |
midnight |
169 |
"Answer a new instance at midnight." |
|
170 |
||
13235 | 171 |
^ self fromSeconds: 0 |
7293 | 172 |
|
173 |
" |
|
174 |
Time midnight |
|
175 |
" |
|
176 |
! |
|
177 |
||
178 |
noon |
|
179 |
"Answer a new instance at noon." |
|
180 |
||
13235 | 181 |
^ self fromSeconds: 43200 "12*60*60" |
7293 | 182 |
|
183 |
" |
|
184 |
Time noon |
|
185 |
" |
|
186 |
! |
|
187 |
||
18456 | 188 |
readFrom:aStringOrStream format:formatString language:languageOrNil onError:exceptionalValue |
189 |
"return a new Time, reading a printed representation from aStream using a formatString. |
|
190 |
The formatString is similar to the one used when printing. |
|
191 |
On error, exceptionalValue is returned. |
|
192 |
If exceptionalValue is a one-arg block, an error message is passed as argument. |
|
193 |
Format: |
|
194 |
%h hours, 00..23 (i.e. european) 0-padded to length 2 |
|
195 |
%u hours, 00..12 (i.e. us) 0-padded to length 2 |
|
196 |
%m minutes, 00..59 0-padded to length 2 |
|
197 |
%s seconds, 00..59 0-padded to length 2 |
|
198 |
%i milliseconds, 000..999 0-padded to length 3 |
|
19922 | 199 |
%f fractional seconds any length, but only milliseconds are read |
18456 | 200 |
%a am/pm |
201 |
||
202 |
an optional length after the % gives a field length; |
|
203 |
i.e. %2h%2m%2s parses '123557' as 12:35:37 |
|
204 |
||
205 |
Please consider using a standard format, such as iso8601. |
|
206 |
" |
|
207 |
||
208 |
|hour minute second millisecond |
|
209 |
utcOffset inStream formatStream error fChar format itemHandler |
|
19922 | 210 |
len s fraction fractionString| |
18456 | 211 |
|
212 |
error := [:msg | |
|
213 |
exceptionalValue isBlock ifTrue:[ |
|
214 |
^ exceptionalValue valueWithOptionalArgument:'format error' |
|
215 |
] ifFalse:[ |
|
216 |
^ exceptionalValue value |
|
217 |
]. |
|
218 |
]. |
|
219 |
||
220 |
itemHandler := [:format | |
|
221 |
|input| |
|
222 |
||
223 |
input := len isNil ifTrue:[ inStream ] ifFalse:[ inStream next: len ]. |
|
224 |
||
225 |
( format = 'h' or:[ format = 'H' ]) ifTrue:[ |
|
226 |
hour := Integer readFrom:input onError:[ error value:'invalid hour' ]. |
|
227 |
||
228 |
] ifFalse:[ ( format = 'u' or:[ format = 'U']) ifTrue:[ |
|
229 |
hour := Integer readFrom:input onError:[ error value:'invalid hour' ]. |
|
230 |
||
231 |
] ifFalse:[ ( format = 'm' or:[ format = 'M' ]) ifTrue:[ |
|
232 |
minute := Integer readFrom:input onError:[ error value:'invalid minute' ]. |
|
233 |
||
234 |
] ifFalse:[ ( format = 's' or:[ format = 'S' ]) ifTrue:[ |
|
235 |
second := Integer readFrom:input onError:[ error value:'invalid second' ]. |
|
236 |
||
237 |
] ifFalse:[ ( format = 'i' or:[ format = 'I' ]) ifTrue:[ |
|
238 |
millisecond := Integer readFrom:input onError:[ error value:'invalid millsecond' ]. |
|
239 |
||
19922 | 240 |
] ifFalse:[ ( format = 'f' or:[ format = 'F' ]) ifTrue:[ |
241 |
fractionString := input upToMatching:[:ch | ch isDigit not]. |
|
242 |
fraction := FixedPoint readFrom:'0.',fractionString. |
|
243 |
millisecond := (fraction * 1000) truncated. |
|
18456 | 244 |
] ifFalse:[ ( format = 'tz' ) ifTrue:[ |
245 |
utcOffset := Timestamp utcOffsetFrom:input. |
|
246 |
utcOffset isNil ifTrue:[ error value:'invalid timezone' ] |
|
247 |
] ifFalse:[ ( format = 'a' ) ifTrue:[ |
|
248 |
s := (input next:2) asLowercase. |
|
249 |
s = 'am' ifTrue:[ |
|
250 |
(hour between:0 and:12) ifFalse:[ error value:'invalid hour' ] |
|
251 |
] ifFalse:[ |
|
252 |
s = 'pm' ifTrue:[ |
|
253 |
(hour between:1 and:12) ifFalse:[ error value:'invalid hour' ]. |
|
254 |
hour := hour + 12. |
|
255 |
] ifFalse:[ |
|
256 |
error value:'invalid am/pm' |
|
257 |
] |
|
258 |
] |
|
259 |
||
260 |
] ifFalse:[ |
|
261 |
error value:'unhandled format:',format |
|
19922 | 262 |
]]]]]]]] |
18456 | 263 |
]. |
264 |
||
265 |
hour := 0. |
|
266 |
minute := 0. |
|
267 |
second := 0. |
|
268 |
millisecond := 0. |
|
269 |
utcOffset := 0. |
|
270 |
||
271 |
inStream := aStringOrStream readStream. |
|
272 |
formatStream := formatString readStream. |
|
273 |
||
274 |
[formatStream atEnd] whileFalse:[ |
|
275 |
fChar := formatStream next. |
|
276 |
fChar = Character space ifTrue:[ |
|
277 |
inStream peek isSeparator ifFalse:[ error value: 'format error; space expcected' ]. |
|
278 |
inStream skipSeparators. |
|
279 |
] ifFalse:[ |
|
280 |
fChar == $% ifTrue:[ |
|
281 |
len := nil. |
|
282 |
(formatStream peek isDigit) ifTrue:[ |
|
283 |
len := Integer readFrom:formatStream onError:[ error value: 'format error; invalid length' ] |
|
284 |
]. |
|
285 |
(formatStream peek == $() ifTrue:[ |
|
286 |
formatStream next. |
|
287 |
format := formatStream upTo:$). |
|
288 |
] ifFalse:[ |
|
289 |
(formatStream peek == ${) ifTrue:[ |
|
290 |
formatStream next. |
|
291 |
format := formatStream upTo:$}. |
|
292 |
] ifFalse:[ |
|
293 |
(formatStream peek isLetter) ifTrue:[ |
|
294 |
format := formatStream nextAlphaNumericWord. |
|
295 |
] ifFalse:[ |
|
296 |
error value:'unhandled format:',formatStream peek |
|
297 |
] |
|
298 |
] |
|
299 |
]. |
|
300 |
itemHandler value:format. |
|
301 |
] ifFalse:[ |
|
302 |
inStream peek = fChar ifFalse:[^ error value: 'format error; ',fChar,' expcected']. |
|
303 |
inStream next. |
|
304 |
] |
|
305 |
]. |
|
306 |
]. |
|
307 |
||
308 |
^ (self |
|
309 |
hours:(hour ? 0) minutes:(minute ? 0) seconds:(second ? 0) milliseconds:millisecond) |
|
310 |
+ utcOffset |
|
311 |
||
312 |
" |
|
313 |
Time readFrom:'13:11:06' format:'%h:%m:%s' language:nil onError:[self halt] |
|
314 |
Time readFrom:'131106' format:'%2h%2m%2s' language:nil onError:[self halt] |
|
315 |
Time readFrom:'7:30pm EST' format:'%u:%m%a %tz' language:#en onError:[self halt] |
|
316 |
Time readFrom:'7:30pm UTC' format:'%u:%m%a %tz' language:#en onError:[self halt] |
|
19922 | 317 |
|
318 |
Time readFrom:'13:11:06.111' format:'%h:%m:%s.%i' language:nil onError:[self halt] |
|
319 |
Time readFrom:'13:11:06.1' format:'%h:%m:%s.%f' language:nil onError:[self halt] |
|
320 |
Time readFrom:'13:11:06.01' format:'%h:%m:%s.%f' language:nil onError:[self halt] |
|
321 |
Time readFrom:'13:11:06.001' format:'%h:%m:%s.%f' language:nil onError:[self halt] |
|
322 |
Time readFrom:'13:11:06.1234567' format:'%h:%m:%s.%f' language:nil onError:[self halt] |
|
18456 | 323 |
" |
324 |
! |
|
325 |
||
6165 | 326 |
readFrom:aStringOrStream onError:exceptionBlock |
327 |
"return a new Time, reading a printed representation from aStream. |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
328 |
If no am/pm follows the time, the string is interpreted as |
6165 | 329 |
either 24 hour format or being am." |
330 |
||
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6467
diff
changeset
|
331 |
^ [ |
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
332 |
|str hour min sec peekC millis| |
6165 | 333 |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
334 |
str := aStringOrStream readStream. |
6165 | 335 |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
336 |
hour := Integer readFrom:str. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
337 |
(hour between:0 and:24) ifFalse:[^ exceptionBlock value]. |
6165 | 338 |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
339 |
min := 0. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
340 |
sec := 0. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
341 |
millis := 0. |
16940 | 342 |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
343 |
str atEnd ifFalse:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
344 |
peekC := str peek. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
345 |
(peekC == $:) ifTrue:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
346 |
str next. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
347 |
min := Integer readFrom:str. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
348 |
(min between:0 and:59) ifFalse:[^ exceptionBlock value]. |
6165 | 349 |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
350 |
(str peek == $:) ifTrue:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
351 |
str next. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
352 |
sec := Integer readFrom:str. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
353 |
(sec between:0 and:59) ifFalse:[^ exceptionBlock value]. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
354 |
(str peek == $.) ifTrue:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
355 |
str next. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
356 |
millis := ((Fraction readDecimalFractionFrom:str onError:[^ exceptionBlock value]) * 1000) asInteger. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
357 |
]. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
358 |
]. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
359 |
peekC := str peek. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
360 |
]. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
361 |
[peekC == Character space] whileTrue:[str next. peekC := str peek]. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
362 |
(peekC == $p or:[peekC == $P]) ifTrue:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
363 |
str next. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
364 |
(str peek == $m or:[str peek == $M]) ifTrue:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
365 |
str next |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
366 |
]. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
367 |
(hour <= 0 or:[hour > 12]) ifTrue:[^ exceptionBlock value]. |
6165 | 368 |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
369 |
"pm" |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
370 |
hour ~~ 12 ifTrue:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
371 |
hour := hour + 12 |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
372 |
]. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
373 |
peekC := str peek |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
374 |
] ifFalse:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
375 |
(peekC == $a or:[peekC == $A]) ifTrue:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
376 |
str next. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
377 |
(str peek == $m or:[str peek == $M]) ifTrue:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
378 |
str next |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
379 |
]. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
380 |
hour == 12 ifTrue:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
381 |
hour := 0. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
382 |
]. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
383 |
hour > 12 ifTrue:[^ exceptionBlock value]. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
384 |
peekC := str peek |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
385 |
] ifFalse:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
386 |
"/ cg: dont be too picky here - we do not care, what comes after the |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
387 |
"/ time string. (Needed to be able to read rfc822 strings where a timezone |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
388 |
"/ follows (-/+0700 GMT, for example) |
11809
efca8cccc66b
time reading: do not insist on peek-char to be a separator after the
Claus Gittinger <cg@exept.de>
parents:
11308
diff
changeset
|
389 |
"/ peekC notNil ifTrue:[ |
efca8cccc66b
time reading: do not insist on peek-char to be a separator after the
Claus Gittinger <cg@exept.de>
parents:
11308
diff
changeset
|
390 |
"/ peekC isSeparator ifFalse:[^ exceptionBlock value]. |
efca8cccc66b
time reading: do not insist on peek-char to be a separator after the
Claus Gittinger <cg@exept.de>
parents:
11308
diff
changeset
|
391 |
"/ ] |
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
392 |
]. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
393 |
] |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
394 |
]. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
395 |
self basicNew setHours:hour minutes:min seconds:sec milliseconds:millis |
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6467
diff
changeset
|
396 |
] on:Error do:exceptionBlock. |
6165 | 397 |
|
398 |
" |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
399 |
Time readFrom:'0:00' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
400 |
Time readFrom:'2:00' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
401 |
Time readFrom:'12:00' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
402 |
Time readFrom:'14:00' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
403 |
Time readFrom:'23:00' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
404 |
Time readFrom:'24:00' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
405 |
Time readFrom:'2:30 am' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
406 |
Time readFrom:'2:30 pm' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
407 |
Time readFrom:'14' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
408 |
Time readFrom:'2 am' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
409 |
Time readFrom:'2 pm' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
410 |
Time readFrom:'12:05 pm' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
411 |
Time readFrom:'12:06 am' |
6165 | 412 |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
413 |
Time readFrom:'18:22:00' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
414 |
Time readFrom:'14:00:11' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
415 |
Time readFrom:'7:00:11' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
416 |
Time readFrom:'24:00:00' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
417 |
Time readFrom:'0:00:00' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
418 |
Time readFrom:'12:00:00' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
419 |
Time readFrom:'0:00:00' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
420 |
Time readFrom:'6:22:00 pm' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
421 |
Time readFrom:'2:00:11 pm' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
422 |
Time readFrom:'7:00:11 am' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
423 |
Time readFrom:'12:00:00 am' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
424 |
Time readFrom:'0:00:00 am' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
425 |
Time readFrom:'24:00:00 am' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
426 |
Time readFrom:'12:00:00 pm' |
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6467
diff
changeset
|
427 |
Time readFrom:'0:00:00 pm' onError:'invalid' |
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
428 |
Time readFrom:'24:00:00 pm' |
16940 | 429 |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
430 |
Time readFrom:'13:00:00.5' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
431 |
Time readFrom:'13:00:00.123' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
432 |
Time readFrom:'1:00:00.123 pm' |
6165 | 433 |
" |
434 |
||
435 |
"Modified: 8.10.1996 / 19:32:11 / cg" |
|
13235 | 436 |
! |
437 |
||
438 |
utcNow |
|
17136 | 439 |
"return an instance of myself representing this moment in UTC. |
440 |
That is, the current time in London without any daylight saving adjustments." |
|
13235 | 441 |
|
442 |
^ self basicNew fromUtcOSTime:(OperatingSystem getOSTime) |
|
443 |
||
444 |
" |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
445 |
Timestamp now |
13235 | 446 |
Timestamp utcNow |
447 |
||
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
448 |
Time now |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
449 |
Time utcNow |
13235 | 450 |
" |
451 |
||
452 |
"Modified: 1.7.1996 / 15:20:10 / cg" |
|
1 | 453 |
! ! |
454 |
||
6165 | 455 |
!Time class methodsFor:'format strings'! |
4411
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
456 |
|
13213
d37c29bad3da
added: #defaultFormatString
Claus Gittinger <cg@exept.de>
parents:
12829
diff
changeset
|
457 |
defaultFormatString |
16985 | 458 |
"a language specific format string to present times in user interfaces. |
459 |
Do not use this to store/retrieve times (use ISO8601 for that)" |
|
460 |
||
20614 | 461 |
Smalltalk languageTerritory == #us ifTrue:[ |
462 |
^ self formatString12us |
|
13213
d37c29bad3da
added: #defaultFormatString
Claus Gittinger <cg@exept.de>
parents:
12829
diff
changeset
|
463 |
] ifFalse:[ |
20614 | 464 |
^ self formatString24 |
13213
d37c29bad3da
added: #defaultFormatString
Claus Gittinger <cg@exept.de>
parents:
12829
diff
changeset
|
465 |
] |
d37c29bad3da
added: #defaultFormatString
Claus Gittinger <cg@exept.de>
parents:
12829
diff
changeset
|
466 |
|
d37c29bad3da
added: #defaultFormatString
Claus Gittinger <cg@exept.de>
parents:
12829
diff
changeset
|
467 |
"Created: / 16-01-2011 / 11:23:36 / cg" |
d37c29bad3da
added: #defaultFormatString
Claus Gittinger <cg@exept.de>
parents:
12829
diff
changeset
|
468 |
! |
d37c29bad3da
added: #defaultFormatString
Claus Gittinger <cg@exept.de>
parents:
12829
diff
changeset
|
469 |
|
16940 | 470 |
defaultFormatStringWithMilliseconds |
20614 | 471 |
Smalltalk languageTerritory == #us ifTrue:[ |
472 |
^ self formatStringWithMilliseconds12us |
|
16940 | 473 |
] ifFalse:[ |
20614 | 474 |
^ self formatStringWithMilliseconds24 |
16940 | 475 |
] |
476 |
! |
|
477 |
||
4411
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
478 |
formatString12us |
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
479 |
"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
|
480 |
|
8231 | 481 |
^ '%u:%m:%s %A' |
4411
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
482 |
! |
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
483 |
|
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
484 |
formatString24 |
8231 | 485 |
"return the format string used to format non US times" |
4411
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
486 |
|
6164 | 487 |
^ '%h:%m:%s' |
16940 | 488 |
! |
489 |
||
490 |
formatStringWithMilliseconds12us |
|
491 |
"return the format string used to format US times (and other areas)" |
|
492 |
||
16949 | 493 |
^ '%u:%m:%s.%i %A' |
16940 | 494 |
! |
495 |
||
496 |
formatStringWithMilliseconds24 |
|
497 |
"return the format string used to format non US times" |
|
498 |
||
499 |
^ '%h:%m:%s.%i' |
|
6164 | 500 |
! ! |
501 |
||
16981 | 502 |
!Time methodsFor:'Compatibility-Backward'! |
503 |
||
504 |
asMilliSeconds |
|
505 |
<resource: #obsolete> |
|
506 |
"return the number of milliseconds elapsed since midnight" |
|
507 |
||
508 |
^ self asMilliseconds |
|
6164 | 509 |
|
16981 | 510 |
" |
511 |
Time now asMilliSeconds |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
512 |
(TimeDuration days:1) asMilliSeconds |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
513 |
(TimeDuration hours:1) asMilliSeconds |
16981 | 514 |
" |
13632 | 515 |
|
16981 | 516 |
"Created: / 05-09-2011 / 10:40:15 / cg" |
517 |
! ! |
|
518 |
||
519 |
!Time methodsFor:'Compatibility-Squeak'! |
|
13632 | 520 |
|
6164 | 521 |
intervalString |
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
522 |
"Treat the time as a difference. |
6164 | 523 |
Give it in hours and minutes with two digits of accuracy." |
524 |
||
6467 | 525 |
|hours minutes seconds hh mm ss s| |
6164 | 526 |
|
527 |
hours := self hours. |
|
528 |
minutes := self minutes. |
|
529 |
seconds := self seconds. |
|
6467 | 530 |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
531 |
hours = 0 |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
532 |
ifTrue: [hh := ''] |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
533 |
ifFalse: [ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
534 |
hh := hours printString, ' hour'. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
535 |
hours > 1 ifTrue:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
536 |
hh := hh , 's' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
537 |
] |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
538 |
]. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
539 |
minutes = 0 |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
540 |
ifTrue: [mm := ''] |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
541 |
ifFalse: [ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
542 |
mm := minutes printString, ' minute'. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
543 |
minutes > 1 ifTrue:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
544 |
mm := mm , 's' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
545 |
] |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
546 |
]. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
547 |
seconds = 0 |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
548 |
ifTrue: [ss := ''] |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
549 |
ifFalse: [ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
550 |
ss := seconds printString, ' second'. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
551 |
seconds > 1 ifTrue:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
552 |
ss := ss , 's' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
553 |
] |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
554 |
]. |
6467 | 555 |
|
556 |
"/ do not show seconds, if hours are there |
|
6164 | 557 |
hh size > 0 ifTrue: [ss := '']. |
6467 | 558 |
|
559 |
s := hh. |
|
6873 | 560 |
mm notEmpty ifTrue:[ |
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
561 |
s notEmpty ifTrue:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
562 |
s := s , ' ' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
563 |
]. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
564 |
s := s , mm. |
6467 | 565 |
]. |
6873 | 566 |
ss notEmpty ifTrue:[ |
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
567 |
s notEmpty ifTrue:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
568 |
s := s , ' ' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
569 |
]. |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
570 |
s := s , ss |
6467 | 571 |
]. |
6873 | 572 |
^ s |
6164 | 573 |
|
574 |
" |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
575 |
(Time fromSeconds:3600) intervalString |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
576 |
(Time fromSeconds:3605) intervalString |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
577 |
(Time fromSeconds:3700) intervalString |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
578 |
(Time fromSeconds:5) intervalString |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
579 |
(Time fromSeconds:65) intervalString |
6164 | 580 |
" |
581 |
! |
|
582 |
||
7024 | 583 |
print24:prnt24FormatBoolean on:aStream |
584 |
"print me either US or 24hr format on a stream" |
|
585 |
||
586 |
^ self print24:prnt24FormatBoolean showSeconds:true on:aStream |
|
587 |
||
588 |
" |
|
589 |
Time now print24:true on:Transcript. Transcript cr. |
|
590 |
Time now print24:false on:Transcript. Transcript cr. |
|
591 |
" |
|
592 |
! |
|
593 |
||
6164 | 594 |
print24:prnt24Format showSeconds:doSeconds on:aStream |
595 |
"print me either US or 24hr format, optionally with |
|
596 |
seconds on a stream" |
|
597 |
||
598 |
|format| |
|
599 |
||
600 |
prnt24Format ifTrue:[ |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
601 |
doSeconds ifTrue:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
602 |
format := '%h:%m:%s' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
603 |
] ifFalse:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
604 |
format := '%h:%m' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
605 |
]. |
6164 | 606 |
] ifFalse:[ |
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
607 |
"/ US format |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
608 |
doSeconds ifTrue:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
609 |
format := '%u:%m:%s %a' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
610 |
] ifFalse:[ |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
611 |
format := '%u:%m %a' |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
612 |
]. |
6164 | 613 |
]. |
614 |
^ self |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
615 |
printOn:aStream |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
616 |
format:format. |
6164 | 617 |
|
618 |
" |
|
619 |
Time now print24:true showSeconds:true on:Transcript. Transcript cr. |
|
620 |
Time now print24:false showSeconds:true on:Transcript. Transcript cr. |
|
621 |
Time now print24:true showSeconds:false on:Transcript. Transcript cr. |
|
622 |
Time now print24:false showSeconds:false on:Transcript. Transcript cr. |
|
623 |
" |
|
4411
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
624 |
! ! |
684a2b944463
much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
625 |
|
6164 | 626 |
!Time methodsFor:'accessing'! |
627 |
||
628 |
hours |
|
629 |
"return the number of hours since midnight (i.e. 0..23)" |
|
630 |
||
631 |
^ self getSeconds // 3600 |
|
632 |
||
633 |
" |
|
634 |
Time now hours |
|
635 |
" |
|
636 |
! |
|
275 | 637 |
|
4845 | 638 |
milliseconds |
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
639 |
"get the milliseconds part |
16981 | 640 |
(notice: that is NOT the total number of millis (since midnight), |
19848 | 641 |
but the fractional part only. Use this only for printing. |
642 |
asMilliseconds or getMilliseconds is probably what you want" |
|
6164 | 643 |
|
16940 | 644 |
^ timeEncoding \\ 1000 |
6164 | 645 |
! |
646 |
||
647 |
minutes |
|
19848 | 648 |
"return the number of minutes within the hour (i.e. 0..59). |
649 |
(notice: that is NOT the total number of minutes (since midnight), |
|
650 |
but the fractional part only. Use this only for printing." |
|
6164 | 651 |
|
652 |
^ (self getSeconds \\ 3600) // 60 |
|
653 |
||
654 |
" |
|
655 |
Time now minutes |
|
656 |
" |
|
657 |
! |
|
658 |
||
659 |
seconds |
|
19848 | 660 |
"return the number of seconds within the minute (i.e. 0..59). |
661 |
(notice: that is NOT the total number of seconds (since midnight), |
|
662 |
but the fractional part only. Use this only for printing. |
|
663 |
asSeconds or getSeconds give you the nr of seconds since midnight" |
|
6164 | 664 |
|
7733 | 665 |
^ self getSeconds \\ 60 |
6164 | 666 |
|
667 |
" |
|
668 |
Time now seconds |
|
669 |
" |
|
670 |
! |
|
671 |
||
9441 | 672 |
timeZoneDeltaInMinutes |
673 |
"answer the number of minutes between local time and utc time. |
|
674 |
Delta is positive if local time is ahead of utc, negative if behind utc. |
|
675 |
||
16985 | 676 |
Time is local time, so ask a local timestamp" |
9441 | 677 |
|
678 |
^ Timestamp now timeZoneDeltaInMinutes |
|
679 |
||
680 |
||
681 |
" |
|
682 |
Time now timeZoneDeltaInMinutes |
|
683 |
" |
|
1 | 684 |
! ! |
685 |
||
6164 | 686 |
!Time methodsFor:'comparing'! |
687 |
||
688 |
< aTime |
|
689 |
"return true if the receiver is before the argument" |
|
690 |
||
17141 | 691 |
|milliseconds| |
692 |
||
10744
afd1835c12d2
comparison did only care for seconds, when used with timeDurations
sr
parents:
10666
diff
changeset
|
693 |
aTime class == self class ifTrue:[ |
17141 | 694 |
^ timeEncoding < aTime timeEncoding |
695 |
]. |
|
696 |
aTime isNumber ifTrue:[ |
|
697 |
"backward compatibility for old code, which expects (time1 - time2) to return seconds" |
|
698 |
milliseconds := (aTime * 1000) asInteger. "integer seconds" |
|
699 |
] ifFalse:[ |
|
700 |
milliseconds := aTime getMilliseconds. |
|
10744
afd1835c12d2
comparison did only care for seconds, when used with timeDurations
sr
parents:
10666
diff
changeset
|
701 |
]. |
17141 | 702 |
^ self getMilliseconds < milliseconds |
703 |
||
704 |
" |
|
705 |
(Timestamp now + 10) - Timestamp now < 10 |
|
706 |
(Timestamp now + 10) - Timestamp now < 11 |
|
707 |
" |
|
708 |
! |
|
709 |
||
710 |
<= aTime |
|
711 |
"return true if the receiver is before the argument" |
|
712 |
||
713 |
|milliseconds| |
|
714 |
||
715 |
aTime class == self class ifTrue:[ |
|
716 |
^ timeEncoding <= aTime timeEncoding |
|
717 |
]. |
|
718 |
aTime isNumber ifTrue:[ |
|
719 |
"backward compatibility for old code, which expects (time1 - time2) to return seconds" |
|
720 |
milliseconds := (aTime * 1000) asInteger. "integer seconds" |
|
721 |
] ifFalse:[ |
|
722 |
milliseconds := aTime getMilliseconds. |
|
723 |
]. |
|
724 |
^ self getMilliseconds <= milliseconds |
|
725 |
||
726 |
" |
|
727 |
(Timestamp now + 10) - Timestamp now <= 10 |
|
728 |
(Timestamp now + 10) - Timestamp now <= 11 |
|
729 |
(Timestamp now + 10) - Timestamp now <= 9 |
|
730 |
" |
|
6164 | 731 |
! |
732 |
||
733 |
= aTime |
|
734 |
"return true if the argument, aTime represents the same timeOfDay" |
|
735 |
||
17141 | 736 |
|milliseconds| |
737 |
||
6164 | 738 |
aTime class == self class ifTrue:[ |
17141 | 739 |
^ timeEncoding = aTime timeEncoding |
6164 | 740 |
]. |
17141 | 741 |
aTime isNumber ifTrue:[ |
742 |
"backward compatibility for old code, which expects (time1 - time2) to return seconds" |
|
743 |
milliseconds := (aTime * 1000) asInteger. "integer seconds" |
|
744 |
] ifFalse:[ |
|
745 |
aTime species == self species ifFalse:[^ false]. |
|
746 |
milliseconds := aTime getMilliseconds. |
|
747 |
]. |
|
748 |
^ self getMilliseconds = milliseconds |
|
10666
609bedc85066
changed #'=' (for largeinteger timeEncodings in TimeDuration)
Claus Gittinger <cg@exept.de>
parents:
9441
diff
changeset
|
749 |
|
17141 | 750 |
" |
751 |
(Timestamp now + 10) - Timestamp now = 10 |
|
752 |
(Timestamp now + 10) - Timestamp now = 9 |
|
753 |
" |
|
6164 | 754 |
! |
755 |
||
756 |
> aTime |
|
757 |
"return true if the receiver is before the argument" |
|
758 |
||
17141 | 759 |
|milliseconds| |
760 |
||
10744
afd1835c12d2
comparison did only care for seconds, when used with timeDurations
sr
parents:
10666
diff
changeset
|
761 |
aTime class == self class ifTrue:[ |
17141 | 762 |
^ timeEncoding > aTime timeEncoding |
10744
afd1835c12d2
comparison did only care for seconds, when used with timeDurations
sr
parents:
10666
diff
changeset
|
763 |
]. |
17141 | 764 |
aTime isNumber ifTrue:[ |
765 |
"backward compatibility for old code, which expects (time1 - time2) to return seconds" |
|
766 |
milliseconds := (aTime * 1000) asInteger. "integer seconds" |
|
767 |
] ifFalse:[ |
|
768 |
milliseconds := aTime getMilliseconds. |
|
769 |
]. |
|
770 |
^ self getMilliseconds > milliseconds |
|
771 |
||
772 |
" |
|
773 |
(Timestamp now + 10) - Timestamp now > 10 |
|
774 |
(Timestamp now + 10) - Timestamp now > 9 |
|
775 |
" |
|
6164 | 776 |
! |
777 |
||
778 |
hash |
|
779 |
"return an integer useful for hashing on times" |
|
780 |
||
10744
afd1835c12d2
comparison did only care for seconds, when used with timeDurations
sr
parents:
10666
diff
changeset
|
781 |
^ timeEncoding |
6164 | 782 |
! ! |
783 |
||
784 |
!Time methodsFor:'converting'! |
|
785 |
||
13235 | 786 |
asLocalTimestamp |
787 |
"return an Timestamp object from the receiver. |
|
788 |
So I am interpreted as a Time in the local timezone. |
|
789 |
The date components are taken from today." |
|
790 |
||
791 |
|todayTimestamp| |
|
792 |
||
793 |
todayTimestamp := Timestamp now. |
|
794 |
todayTimestamp year:todayTimestamp year month:todayTimestamp month day:todayTimestamp day |
|
17141 | 795 |
hour:(self hours) minute:(self minutes) second:(self seconds) |
796 |
millisecond:(self milliseconds). |
|
13235 | 797 |
|
798 |
^ todayTimestamp. |
|
799 |
||
800 |
" |
|
801 |
Time now asLocalTimestamp |
|
802 |
" |
|
803 |
! |
|
804 |
||
699 | 805 |
asTime |
16981 | 806 |
"return a Time object from the receiver - that's the receiver." |
699 | 807 |
|
6164 | 808 |
^ self |
8249
bdcae1232e6d
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8231
diff
changeset
|
809 |
! |
bdcae1232e6d
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8231
diff
changeset
|
810 |
|
8796 | 811 |
asTimeDuration |
812 |
"return an TimeDuration object from the receiver, taking the time since midnight." |
|
813 |
||
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
814 |
^ TimeDuration |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
815 |
hours:(self hours) minutes:(self minutes) seconds:(self seconds) |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
816 |
milliseconds:(self milliseconds) |
8796 | 817 |
" |
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
818 |
Time now asTimeDuration |
8796 | 819 |
" |
820 |
! |
|
821 |
||
8994
cbf9e75584fe
asTimeStamp -> asTimestamp for AbstractTime protocol compatibility
Stefan Vogel <sv@exept.de>
parents:
8796
diff
changeset
|
822 |
asTimestamp |
cbf9e75584fe
asTimeStamp -> asTimestamp for AbstractTime protocol compatibility
Stefan Vogel <sv@exept.de>
parents:
8796
diff
changeset
|
823 |
"return an Timestamp object from the receiver. |
8249
bdcae1232e6d
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8231
diff
changeset
|
824 |
The date components are taken from today." |
bdcae1232e6d
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8231
diff
changeset
|
825 |
|
13235 | 826 |
^ self asLocalTimestamp |
8249
bdcae1232e6d
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8231
diff
changeset
|
827 |
|
bdcae1232e6d
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8231
diff
changeset
|
828 |
" |
8994
cbf9e75584fe
asTimeStamp -> asTimestamp for AbstractTime protocol compatibility
Stefan Vogel <sv@exept.de>
parents:
8796
diff
changeset
|
829 |
Time now asTimestamp |
8249
bdcae1232e6d
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8231
diff
changeset
|
830 |
" |
13235 | 831 |
! |
832 |
||
833 |
asUtcTimestamp |
|
834 |
"return an UtcTimestamp object from the receiver. |
|
835 |
So I am interpreted as a Time in the UTC zone. |
|
836 |
The date components are taken from today." |
|
837 |
||
838 |
|todayTimestamp| |
|
839 |
||
16981 | 840 |
todayTimestamp := Timestamp now. |
13235 | 841 |
todayTimestamp year:todayTimestamp year month:todayTimestamp month day:todayTimestamp day |
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
842 |
hour:(self hours) minute:(self minutes) second:(self seconds) |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
843 |
millisecond:(self milliseconds). |
13235 | 844 |
|
16981 | 845 |
^ todayTimestamp asUtcTimestamp. |
13235 | 846 |
|
847 |
" |
|
16981 | 848 |
Time now asUtcTimestamp |
13235 | 849 |
" |
699 | 850 |
! ! |
851 |
||
6164 | 852 |
!Time methodsFor:'printing & storing'! |
853 |
||
854 |
print12HourFormatOn:aStream |
|
11151 | 855 |
"append a human readable printed representation of the receiver to aStream. |
6164 | 856 |
Format is hh:mm:ss am/pm (i.e. 12-hour american format)." |
857 |
||
858 |
^ self |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
859 |
printOn:aStream |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
860 |
format:(self class formatString12us) |
6164 | 861 |
|
862 |
"/ |h m s ampm| |
|
863 |
"/ |
|
864 |
"/ h := self hours. |
|
865 |
"/ |
|
866 |
"/ "/ 0 -> 12 am |
|
867 |
"/ "/ 12 -> 12 pm |
|
868 |
"/ |
|
869 |
"/ h // 12 == 0 ifTrue:[ |
|
870 |
"/ ampm := ' am'. |
|
871 |
"/ ] ifFalse:[ |
|
872 |
"/ ampm := ' pm'. |
|
873 |
"/ ]. |
|
874 |
"/ |
|
875 |
"/ h == 0 ifFalse:[ |
|
876 |
"/ h := h - 1 \\ 12 + 1. |
|
877 |
"/ ]. |
|
878 |
"/ |
|
879 |
"/ h printOn:aStream. |
|
880 |
"/ aStream nextPut:$:. |
|
881 |
"/ m := self minutes. |
|
882 |
"/ (m < 10) ifTrue:[aStream nextPut:$0]. |
|
883 |
"/ m printOn:aStream. |
|
884 |
"/ aStream nextPut:$:. |
|
885 |
"/ s := self seconds. |
|
886 |
"/ (s < 10) ifTrue:[aStream nextPut:$0]. |
|
887 |
"/ s printOn:aStream. |
|
888 |
"/ aStream nextPutAll:ampm |
|
889 |
||
890 |
" |
|
891 |
Time now print12HourFormatOn:Transcript. Transcript cr |
|
892 |
(Time now subtractHours:12) print12HourFormatOn:Transcript. Transcript cr |
|
893 |
(Time hour:24 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr |
|
894 |
(Time hour:12 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr |
|
895 |
(Time hour:0 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr |
|
896 |
0 to:24 do:[:h | |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
897 |
(Time hour:h minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr |
6164 | 898 |
] |
899 |
" |
|
900 |
! |
|
901 |
||
902 |
print24HourFormatOn:aStream |
|
11151 | 903 |
"append a human readable printed representation of the receiver to aStream. |
6164 | 904 |
Format is hh:mm:ss (i.e. 24-hour european format)." |
905 |
||
906 |
^ self |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
907 |
printOn:aStream |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
908 |
format:(self class formatString24). |
6164 | 909 |
|
910 |
"/ |h m s| |
|
911 |
"/ |
|
912 |
"/ h := self hours. |
|
913 |
"/ (h < 10) ifTrue:[aStream nextPut:$0]. |
|
914 |
"/ h printOn:aStream. |
|
915 |
"/ aStream nextPut:$:. |
|
916 |
"/ m := self minutes. |
|
917 |
"/ (m < 10) ifTrue:[aStream nextPut:$0]. |
|
918 |
"/ m printOn:aStream. |
|
919 |
"/ aStream nextPut:$:. |
|
920 |
"/ s := self seconds. |
|
921 |
"/ (s < 10) ifTrue:[aStream nextPut:$0]. |
|
922 |
"/ s printOn:aStream |
|
923 |
||
924 |
" |
|
925 |
Time now print24HourFormatOn:Transcript. Transcript cr |
|
926 |
" |
|
927 |
! |
|
928 |
||
929 |
printOn:aStream |
|
11151 | 930 |
"append a human readable printed representation of the receiver to aStream. |
6164 | 931 |
The format is suitable for a human - not meant to be read back. |
932 |
||
933 |
Format is hh:mm:ss either in 12-hour or 24-hour format. |
|
934 |
depending on the setting of LanguageTerritory. |
|
17162 | 935 |
I don't know what ST-80 does here (12-hour format ?)" |
6164 | 936 |
|
16940 | 937 |
|format| |
938 |
||
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
939 |
format := (self milliseconds = 0) |
17162 | 940 |
ifTrue:[self class defaultFormatString] |
941 |
ifFalse:[self class defaultFormatStringWithMilliseconds]. |
|
13213
d37c29bad3da
added: #defaultFormatString
Claus Gittinger <cg@exept.de>
parents:
12829
diff
changeset
|
942 |
^ self |
17162 | 943 |
printOn:aStream |
944 |
format:format |
|
6164 | 945 |
|
946 |
" |
|
947 |
Time now printOn:Transcript. Transcript cr |
|
948 |
" |
|
949 |
||
13213
d37c29bad3da
added: #defaultFormatString
Claus Gittinger <cg@exept.de>
parents:
12829
diff
changeset
|
950 |
"Modified: / 16-01-2011 / 11:27:24 / cg" |
6164 | 951 |
! |
952 |
||
953 |
printString12HourFormat |
|
954 |
"return a printed representation in 12 hour format" |
|
955 |
||
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
956 |
^ self printStringFormat:(self class formatString12us) |
6164 | 957 |
|
958 |
" |
|
959 |
Time now printString12HourFormat |
|
960 |
" |
|
961 |
! |
|
962 |
||
963 |
printString24HourFormat |
|
964 |
"return a printed representation in 24 hour format" |
|
965 |
||
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
966 |
^ self printStringFormat:(self class formatString24) |
6164 | 967 |
|
968 |
" |
|
969 |
Time now printString24HourFormat |
|
970 |
" |
|
971 |
||
972 |
! |
|
973 |
||
974 |
shortPrintString |
|
975 |
"dummy - for now" |
|
976 |
||
977 |
^ self printString |
|
978 |
||
979 |
"Created: 20.6.1997 / 17:17:01 / cg" |
|
980 |
! ! |
|
981 |
||
982 |
!Time methodsFor:'private'! |
|
983 |
||
984 |
fromOSTime:osTime |
|
13235 | 985 |
"set my time in the local timezone, given an osTime" |
6164 | 986 |
|
7513 | 987 |
|i| |
6164 | 988 |
|
7513 | 989 |
i := OperatingSystem computeTimeAndDateFrom:osTime. |
7740 | 990 |
self setHours:(i hours) minutes:(i minutes) seconds:(i seconds) |
6164 | 991 |
|
992 |
"Modified: 1.7.1996 / 15:21:06 / cg" |
|
993 |
! |
|
275 | 994 |
|
16940 | 995 |
fromOSTimeWithMilliseconds:osTime |
996 |
"set my time in the local timezone, given an osTime" |
|
997 |
||
998 |
|i| |
|
999 |
||
1000 |
i := OperatingSystem computeTimeAndDateFrom:osTime. |
|
1001 |
self setHours:(i hours) minutes:(i minutes) seconds:(i seconds) milliseconds:(i milliseconds) |
|
1002 |
! |
|
1003 |
||
13235 | 1004 |
fromUtcOSTime:osTime |
1005 |
"set my time in the local timezone, given an osTime" |
|
1006 |
||
1007 |
|i| |
|
1008 |
||
1009 |
i := OperatingSystem computeUTCTimeAndDateFrom:osTime. |
|
1010 |
self setHours:(i hours) minutes:(i minutes) seconds:(i seconds) |
|
1011 |
||
1012 |
"Modified: 1.7.1996 / 15:21:06 / cg" |
|
1013 |
! |
|
1014 |
||
3477 | 1015 |
getMilliseconds |
6046 | 1016 |
"return the number of milliseconds since midnight" |
1017 |
||
16933 | 1018 |
^ timeEncoding |
3477 | 1019 |
! |
1020 |
||
275 | 1021 |
getSeconds |
6046 | 1022 |
"return the number of seconds since midnight" |
1023 |
||
16933 | 1024 |
^ timeEncoding // 1000 |
275 | 1025 |
! |
1026 |
||
6165 | 1027 |
setHours:h minutes:m seconds:s |
699 | 1028 |
"set my time given individual values" |
1029 |
||
6165 | 1030 |
self setSeconds:(((h\\24) * 60 * 60 ) + (m * 60) + s). |
3477 | 1031 |
! |
1032 |
||
16937 | 1033 |
setHours:h minutes:m seconds:s milliseconds:ms |
1034 |
"set my time given individual values" |
|
1035 |
||
1036 |
self setMilliseconds:((((h\\24) * 60 * 60 ) + (m * 60) + s) * 1000) + ms. |
|
1037 |
! |
|
1038 |
||
3477 | 1039 |
setMilliseconds:millis |
16933 | 1040 |
"set my time given milliseconds since midnight. |
1041 |
Notice the modulo operations here - there cannot be a time beyond 24hours |
|
1042 |
(use TimeDuration, if you need that)." |
|
3477 | 1043 |
|
16933 | 1044 |
millis < 0 ifTrue:[ |
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
1045 |
timeEncoding := (24 * 3600 * 1000) - (millis negated \\ (24 * 3600 * 1000)) |
16933 | 1046 |
] ifFalse:[ |
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
1047 |
timeEncoding := millis |
16933 | 1048 |
]. |
1049 |
timeEncoding >= (24 * 3600 * 1000) ifTrue:[ |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
1050 |
timeEncoding := timeEncoding \\ (24 * 3600 * 1000). |
16933 | 1051 |
] |
1052 |
||
1053 |
" |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
1054 |
Time basicNew setSeconds:0 |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
1055 |
Time fromSeconds:3601 |
16933 | 1056 |
Time now seconds |
1057 |
Time now timeEncoding |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
1058 |
(Time now addDays:5) seconds |
16933 | 1059 |
(Time now addDays:5) timeEncoding |
1060 |
" |
|
699 | 1061 |
! |
1062 |
||
6904 | 1063 |
setSeconds:secs |
1064 |
"set my time given seconds since midnight. |
|
9441 | 1065 |
Notice the modulo operations here - there cannot be a time beyond 24hours |
6904 | 1066 |
(use TimeDuration, if you need that)." |
1067 |
||
16933 | 1068 |
self setMilliseconds:secs * 1000 |
6904 | 1069 |
|
1070 |
" |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
1071 |
Time basicNew setSeconds:0 |
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
1072 |
Time fromSeconds:3601 |
6904 | 1073 |
Time now seconds |
1074 |
Time now timeEncoding |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
1075 |
(Time now addDays:5) seconds |
6904 | 1076 |
(Time now addDays:5) timeEncoding |
1077 |
" |
|
1078 |
! |
|
1079 |
||
6165 | 1080 |
timeEncoding |
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
1081 |
"the internal encoding is stricktly private, |
6165 | 1082 |
and should not be used outside." |
1083 |
||
1084 |
^ timeEncoding |
|
1085 |
! |
|
1086 |
||
1087 |
timeEncoding:encoding |
|
17066
983f61f73c8f
wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents:
16985
diff
changeset
|
1088 |
"the internal encoding is stricktly private, |
6165 | 1089 |
and should not be used outside." |
1090 |
||
1091 |
timeEncoding := encoding |
|
699 | 1092 |
! ! |
1093 |
||
6165 | 1094 |
!Time class methodsFor:'documentation'! |
241 | 1095 |
|
699 | 1096 |
version |
19848 | 1097 |
^ '$Header$' |
12728 | 1098 |
! |
1099 |
||
1100 |
version_CVS |
|
19848 | 1101 |
^ '$Header$' |
241 | 1102 |
! ! |
17136 | 1103 |