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