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