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