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