author | Claus Gittinger <cg@exept.de> |
Thu, 19 Jun 1997 16:17:25 +0200 | |
changeset 2694 | 46ba8cbdc013 |
parent 2623 | 593ab389efd1 |
child 3120 | 56348e25a94f |
permissions | -rw-r--r-- |
30 | 1 |
" |
2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
154 | 3 |
All Rights Reserved |
30 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
241 | 13 |
AbstractTime subclass:#AbsoluteTime |
795 | 14 |
instanceVariableNames:'osTime' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Magnitude-General' |
|
30 | 18 |
! |
19 |
||
2311 | 20 |
!AbsoluteTime class methodsFor:'documentation'! |
30 | 21 |
|
82 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
154 | 25 |
All Rights Reserved |
82 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
30 | 36 |
documentation |
37 |
" |
|
1669 | 38 |
This class represents absolute time values in milliSeconds starting some |
1501 | 39 |
time in the past. |
40 |
(typically, from 1st. Jan 1970, as used in the Unix operating system, |
|
41 |
but other systems may bias the time differently. |
|
42 |
Actually, the implementation does not depend or even know which time/date |
|
43 |
the OperatingSystem bases its time upon - it is simply keeping the value(s) |
|
44 |
as return from the OS. |
|
45 |
For conversion, these values are given back to the OS, which will know |
|
46 |
how to convert these times. |
|
47 |
This has the advantage, that time-stamps on files (such as last-access- |
|
48 |
time or last-modifiaction-time) can be handled transparent to other |
|
49 |
times - especially comparisons). |
|
241 | 50 |
|
1501 | 51 |
You should not interpret the osTime instance variable directly, instead |
52 |
(if at all), as the OS to convert. |
|
30 | 53 |
|
1501 | 54 |
Its implementation is not the same as in ST-80 |
1669 | 55 |
(which represents Time as seconds from 1. Jan 1901.) |
30 | 56 |
|
241 | 57 |
This class should not be confused with Time (which only represents the |
1501 | 58 |
time within one day). |
59 |
Time instances cannot be used to compare times across midnight; |
|
60 |
instances of AbsoluteTime can. |
|
241 | 61 |
|
1306 | 62 |
[author:] |
63 |
Claus Gittinger |
|
64 |
||
1282 | 65 |
[See also:] |
66 |
Time Date |
|
67 |
Delay ProcessorScheduler |
|
30 | 68 |
" |
69 |
! ! |
|
70 |
||
2311 | 71 |
!AbsoluteTime class methodsFor:'instance creation'! |
30 | 72 |
|
241 | 73 |
day:d month:m year:y hour:h minutes:min seconds:s |
1228 | 74 |
"return an instance of the receiver, given individual components. |
75 |
See also `AbsoluteTime now' and other protocol inherited |
|
76 |
from my superclass." |
|
30 | 77 |
|
1501 | 78 |
^ self |
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 |
" |
2311 | 102 |
AbsoluteTime day:1 month:1 year:1970 hour:1 minutes:0 seconds:0 |
241 | 103 |
AbsoluteTime day:2 month:1 year:1991 hour:12 minutes:30 seconds:0 |
1501 | 104 |
AbsoluteTime day:2 month:1 year:1991 hour:12 minutes:30 seconds:0 milliseconds:100 |
241 | 105 |
" |
1228 | 106 |
|
1501 | 107 |
"Created: 1.7.1996 / 14:46:09 / cg" |
108 |
"Modified: 1.7.1996 / 15:22:07 / cg" |
|
2311 | 109 |
"Modified: 22.10.1996 / 09:25:04 / stefan" |
275 | 110 |
! |
111 |
||
423 | 112 |
fromDate:aDate andTime:aTime |
113 |
"return an instance of the receiver, initialized from a time and a date |
|
1228 | 114 |
object. |
115 |
See also `AbsoluteTime now' and other protocol inherited |
|
116 |
from my superclass." |
|
423 | 117 |
|
118 |
^ self |
|
1228 | 119 |
day:aDate day |
120 |
month:aDate month |
|
121 |
year:aDate year |
|
122 |
hour:aTime hours |
|
123 |
minutes:aTime minutes |
|
124 |
seconds:aTime seconds |
|
423 | 125 |
|
126 |
" |
|
1228 | 127 |
AbsoluteTime fromDate:(Date today) andTime:(Time now) |
128 |
AbsoluteTime fromDate:(Date today plusDays:1) andTime:(Time now) |
|
129 |
AbsoluteTime now |
|
423 | 130 |
" |
131 |
||
132 |
"Modified: 8.9.1995 / 15:07:30 / claus" |
|
1228 | 133 |
"Modified: 19.4.1996 / 15:25:46 / cg" |
423 | 134 |
! |
135 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
136 |
newDay:dayInYear year:year |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
137 |
"return a new AbsoluteTime, given the year and the day-in-year (starting at 1). |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
138 |
Date protocol compatibility" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
139 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
140 |
^ (Date newDay:dayInYear year:year) asAbsoluteTime |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
141 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
142 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
143 |
AbsoluteTime newDay:183 year:1996 |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
144 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
145 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
146 |
"Modified: 2.7.1996 / 09:39:30 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
147 |
! |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
148 |
|
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
149 |
readFrom:aStringOrStream onError:exceptionBlock |
275 | 150 |
"return a new AbsoluteTime, reading a printed representation from aStream. |
151 |
The string is interpreted as 24 hour format, as printed. |
|
152 |
Notice, that this is not the storeString format and |
|
153 |
is different from the format expected by readFrom:." |
|
154 |
||
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
155 |
ErrorSignal handle:[:ex | |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
156 |
^ exceptionBlock value |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
157 |
] do:[ |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
158 |
|str day month year hour min sec millis ex| |
275 | 159 |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
160 |
str := aStringOrStream readStream. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
161 |
|
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
162 |
ex := [^ exceptionBlock value]. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
163 |
day := Integer readFrom:str onError:ex. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
164 |
(day between:1 and:31) ifFalse:[^ exceptionBlock value]. |
275 | 165 |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
166 |
[str peek isDigit] whileFalse:[str next]. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
167 |
month := Integer readFrom:str onError:ex. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
168 |
(month between:1 and:12) ifFalse:[^ exceptionBlock value]. |
275 | 169 |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
170 |
[str peek isDigit] whileFalse:[str next]. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
171 |
year := Integer readFrom:str onError:ex. |
275 | 172 |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
173 |
[str peek isDigit] whileFalse:[str next]. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
174 |
hour := Integer readFrom:str onError:ex. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
175 |
(hour between:0 and:24) ifFalse:[^ exceptionBlock value]. |
275 | 176 |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
177 |
[str peek isDigit] whileFalse:[str next]. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
178 |
min := Integer readFrom:str onError:ex. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
179 |
(min between:0 and:59) ifFalse:[^ exceptionBlock value]. |
275 | 180 |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
181 |
[str peek isDigit] whileFalse:[str next]. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
182 |
sec := Integer readFrom:str onError:ex. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
183 |
(sec between:0 and:59) ifFalse:[^ exceptionBlock value]. |
275 | 184 |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
185 |
str peek = '.' ifTrue:[ |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
186 |
str next. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
187 |
millis := Integer readFrom:str onError:ex. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
188 |
] ifFalse:[ |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
189 |
millis := 0. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
190 |
]. |
1501 | 191 |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
192 |
"special check" |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
193 |
hour == 24 ifTrue:[ |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
194 |
(min ~~ 0 or:[sec ~~ 0]) ifTrue:[^ exceptionBlock value]. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
195 |
]. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
196 |
|
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
197 |
^ self day:day month:month year:year hour:hour minutes:min seconds:sec |
275 | 198 |
]. |
199 |
||
200 |
" |
|
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
201 |
AbsoluteTime readFrom:'20-2-1995 13:11:06' |
1501 | 202 |
AbsoluteTime readFrom:'20-2-1995 13:11:06.100' |
275 | 203 |
" |
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
204 |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1669
diff
changeset
|
205 |
"Modified: 8.10.1996 / 19:25:59 / cg" |
2311 | 206 |
! |
207 |
||
208 |
secondsSince1970:sec |
|
209 |
"set time from elapsed seconds since 1-1-1970, 0:0:0. |
|
210 |
This is the format used in the UNIX world" |
|
211 |
||
212 |
^ self day:1 month:1 year:1970 hour:0 minutes:0 seconds:sec. |
|
213 |
||
214 |
" |
|
215 |
AbsoluteTime secondsSince1970:0 |
|
216 |
AbsoluteTime secondsSince1970:3600 |
|
217 |
" |
|
218 |
||
219 |
"Created: 21.10.1996 / 17:48:30 / stefan" |
|
220 |
"Modified: 22.10.1996 / 11:07:45 / stefan" |
|
241 | 221 |
! ! |
30 | 222 |
|
223 |
!AbsoluteTime methodsFor:'accessing'! |
|
224 |
||
225 |
day |
|
92 | 226 |
"return the day-in-month of the receiver (1..31). |
275 | 227 |
For compatibility, use instances of Date for this." |
30 | 228 |
|
241 | 229 |
|d| |
230 |
||
275 | 231 |
OperatingSystem computeDatePartsOf:osTime for:[:year :month :day | |
1501 | 232 |
d := day |
241 | 233 |
]. |
234 |
^ d |
|
54 | 235 |
|
92 | 236 |
" |
241 | 237 |
AbsoluteTime now day |
92 | 238 |
" |
1501 | 239 |
|
240 |
"Modified: 1.7.1996 / 15:23:02 / cg" |
|
241 |
! |
|
242 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
243 |
dayInWeek |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
244 |
"return the week-day of the receiver - 1 for monday, 7 for sunday" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
245 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
246 |
|info| |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
247 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
248 |
info := OperatingSystem computeTimeAndDateFrom:osTime. |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
249 |
^ info at:11 |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
250 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
251 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
252 |
AbsoluteTime now dayInWeek |
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 |
"Modified: 2.7.1996 / 09:20:32 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
256 |
"Created: 2.7.1996 / 09:35:48 / cg" |
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 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
259 |
dayInYear |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
260 |
"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
|
261 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
262 |
|info| |
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 |
info := OperatingSystem computeTimeAndDateFrom:osTime. |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
265 |
^ info at:10 |
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 | |
1501 | 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 | |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
318 |
m := millis |
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 | |
1501 | 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 | |
|
1501 | 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 | |
1501 | 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 | |
1501 | 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 |
||
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
459 |
millisecondDeltaFrom:anAbsoluteTime |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
460 |
"return the delta in milliseconds between 2 absolute times." |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
461 |
|
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
462 |
^ (self getSeconds - (anAbsoluteTime getSeconds)) * 1000 |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
463 |
+ self milliseconds - anAbsoluteTime milliseconds |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
464 |
|
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
465 |
" |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
466 |
|t1 t2| |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
467 |
|
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
468 |
t1 := AbsoluteTime now. |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
469 |
Delay waitForSeconds:0.5. |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
470 |
t2 := AbsoluteTime now. |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
471 |
t2 millisecondDeltaFrom:t1 |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
472 |
" |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
473 |
|
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
474 |
"Modified: 7.5.1997 / 16:38:49 / cg" |
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 |
|
242 | 477 |
subtractDays:numberOfDays |
478 |
"return a new instance of myself, numberOfDays before." |
|
479 |
||
480 |
^ self subtractSeconds:(numberOfDays * (60 * 60 * 24)) |
|
481 |
||
482 |
" |
|
483 |
|t| |
|
484 |
||
485 |
t := AbsoluteTime now. |
|
486 |
t printNL. |
|
487 |
(t subtractDays:50) printNL |
|
488 |
" |
|
30 | 489 |
! ! |
490 |
||
699 | 491 |
!AbsoluteTime methodsFor:'comparing'! |
492 |
||
493 |
< aTime |
|
494 |
"return true if the argument, aTime is before the receiver" |
|
495 |
||
1520
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
496 |
^ self getMilliseconds < aTime getMilliseconds |
699 | 497 |
|
1520
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
498 |
"Modified: 3.7.1996 / 13:10:17 / cg" |
699 | 499 |
! |
500 |
||
501 |
= aTime |
|
502 |
"return true if the argument, aTime represents the same time" |
|
503 |
||
504 |
(aTime species == self species) ifFalse:[^ false]. |
|
1520
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
505 |
^ (self getMilliseconds = aTime getMilliseconds) |
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
506 |
|
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
507 |
"Modified: 3.7.1996 / 13:10:24 / cg" |
699 | 508 |
! |
509 |
||
510 |
> aTime |
|
511 |
"return true if the argument, aTime is after the receiver" |
|
512 |
||
1501 | 513 |
^ self getMilliseconds > aTime getMilliseconds |
699 | 514 |
|
1501 | 515 |
"Modified: 1.7.1996 / 15:24:38 / cg" |
699 | 516 |
! |
517 |
||
518 |
hash |
|
519 |
"return an integer useful for hashing on times" |
|
520 |
||
1520
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
521 |
^ osTime // 1000 |
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
522 |
|
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
523 |
"Modified: 3.7.1996 / 13:10:52 / cg" |
699 | 524 |
! ! |
525 |
||
526 |
!AbsoluteTime methodsFor:'converting'! |
|
527 |
||
528 |
asAbsoluteTime |
|
529 |
"return an AbsoluteTime object from the receiver - thats the receiver." |
|
530 |
||
531 |
^ self |
|
532 |
! |
|
533 |
||
534 |
asDate |
|
535 |
"return a Date object from the receiver. |
|
536 |
The returned date will only represent the day - not the timeOfDay." |
|
537 |
||
538 |
^ Date fromOSTime:osTime |
|
539 |
||
540 |
" |
|
541 |
AbsoluteTime now |
|
542 |
AbsoluteTime now asDate |
|
543 |
(AbsoluteTime now addTime:3600) asDate |
|
544 |
(AbsoluteTime now addTime:3600) asTime |
|
545 |
AbsoluteTime fromSeconds:(AbsoluteTime now asSeconds + 3600) |
|
546 |
(AbsoluteTime fromSeconds:(AbsoluteTime now asSeconds + 3600)) asDate |
|
547 |
" |
|
548 |
||
549 |
! |
|
550 |
||
551 |
asSeconds |
|
552 |
"return the number of seconds elapsed since whatever time the |
|
553 |
OperatingSystem bases its time upon. Since this is totally |
|
554 |
OS-dependent, do not interpret the value returned by this method. |
|
555 |
You can use it to add/subtract seconds or get time deltas, though." |
|
556 |
||
557 |
^ self getSeconds |
|
558 |
||
559 |
" |
|
560 |
AbsoluteTime now asSeconds |
|
561 |
AbsoluteTime fromSeconds:(AbsoluteTime now asSeconds + 3600) |
|
562 |
Time hour:23 minutes:33 seconds:0 |
|
563 |
Time fromSeconds:((Time hour:23 minutes:33 seconds:0) asSeconds + 3600) |
|
564 |
" |
|
565 |
! |
|
566 |
||
567 |
asTime |
|
568 |
"return a Time object from the receiver. |
|
569 |
The returned time will only represent the timeOfDay - not the day." |
|
570 |
||
571 |
^ Time fromOSTime:osTime |
|
572 |
||
573 |
" |
|
574 |
AbsoluteTime now |
|
575 |
AbsoluteTime now asTime |
|
576 |
(AbsoluteTime now addTime:3600) asTime |
|
577 |
" |
|
578 |
! ! |
|
579 |
||
213 | 580 |
!AbsoluteTime methodsFor:'printing & storing'! |
30 | 581 |
|
241 | 582 |
printOn:aStream |
275 | 583 |
"append a user readable representation of the receiver to aStream. |
584 |
The format is compatible with readFromString:, but not with readFrom:." |
|
585 |
||
1501 | 586 |
|h min s mil d m y| |
30 | 587 |
|
275 | 588 |
OperatingSystem computeDatePartsOf:osTime for:[ |
1501 | 589 |
:year :month :day | d := day. m := month. y := year. |
241 | 590 |
]. |
275 | 591 |
OperatingSystem computeTimePartsOf:osTime for:[ |
1501 | 592 |
:hours :minutes :secs :millis | h := hours. min := minutes. s := secs. mil := millis |
241 | 593 |
]. |
594 |
d printOn:aStream. |
|
595 |
aStream nextPut:$-. |
|
596 |
m printOn:aStream. |
|
597 |
aStream nextPut:$-. |
|
598 |
y printOn:aStream. |
|
599 |
aStream space. |
|
600 |
h printOn:aStream leftPaddedTo:2 with:$0. |
|
601 |
aStream nextPut:$:. |
|
602 |
min printOn:aStream leftPaddedTo:2 with:$0. |
|
603 |
aStream nextPut:$:. |
|
604 |
s printOn:aStream leftPaddedTo:2 with:$0. |
|
1501 | 605 |
mil ~~ 0 ifTrue:[ |
606 |
aStream nextPut:$.. |
|
607 |
mil printOn:aStream leftPaddedTo:3 with:$0. |
|
608 |
]. |
|
92 | 609 |
|
610 |
" |
|
275 | 611 |
AbsoluteTime now printOn:Transcript. Transcript cr. |
612 |
(AbsoluteTime fromSeconds:0) printOn:Transcript. Transcript cr. |
|
613 |
Time now printOn:Transcript. Transcript cr. |
|
614 |
Date today printOn:Transcript. Transcript cr. |
|
1501 | 615 |
|
616 |
Time now asAbsoluteTime printOn:Transcript. Transcript cr. |
|
617 |
AbsoluteTime now printOn:Transcript. Transcript cr. |
|
618 |
||
619 |
Date today asAbsoluteTime printOn:Transcript. Transcript cr. |
|
620 |
Date today printOn:Transcript. Transcript cr. |
|
92 | 621 |
" |
1501 | 622 |
|
623 |
"Modified: 1.7.1996 / 15:20:59 / cg" |
|
30 | 624 |
! |
625 |
||
241 | 626 |
storeOn:aStream |
275 | 627 |
"store the receiver in a format suitable for reconstruction of the |
628 |
receiver via readFrom:" |
|
629 |
||
241 | 630 |
aStream nextPut:$(; |
242 | 631 |
nextPutAll:self class name; |
275 | 632 |
nextPutAll:' new setSeconds:'. |
633 |
self getSeconds storeOn:aStream. |
|
241 | 634 |
aStream nextPut:$). |
54 | 635 |
|
241 | 636 |
" |
275 | 637 |
AbsoluteTime now storeString |
30 | 638 |
|
275 | 639 |
AbsoluteTime readFrom:(AbsoluteTime now storeString) readStream |
241 | 640 |
" |
30 | 641 |
! ! |
699 | 642 |
|
643 |
!AbsoluteTime methodsFor:'private'! |
|
644 |
||
1501 | 645 |
fromOSTime:anUninterpretedOSTime |
699 | 646 |
"strictly private: set the seconds from an OS time (since whatever)" |
647 |
||
1501 | 648 |
osTime := anUninterpretedOSTime |
649 |
||
650 |
"Created: 1.7.1996 / 14:33:21 / cg" |
|
651 |
! |
|
652 |
||
653 |
getMilliseconds |
|
654 |
"strictly private: return the milliseconds (since whatever)" |
|
655 |
||
656 |
^ osTime |
|
657 |
||
658 |
"Created: 1.7.1996 / 14:33:56 / cg" |
|
699 | 659 |
! |
660 |
||
661 |
getSeconds |
|
662 |
"strictly private: return the seconds (since whatever)" |
|
663 |
||
1501 | 664 |
^ osTime // 1000 |
665 |
||
666 |
"Modified: 1.7.1996 / 14:33:44 / cg" |
|
699 | 667 |
! |
668 |
||
1501 | 669 |
setMilliseconds:millis |
670 |
"strictly private: set the milliseconds (since whatever)" |
|
671 |
||
672 |
osTime := millis. |
|
673 |
||
674 |
"Modified: 20.12.1995 / 11:46:36 / stefan" |
|
675 |
"Created: 1.7.1996 / 14:34:24 / cg" |
|
676 |
! |
|
677 |
||
699 | 678 |
setSeconds:secs |
679 |
"strictly private: set the seconds (since whatever)" |
|
680 |
||
1501 | 681 |
osTime := secs * 1000. |
795 | 682 |
|
683 |
"Modified: 20.12.1995 / 11:46:36 / stefan" |
|
1501 | 684 |
"Modified: 1.7.1996 / 14:34:10 / cg" |
699 | 685 |
! ! |
686 |
||
2311 | 687 |
!AbsoluteTime class methodsFor:'documentation'! |
699 | 688 |
|
689 |
version |
|
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
690 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/AbsoluteTime.st,v 1.32 1997-05-07 14:39:13 cg Exp $' |
699 | 691 |
! ! |