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