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