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