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