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