author | Claus Gittinger <cg@exept.de> |
Wed, 13 May 1998 23:38:30 +0200 | |
changeset 3443 | d57ea75d3ac5 |
parent 3122 | a0be2e69caf0 |
child 3479 | 9ca6229713f4 |
permissions | -rw-r--r-- |
30 | 1 |
" |
2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
154 | 3 |
All Rights Reserved |
30 | 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 |
" |
|
12 |
||
241 | 13 |
AbstractTime subclass:#AbsoluteTime |
795 | 14 |
instanceVariableNames:'osTime' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Magnitude-General' |
|
30 | 18 |
! |
19 |
||
2311 | 20 |
!AbsoluteTime class methodsFor:'documentation'! |
30 | 21 |
|
82 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
154 | 25 |
All Rights Reserved |
82 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
30 | 36 |
documentation |
37 |
" |
|
1669 | 38 |
This class represents absolute time values in milliSeconds starting some |
1501 | 39 |
time in the past. |
40 |
(typically, from 1st. Jan 1970, as used in the Unix operating system, |
|
41 |
but other systems may bias the time differently. |
|
42 |
Actually, the implementation does not depend or even know which time/date |
|
43 |
the OperatingSystem bases its time upon - it is simply keeping the value(s) |
|
44 |
as return from the OS. |
|
45 |
For conversion, these values are given back to the OS, which will know |
|
46 |
how to convert these times. |
|
47 |
This has the advantage, that time-stamps on files (such as last-access- |
|
48 |
time or last-modifiaction-time) can be handled transparent to other |
|
49 |
times - especially comparisons). |
|
241 | 50 |
|
1501 | 51 |
You should not interpret the osTime instance variable directly, instead |
52 |
(if at all), as the OS to convert. |
|
30 | 53 |
|
1501 | 54 |
Its implementation is not the same as in ST-80 |
1669 | 55 |
(which represents Time as seconds from 1. Jan 1901.) |
30 | 56 |
|
241 | 57 |
This class should not be confused with Time (which only represents the |
1501 | 58 |
time within one day). |
59 |
Time instances cannot be used to compare times across midnight; |
|
60 |
instances of AbsoluteTime can. |
|
241 | 61 |
|
1306 | 62 |
[author:] |
3120 | 63 |
Claus Gittinger |
1306 | 64 |
|
1282 | 65 |
[See also:] |
3120 | 66 |
Time Date |
67 |
Delay ProcessorScheduler |
|
30 | 68 |
" |
69 |
! ! |
|
70 |
||
2311 | 71 |
!AbsoluteTime class methodsFor:'instance creation'! |
30 | 72 |
|
241 | 73 |
day:d month:m year:y hour:h minutes:min seconds:s |
1228 | 74 |
"return an instance of the receiver, given individual components. |
75 |
See also `AbsoluteTime now' and other protocol inherited |
|
76 |
from my superclass." |
|
30 | 77 |
|
1501 | 78 |
^ self |
3120 | 79 |
day:d month:m year:y hour:h |
80 |
minutes:min seconds:s milliseconds:0 |
|
1501 | 81 |
|
82 |
" |
|
83 |
AbsoluteTime day:2 month:1 year:1991 hour:12 minutes:30 seconds:0 |
|
84 |
AbsoluteTime day:8 month:1 year:1995 hour:0 minutes:43 seconds:48 |
|
85 |
" |
|
86 |
||
87 |
"Modified: 1.7.1996 / 15:22:26 / cg" |
|
88 |
! |
|
89 |
||
90 |
day:d month:m year:y hour:h minutes:min seconds:s milliseconds:millis |
|
91 |
"return an instance of the receiver, given individual components. |
|
92 |
See also `AbsoluteTime now' and other protocol inherited |
|
93 |
from my superclass." |
|
94 |
||
423 | 95 |
^ self basicNew |
3120 | 96 |
fromOSTime:(OperatingSystem |
97 |
computeOSTimeFromYear:y month:m day:d |
|
98 |
hour:h minute:min seconds:s |
|
99 |
millis:millis) |
|
30 | 100 |
|
241 | 101 |
" |
2311 | 102 |
AbsoluteTime day:1 month:1 year:1970 hour:1 minutes:0 seconds:0 |
241 | 103 |
AbsoluteTime day:2 month:1 year:1991 hour:12 minutes:30 seconds:0 |
1501 | 104 |
AbsoluteTime day:2 month:1 year:1991 hour:12 minutes:30 seconds:0 milliseconds:100 |
241 | 105 |
" |
1228 | 106 |
|
1501 | 107 |
"Created: 1.7.1996 / 14:46:09 / cg" |
108 |
"Modified: 1.7.1996 / 15:22:07 / cg" |
|
2311 | 109 |
"Modified: 22.10.1996 / 09:25:04 / stefan" |
275 | 110 |
! |
111 |
||
423 | 112 |
fromDate:aDate andTime:aTime |
113 |
"return an instance of the receiver, initialized from a time and a date |
|
1228 | 114 |
object. |
115 |
See also `AbsoluteTime now' and other protocol inherited |
|
116 |
from my superclass." |
|
423 | 117 |
|
118 |
^ self |
|
3120 | 119 |
day:aDate day |
120 |
month:aDate month |
|
121 |
year:aDate year |
|
122 |
hour:aTime hours |
|
123 |
minutes:aTime minutes |
|
124 |
seconds:aTime seconds |
|
423 | 125 |
|
126 |
" |
|
1228 | 127 |
AbsoluteTime fromDate:(Date today) andTime:(Time now) |
128 |
AbsoluteTime fromDate:(Date today plusDays:1) andTime:(Time now) |
|
129 |
AbsoluteTime now |
|
423 | 130 |
" |
131 |
||
132 |
"Modified: 8.9.1995 / 15:07:30 / claus" |
|
1228 | 133 |
"Modified: 19.4.1996 / 15:25:46 / cg" |
423 | 134 |
! |
135 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
136 |
newDay:dayInYear year:year |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
137 |
"return a new AbsoluteTime, given the year and the day-in-year (starting at 1). |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
138 |
Date protocol compatibility" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
139 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
140 |
^ (Date newDay:dayInYear year:year) asAbsoluteTime |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
141 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
142 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
143 |
AbsoluteTime newDay:183 year:1996 |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
144 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
145 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
146 |
"Modified: 2.7.1996 / 09:39:30 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
147 |
! |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
148 |
|
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
149 |
readFrom:aStringOrStream onError:exceptionBlock |
275 | 150 |
"return a new AbsoluteTime, reading a printed representation from aStream. |
151 |
The string is interpreted as 24 hour format, as printed. |
|
152 |
Notice, that this is not the storeString format and |
|
153 |
is different from the format expected by readFrom:." |
|
154 |
||
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
155 |
ErrorSignal handle:[:ex | |
3120 | 156 |
^ exceptionBlock value |
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
157 |
] do:[ |
3120 | 158 |
|str day month year hour min sec millis ex| |
275 | 159 |
|
3120 | 160 |
str := aStringOrStream readStream. |
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
161 |
|
3120 | 162 |
ex := [^ exceptionBlock value]. |
163 |
day := Integer readFrom:str onError:ex. |
|
164 |
(day between:1 and:31) ifFalse:[^ exceptionBlock value]. |
|
275 | 165 |
|
3120 | 166 |
[str peek isDigit] whileFalse:[str next]. |
167 |
month := Integer readFrom:str onError:ex. |
|
168 |
(month between:1 and:12) ifFalse:[^ exceptionBlock value]. |
|
275 | 169 |
|
3120 | 170 |
[str peek isDigit] whileFalse:[str next]. |
171 |
year := Integer readFrom:str onError:ex. |
|
275 | 172 |
|
3120 | 173 |
[str peek isDigit] whileFalse:[str next]. |
174 |
hour := Integer readFrom:str onError:ex. |
|
175 |
(hour between:0 and:24) ifFalse:[^ exceptionBlock value]. |
|
275 | 176 |
|
3120 | 177 |
[str peek isDigit] whileFalse:[str next]. |
178 |
min := Integer readFrom:str onError:ex. |
|
179 |
(min between:0 and:59) ifFalse:[^ exceptionBlock value]. |
|
275 | 180 |
|
3120 | 181 |
[str peek isDigit] whileFalse:[str next]. |
182 |
sec := Integer readFrom:str onError:ex. |
|
183 |
(sec between:0 and:59) ifFalse:[^ exceptionBlock value]. |
|
275 | 184 |
|
3120 | 185 |
str peek = '.' ifTrue:[ |
186 |
str next. |
|
187 |
millis := Integer readFrom:str onError:ex. |
|
188 |
] ifFalse:[ |
|
189 |
millis := 0. |
|
190 |
]. |
|
1501 | 191 |
|
3120 | 192 |
"special check" |
193 |
hour == 24 ifTrue:[ |
|
194 |
(min ~~ 0 or:[sec ~~ 0]) ifTrue:[^ exceptionBlock value]. |
|
195 |
]. |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
196 |
|
3120 | 197 |
^ self day:day month:month year:year hour:hour minutes:min seconds:sec |
275 | 198 |
]. |
199 |
||
200 |
" |
|
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
201 |
AbsoluteTime readFrom:'20-2-1995 13:11:06' |
1501 | 202 |
AbsoluteTime readFrom:'20-2-1995 13:11:06.100' |
275 | 203 |
" |
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
204 |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
205 |
"Modified: 8.10.1996 / 19:25:59 / cg" |
2311 | 206 |
! |
207 |
||
208 |
secondsSince1970:sec |
|
209 |
"set time from elapsed seconds since 1-1-1970, 0:0:0. |
|
210 |
This is the format used in the UNIX world" |
|
211 |
||
212 |
^ self day:1 month:1 year:1970 hour:0 minutes:0 seconds:sec. |
|
213 |
||
214 |
" |
|
3120 | 215 |
AbsoluteTime secondsSince1970:0 |
216 |
AbsoluteTime secondsSince1970:3600 |
|
2311 | 217 |
" |
218 |
||
219 |
"Created: 21.10.1996 / 17:48:30 / stefan" |
|
220 |
"Modified: 22.10.1996 / 11:07:45 / stefan" |
|
241 | 221 |
! ! |
30 | 222 |
|
223 |
!AbsoluteTime methodsFor:'accessing'! |
|
224 |
||
225 |
day |
|
92 | 226 |
"return the day-in-month of the receiver (1..31). |
275 | 227 |
For compatibility, use instances of Date for this." |
30 | 228 |
|
241 | 229 |
|d| |
230 |
||
275 | 231 |
OperatingSystem computeDatePartsOf:osTime for:[:year :month :day | |
3120 | 232 |
d := day |
241 | 233 |
]. |
234 |
^ d |
|
54 | 235 |
|
92 | 236 |
" |
241 | 237 |
AbsoluteTime now day |
92 | 238 |
" |
1501 | 239 |
|
240 |
"Modified: 1.7.1996 / 15:23:02 / cg" |
|
241 |
! |
|
242 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
243 |
dayInWeek |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
244 |
"return the week-day of the receiver - 1 for monday, 7 for sunday" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
245 |
|
3120 | 246 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) at:11 |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
247 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
248 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
249 |
AbsoluteTime now dayInWeek |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
250 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
251 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
252 |
"Modified: 2.7.1996 / 09:20:32 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
253 |
"Created: 2.7.1996 / 09:35:48 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
254 |
! |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
255 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
256 |
dayInYear |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
257 |
"return the year-day of the receiver - 1 for Jan, 1st." |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
258 |
|
3120 | 259 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) at:10 |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
260 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
261 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
262 |
AbsoluteTime now dayInYear |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
263 |
AbsoluteTime newDay:184 year:1996 |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
264 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
265 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
266 |
"Modified: 2.7.1996 / 10:21:02 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
267 |
! |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
268 |
|
1501 | 269 |
hour |
270 |
"return the hour (0..23). |
|
271 |
ST-80 Timestamp compatibility (I'd prefer the name #hours, for Time compatibility)." |
|
272 |
||
273 |
^ self hours |
|
274 |
||
275 |
"Created: 1.7.1996 / 15:14:50 / cg" |
|
276 |
"Modified: 1.7.1996 / 15:15:32 / cg" |
|
30 | 277 |
! |
278 |
||
241 | 279 |
hours |
280 |
"return the hours (0..23)" |
|
281 |
||
282 |
|hr| |
|
283 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
284 |
OperatingSystem computeTimePartsOf:osTime for:[:hours :minutes :secs :millis | |
3120 | 285 |
hr := hours |
241 | 286 |
]. |
287 |
^ hr |
|
54 | 288 |
|
92 | 289 |
" |
241 | 290 |
AbsoluteTime now hours |
291 |
" |
|
292 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
293 |
"Modified: 2.7.1996 / 09:20:32 / cg" |
1501 | 294 |
! |
295 |
||
296 |
millisecond |
|
297 |
"return the millisecond (0..999). |
|
298 |
ST-80 Timestamp compatibility (I'd prefer the name #milliseconds)." |
|
299 |
||
300 |
^ self milliseconds |
|
301 |
||
302 |
"Created: 1.7.1996 / 15:14:50 / cg" |
|
303 |
"Modified: 1.7.1996 / 15:15:24 / cg" |
|
304 |
! |
|
305 |
||
306 |
milliseconds |
|
307 |
"return the milliseconds (0..999)" |
|
308 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
309 |
|m| |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
310 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
311 |
OperatingSystem computeTimePartsOf:osTime for:[:hours :minutes :secs :millis | |
3120 | 312 |
m := millis |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
313 |
]. |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
314 |
^ m |
1501 | 315 |
|
316 |
" |
|
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
317 |
AbsoluteTime now milliseconds |
1501 | 318 |
" |
319 |
||
320 |
"Created: 1.7.1996 / 15:15:02 / cg" |
|
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
321 |
"Modified: 2.7.1996 / 09:21:41 / cg" |
1501 | 322 |
! |
323 |
||
324 |
minute |
|
325 |
"return the minute (0..59). |
|
326 |
ST-80 Timestamp compatibility (I'd prefer the name #minutes, for Time compatibility)." |
|
327 |
||
328 |
^ self minutes |
|
329 |
||
330 |
"Created: 1.7.1996 / 15:14:29 / cg" |
|
331 |
"Modified: 1.7.1996 / 15:15:37 / cg" |
|
241 | 332 |
! |
333 |
||
334 |
minutes |
|
335 |
"return the minutes (0..59)" |
|
336 |
||
337 |
|m| |
|
338 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
339 |
OperatingSystem computeTimePartsOf:osTime for:[:hours :minutes :secs :millis | |
3120 | 340 |
m := minutes |
241 | 341 |
]. |
342 |
^ m |
|
343 |
||
344 |
" |
|
345 |
AbsoluteTime now minutes |
|
92 | 346 |
" |
241 | 347 |
|
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
348 |
"Modified: 2.7.1996 / 09:20:49 / cg" |
241 | 349 |
! |
350 |
||
699 | 351 |
month |
352 |
"return the month of the receiver (1..12). |
|
353 |
For compatibility, use instances of Date for this." |
|
354 |
||
355 |
|m| |
|
356 |
||
357 |
OperatingSystem computeDatePartsOf:osTime for:[ :year :month :day | |
|
3120 | 358 |
m := month |
699 | 359 |
]. |
360 |
^ m |
|
361 |
||
362 |
" |
|
363 |
AbsoluteTime now month |
|
364 |
" |
|
1501 | 365 |
|
366 |
"Modified: 1.7.1996 / 15:23:05 / cg" |
|
367 |
! |
|
368 |
||
369 |
second |
|
370 |
"return the second (0..59). |
|
371 |
ST-80 Timestamp compatibility (I'd prefer the name #seconds, for Time compatibility)." |
|
372 |
||
373 |
^ self seconds |
|
374 |
||
375 |
"Created: 1.7.1996 / 15:14:19 / cg" |
|
376 |
"Modified: 1.7.1996 / 15:15:49 / cg" |
|
699 | 377 |
! |
378 |
||
241 | 379 |
seconds |
380 |
"return the seconds (0..59)" |
|
381 |
||
382 |
|s| |
|
383 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
384 |
OperatingSystem computeTimePartsOf:osTime for:[:hours :minutes :secs :millis | |
3120 | 385 |
s := secs |
241 | 386 |
]. |
387 |
^ s |
|
388 |
||
389 |
" |
|
390 |
AbsoluteTime now seconds |
|
391 |
" |
|
392 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
393 |
"Modified: 2.7.1996 / 09:20:54 / cg" |
92 | 394 |
! |
395 |
||
799 | 396 |
utcOffset |
397 |
"return the difference between UTC (Greenwich Mean Time) and the local time |
|
398 |
if daylight saving time applies to ourself, take that into account. |
|
399 |
Add utcOffset bevor converting to get UTC-Time resp. UTC-Date. |
|
400 |
" |
|
401 |
||
402 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) at:7 |
|
403 |
||
404 |
" |
|
405 |
AbsoluteTime now utcOffset |
|
406 |
(AbsoluteTime day:1 month:7 year:1995 hour:12 minutes:0 seconds:0) utcOffset |
|
407 |
" |
|
408 |
||
409 |
"Modified: 20.12.1995 / 17:28:49 / stefan" |
|
1501 | 410 |
"Modified: 1.7.1996 / 15:21:29 / cg" |
799 | 411 |
! |
412 |
||
699 | 413 |
year |
414 |
"return the year of the receiver i.e. 1992. |
|
415 |
For compatibility, use instances of Date for this." |
|
241 | 416 |
|
699 | 417 |
|y| |
241 | 418 |
|
699 | 419 |
OperatingSystem computeDatePartsOf:osTime for:[:year :month :day | |
3120 | 420 |
y := year |
699 | 421 |
]. |
422 |
^ y |
|
241 | 423 |
|
424 |
" |
|
699 | 425 |
AbsoluteTime now year |
241 | 426 |
" |
1501 | 427 |
|
428 |
"Modified: 1.7.1996 / 15:23:08 / cg" |
|
241 | 429 |
! ! |
430 |
||
30 | 431 |
!AbsoluteTime methodsFor:'arithmetic'! |
432 |
||
433 |
- aTime |
|
242 | 434 |
"return the delta in seconds between 2 times." |
30 | 435 |
|
436 |
^ self getSeconds - (aTime getSeconds) |
|
437 |
! |
|
438 |
||
242 | 439 |
addDays:numberOfDays |
440 |
"return a new instance of myself, numberOfDays afterwards." |
|
441 |
||
442 |
^ self addSeconds:(numberOfDays * (60 * 60 * 24)) |
|
443 |
||
444 |
" |
|
445 |
|t| |
|
446 |
||
447 |
t := AbsoluteTime now. |
|
448 |
t printNL. |
|
449 |
(t addDays:7) printNL |
|
450 |
" |
|
451 |
! |
|
452 |
||
3122 | 453 |
addMilliseconds:nMillis |
454 |
"return a new absoluteTime instance, nMillis milliseconds after myself" |
|
455 |
||
456 |
^ (self class basicNew) setMilliseconds:(self getMilliseconds + nMillis) |
|
457 |
||
458 |
" |
|
459 |
|t1 t2| |
|
460 |
||
461 |
t1 := AbsoluteTime now. |
|
462 |
t2 := t1 addMilliseconds:10. |
|
463 |
Transcript showCR:t1. |
|
464 |
Transcript showCR:t2. |
|
465 |
" |
|
466 |
||
467 |
"Modified: / 2.12.1997 / 17:10:39 / cg" |
|
468 |
! |
|
469 |
||
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
470 |
millisecondDeltaFrom:anAbsoluteTime |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
471 |
"return the delta in milliseconds between 2 absolute times." |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
472 |
|
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
473 |
^ (self getSeconds - (anAbsoluteTime getSeconds)) * 1000 |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
474 |
+ self milliseconds - anAbsoluteTime milliseconds |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
475 |
|
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
476 |
" |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
477 |
|t1 t2| |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
478 |
|
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
479 |
t1 := AbsoluteTime now. |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
480 |
Delay waitForSeconds:0.5. |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
481 |
t2 := AbsoluteTime now. |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
482 |
t2 millisecondDeltaFrom:t1 |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
483 |
" |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
484 |
|
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
485 |
"Modified: 7.5.1997 / 16:38:49 / cg" |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
486 |
! |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
487 |
|
242 | 488 |
subtractDays:numberOfDays |
489 |
"return a new instance of myself, numberOfDays before." |
|
490 |
||
491 |
^ self subtractSeconds:(numberOfDays * (60 * 60 * 24)) |
|
492 |
||
493 |
" |
|
494 |
|t| |
|
495 |
||
496 |
t := AbsoluteTime now. |
|
497 |
t printNL. |
|
498 |
(t subtractDays:50) printNL |
|
499 |
" |
|
30 | 500 |
! ! |
501 |
||
699 | 502 |
!AbsoluteTime methodsFor:'comparing'! |
503 |
||
504 |
< aTime |
|
505 |
"return true if the argument, aTime is before the receiver" |
|
506 |
||
1520
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
507 |
^ self getMilliseconds < aTime getMilliseconds |
699 | 508 |
|
1520
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
509 |
"Modified: 3.7.1996 / 13:10:17 / cg" |
699 | 510 |
! |
511 |
||
512 |
= aTime |
|
513 |
"return true if the argument, aTime represents the same time" |
|
514 |
||
515 |
(aTime species == self species) ifFalse:[^ false]. |
|
1520
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
516 |
^ (self getMilliseconds = aTime getMilliseconds) |
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
517 |
|
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
518 |
"Modified: 3.7.1996 / 13:10:24 / cg" |
699 | 519 |
! |
520 |
||
521 |
> aTime |
|
522 |
"return true if the argument, aTime is after the receiver" |
|
523 |
||
1501 | 524 |
^ self getMilliseconds > aTime getMilliseconds |
699 | 525 |
|
1501 | 526 |
"Modified: 1.7.1996 / 15:24:38 / cg" |
699 | 527 |
! |
528 |
||
529 |
hash |
|
530 |
"return an integer useful for hashing on times" |
|
531 |
||
1520
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
532 |
^ osTime // 1000 |
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
533 |
|
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
534 |
"Modified: 3.7.1996 / 13:10:52 / cg" |
699 | 535 |
! ! |
536 |
||
537 |
!AbsoluteTime methodsFor:'converting'! |
|
538 |
||
539 |
asAbsoluteTime |
|
540 |
"return an AbsoluteTime object from the receiver - thats the receiver." |
|
541 |
||
542 |
^ self |
|
543 |
! |
|
544 |
||
545 |
asDate |
|
546 |
"return a Date object from the receiver. |
|
547 |
The returned date will only represent the day - not the timeOfDay." |
|
548 |
||
549 |
^ Date fromOSTime:osTime |
|
550 |
||
551 |
" |
|
552 |
AbsoluteTime now |
|
553 |
AbsoluteTime now asDate |
|
554 |
(AbsoluteTime now addTime:3600) asDate |
|
555 |
(AbsoluteTime now addTime:3600) asTime |
|
556 |
AbsoluteTime fromSeconds:(AbsoluteTime now asSeconds + 3600) |
|
557 |
(AbsoluteTime fromSeconds:(AbsoluteTime now asSeconds + 3600)) asDate |
|
558 |
" |
|
559 |
||
560 |
! |
|
561 |
||
562 |
asSeconds |
|
563 |
"return the number of seconds elapsed since whatever time the |
|
564 |
OperatingSystem bases its time upon. Since this is totally |
|
565 |
OS-dependent, do not interpret the value returned by this method. |
|
566 |
You can use it to add/subtract seconds or get time deltas, though." |
|
567 |
||
568 |
^ self getSeconds |
|
569 |
||
570 |
" |
|
571 |
AbsoluteTime now asSeconds |
|
572 |
AbsoluteTime fromSeconds:(AbsoluteTime now asSeconds + 3600) |
|
573 |
Time hour:23 minutes:33 seconds:0 |
|
574 |
Time fromSeconds:((Time hour:23 minutes:33 seconds:0) asSeconds + 3600) |
|
575 |
" |
|
576 |
! |
|
577 |
||
578 |
asTime |
|
579 |
"return a Time object from the receiver. |
|
580 |
The returned time will only represent the timeOfDay - not the day." |
|
581 |
||
582 |
^ Time fromOSTime:osTime |
|
583 |
||
584 |
" |
|
585 |
AbsoluteTime now |
|
586 |
AbsoluteTime now asTime |
|
587 |
(AbsoluteTime now addTime:3600) asTime |
|
588 |
" |
|
589 |
! ! |
|
590 |
||
213 | 591 |
!AbsoluteTime methodsFor:'printing & storing'! |
30 | 592 |
|
241 | 593 |
printOn:aStream |
275 | 594 |
"append a user readable representation of the receiver to aStream. |
595 |
The format is compatible with readFromString:, but not with readFrom:." |
|
596 |
||
1501 | 597 |
|h min s mil d m y| |
30 | 598 |
|
275 | 599 |
OperatingSystem computeDatePartsOf:osTime for:[ |
3120 | 600 |
:year :month :day | d := day. m := month. y := year. |
241 | 601 |
]. |
275 | 602 |
OperatingSystem computeTimePartsOf:osTime for:[ |
3120 | 603 |
:hours :minutes :secs :millis | h := hours. min := minutes. s := secs. mil := millis |
241 | 604 |
]. |
605 |
d printOn:aStream. |
|
606 |
aStream nextPut:$-. |
|
607 |
m printOn:aStream. |
|
608 |
aStream nextPut:$-. |
|
609 |
y printOn:aStream. |
|
610 |
aStream space. |
|
611 |
h printOn:aStream leftPaddedTo:2 with:$0. |
|
612 |
aStream nextPut:$:. |
|
613 |
min printOn:aStream leftPaddedTo:2 with:$0. |
|
614 |
aStream nextPut:$:. |
|
615 |
s printOn:aStream leftPaddedTo:2 with:$0. |
|
1501 | 616 |
mil ~~ 0 ifTrue:[ |
3120 | 617 |
aStream nextPut:$.. |
618 |
mil printOn:aStream leftPaddedTo:3 with:$0. |
|
1501 | 619 |
]. |
92 | 620 |
|
621 |
" |
|
275 | 622 |
AbsoluteTime now printOn:Transcript. Transcript cr. |
623 |
(AbsoluteTime fromSeconds:0) printOn:Transcript. Transcript cr. |
|
624 |
Time now printOn:Transcript. Transcript cr. |
|
625 |
Date today printOn:Transcript. Transcript cr. |
|
1501 | 626 |
|
627 |
Time now asAbsoluteTime printOn:Transcript. Transcript cr. |
|
628 |
AbsoluteTime now printOn:Transcript. Transcript cr. |
|
629 |
||
630 |
Date today asAbsoluteTime printOn:Transcript. Transcript cr. |
|
631 |
Date today printOn:Transcript. Transcript cr. |
|
92 | 632 |
" |
1501 | 633 |
|
634 |
"Modified: 1.7.1996 / 15:20:59 / cg" |
|
30 | 635 |
! |
636 |
||
241 | 637 |
storeOn:aStream |
275 | 638 |
"store the receiver in a format suitable for reconstruction of the |
639 |
receiver via readFrom:" |
|
640 |
||
241 | 641 |
aStream nextPut:$(; |
242 | 642 |
nextPutAll:self class name; |
275 | 643 |
nextPutAll:' new setSeconds:'. |
644 |
self getSeconds storeOn:aStream. |
|
241 | 645 |
aStream nextPut:$). |
54 | 646 |
|
241 | 647 |
" |
275 | 648 |
AbsoluteTime now storeString |
30 | 649 |
|
275 | 650 |
AbsoluteTime readFrom:(AbsoluteTime now storeString) readStream |
241 | 651 |
" |
30 | 652 |
! ! |
699 | 653 |
|
654 |
!AbsoluteTime methodsFor:'private'! |
|
655 |
||
1501 | 656 |
fromOSTime:anUninterpretedOSTime |
699 | 657 |
"strictly private: set the seconds from an OS time (since whatever)" |
658 |
||
1501 | 659 |
osTime := anUninterpretedOSTime |
660 |
||
661 |
"Created: 1.7.1996 / 14:33:21 / cg" |
|
662 |
! |
|
663 |
||
664 |
getMilliseconds |
|
665 |
"strictly private: return the milliseconds (since whatever)" |
|
666 |
||
667 |
^ osTime |
|
668 |
||
669 |
"Created: 1.7.1996 / 14:33:56 / cg" |
|
699 | 670 |
! |
671 |
||
672 |
getSeconds |
|
673 |
"strictly private: return the seconds (since whatever)" |
|
674 |
||
1501 | 675 |
^ osTime // 1000 |
676 |
||
677 |
"Modified: 1.7.1996 / 14:33:44 / cg" |
|
699 | 678 |
! |
679 |
||
1501 | 680 |
setMilliseconds:millis |
681 |
"strictly private: set the milliseconds (since whatever)" |
|
682 |
||
683 |
osTime := millis. |
|
684 |
||
685 |
"Modified: 20.12.1995 / 11:46:36 / stefan" |
|
686 |
"Created: 1.7.1996 / 14:34:24 / cg" |
|
687 |
! |
|
688 |
||
699 | 689 |
setSeconds:secs |
690 |
"strictly private: set the seconds (since whatever)" |
|
691 |
||
1501 | 692 |
osTime := secs * 1000. |
795 | 693 |
|
694 |
"Modified: 20.12.1995 / 11:46:36 / stefan" |
|
1501 | 695 |
"Modified: 1.7.1996 / 14:34:10 / cg" |
699 | 696 |
! ! |
697 |
||
2311 | 698 |
!AbsoluteTime class methodsFor:'documentation'! |
699 | 699 |
|
700 |
version |
|
3122 | 701 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/AbsTime.st,v 1.34 1997-12-04 13:15:43 cg Exp $' |
699 | 702 |
! ! |