author | Claus Gittinger <cg@exept.de> |
Fri, 07 Jul 2000 16:13:34 +0200 | |
changeset 5449 | bf1de72fd2bb |
parent 5390 | 5a7c0581cfce |
child 5471 | a57eeb01c5ab |
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 |
||
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
13 |
"{ Package: 'stx:libbasic' }" |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
14 |
|
241 | 15 |
AbstractTime subclass:#AbsoluteTime |
795 | 16 |
instanceVariableNames:'osTime' |
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Magnitude-General' |
|
30 | 20 |
! |
21 |
||
2311 | 22 |
!AbsoluteTime class methodsFor:'documentation'! |
30 | 23 |
|
82 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
154 | 27 |
All Rights Reserved |
82 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
30 | 38 |
documentation |
39 |
" |
|
1669 | 40 |
This class represents absolute time values in milliSeconds starting some |
1501 | 41 |
time in the past. |
42 |
(typically, from 1st. Jan 1970, as used in the Unix operating system, |
|
43 |
but other systems may bias the time differently. |
|
44 |
Actually, the implementation does not depend or even know which time/date |
|
45 |
the OperatingSystem bases its time upon - it is simply keeping the value(s) |
|
46 |
as return from the OS. |
|
47 |
For conversion, these values are given back to the OS, which will know |
|
48 |
how to convert these times. |
|
49 |
This has the advantage, that time-stamps on files (such as last-access- |
|
50 |
time or last-modifiaction-time) can be handled transparent to other |
|
51 |
times - especially comparisons). |
|
241 | 52 |
|
1501 | 53 |
You should not interpret the osTime instance variable directly, instead |
54 |
(if at all), as the OS to convert. |
|
30 | 55 |
|
1501 | 56 |
Its implementation is not the same as in ST-80 |
1669 | 57 |
(which represents Time as seconds from 1. Jan 1901.) |
30 | 58 |
|
241 | 59 |
This class should not be confused with Time (which only represents the |
1501 | 60 |
time within one day). |
61 |
Time instances cannot be used to compare times across midnight; |
|
62 |
instances of AbsoluteTime can. |
|
241 | 63 |
|
3479 | 64 |
Notice: this class is aliased as Timestamp for ST-80 compatibility. |
65 |
||
1306 | 66 |
[author:] |
4679 | 67 |
Claus Gittinger |
1306 | 68 |
|
1282 | 69 |
[See also:] |
4679 | 70 |
Time Date |
71 |
Delay ProcessorScheduler |
|
30 | 72 |
" |
73 |
! ! |
|
74 |
||
2311 | 75 |
!AbsoluteTime class methodsFor:'instance creation'! |
30 | 76 |
|
4378 | 77 |
UTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis |
1501 | 78 |
"return an instance of the receiver, given individual components. |
79 |
See also `AbsoluteTime now' and other protocol inherited |
|
80 |
from my superclass." |
|
81 |
||
423 | 82 |
^ self basicNew |
4679 | 83 |
fromOSTime:(OperatingSystem |
84 |
computeOSTimeFromUTCYear:y month:m day:d |
|
85 |
hour:h minute:min second:s |
|
86 |
millisecond:millis) |
|
30 | 87 |
|
241 | 88 |
" |
4378 | 89 |
AbsoluteTime UTCYear:1970 month:1 day:1 hour:1 minute:0 second:0 millisecond:0 |
90 |
AbsoluteTime UTCYear:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:0 |
|
91 |
AbsoluteTime UTCYear:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100 |
|
92 |
AbsoluteTime UTCYear:1999 month:7 day:1 hour:1 minute:0 second:0 millisecond:0 |
|
93 |
AbsoluteTime UTCYear:2000 month:1 day:1 hour:1 minute:0 second:0 millisecond:0 |
|
241 | 94 |
" |
1228 | 95 |
|
4378 | 96 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
97 |
"Created: / 13.7.1999 / 12:34:37 / stefan" |
|
98 |
"Modified: / 13.7.1999 / 12:42:30 / stefan" |
|
99 |
! |
|
100 |
||
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
101 |
basicReadFrom:aStringOrStream |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
102 |
"return a new AbsoluteTime, reading a printed representation from aStream. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
103 |
The string is interpreted as 24 hour format, as printed. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
104 |
Notice, that this is not the storeString format and |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
105 |
is different from the format expected by readFrom:. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
106 |
The format read here is dd-mm-yyyy hh:mm:ss.iii. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
107 |
On error, raise an exception" |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
108 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
109 |
|str day month year hour min sec millis| |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
110 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
111 |
str := aStringOrStream readStream. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
112 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
113 |
day := Integer readFrom:str. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
114 |
(day between:1 and:31) ifFalse:[ Error raiseErrorString:'bad day' ]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
115 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
116 |
[str peek isDigit] whileFalse:[str next]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
117 |
month := Integer readFrom:str. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
118 |
(month between:1 and:12) ifFalse:[ Error raiseErrorString:'bad month' ]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
119 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
120 |
[str peek isDigit] whileFalse:[str next]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
121 |
year := Integer readFrom:str. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
122 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
123 |
[str peek isDigit] whileFalse:[str next]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
124 |
hour := Integer readFrom:str. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
125 |
(hour between:0 and:24) ifFalse:[ Error raiseErrorString:'bad hour' ]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
126 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
127 |
[str peek isDigit] whileFalse:[str next]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
128 |
min := Integer readFrom:str. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
129 |
(min between:0 and:59) ifFalse:[ Error raiseErrorString:'bad minute' ]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
130 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
131 |
str atEnd ifTrue:[ |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
132 |
sec := millis := 0. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
133 |
] ifFalse:[ |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
134 |
[str peek isDigit] whileFalse:[str next]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
135 |
sec := Integer readFrom:str. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
136 |
(sec between:0 and:59) ifFalse:[ Error raiseErrorString:'bad second' ]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
137 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
138 |
str peek = $. ifTrue:[ |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
139 |
str next. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
140 |
millis := Integer readFrom:str. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
141 |
millis >= 1000 ifTrue:[ Error raiseErrorString:'bad millisecond' ]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
142 |
] ifFalse:[ |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
143 |
millis := 0. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
144 |
]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
145 |
]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
146 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
147 |
"special check - only 24:00:00 is allowed; |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
148 |
every time after that must wrap" |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
149 |
hour == 24 ifTrue:[ |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
150 |
(min ~~ 0 or:[sec ~~ 0 or:[millis ~~ 0]]) ifTrue:[ Error raiseErrorString:'bad hour' ]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
151 |
]. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
152 |
^ self year:year month:month day:day hour:hour minute:min second:sec millisecond:millis. |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
153 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
154 |
" |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
155 |
AbsoluteTime basicReadFrom:'20-2-1995 13:11:06' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
156 |
AbsoluteTime basicReadFrom:'20-2-1995 13:11' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
157 |
AbsoluteTime basicReadFrom:'20-2-1995 13:11:06.100' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
158 |
AbsoluteTime basicReadFrom:'32-2-1995 13:11:06.100' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
159 |
AbsoluteTime basicReadFrom:'32-foo-1995 13:11:06.100' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
160 |
AbsoluteTime basicReadFrom:'20-13-1995 13:11:06.100' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
161 |
AbsoluteTime basicReadFrom:'20-12-1995 25:11:06.100' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
162 |
AbsoluteTime basicReadFrom:'20-12-1995 23:61:06.100' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
163 |
AbsoluteTime basicReadFrom:'20-12-1995 23:10:66.100' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
164 |
AbsoluteTime basicReadFrom:'20-12-1995 23:10:00.1000' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
165 |
AbsoluteTime basicReadFrom:'20-2-1995 24:01:00.100' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
166 |
AbsoluteTime basicReadFrom:'20-2-1995 24:00:01.100' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
167 |
AbsoluteTime basicReadFrom:'foo' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
168 |
AbsoluteTime basicReadFrom:(AbsoluteTime now storeString) |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
169 |
" |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
170 |
|
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
171 |
! |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
172 |
|
4378 | 173 |
day:d month:m year:y hour:h minutes:min seconds:s |
174 |
"This is obsolete. User #year:month:day:hour:minute:second:" |
|
175 |
||
176 |
^ self |
|
4679 | 177 |
year:y month:m day:d hour:h |
178 |
minute:min second:s millisecond:0 |
|
4378 | 179 |
|
180 |
" |
|
181 |
AbsoluteTime day:2 month:1 year:1991 hour:12 minute:30 second:0 |
|
182 |
AbsoluteTime day:8 month:1 year:1995 hour:0 minute:43 second:48 |
|
183 |
" |
|
184 |
||
185 |
"Modified: / 1.7.1996 / 15:22:26 / cg" |
|
186 |
"Modified: / 13.7.1999 / 12:29:56 / stefan" |
|
187 |
! |
|
188 |
||
189 |
day:d month:m year:y hour:h minutes:min seconds:s milliseconds:millis |
|
190 |
"This is obsolete. User #year:month:day:hour:minute:second:millisecond:" |
|
191 |
||
192 |
^ self year:y month:m day:d hour:h minute:min second:s millisecond:millis |
|
193 |
||
194 |
" |
|
195 |
AbsoluteTime day:1 month:1 year:1970 hour:1 minute:0 second:0 |
|
196 |
AbsoluteTime day:2 month:1 year:1991 hour:12 minute:30 second:0 |
|
197 |
AbsoluteTime day:2 month:1 year:1991 hour:12 minute:30 second:0 millisecond:100 |
|
198 |
" |
|
199 |
||
200 |
"Created: / 1.7.1996 / 14:46:09 / cg" |
|
201 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
|
202 |
"Modified: / 13.7.1999 / 12:30:26 / stefan" |
|
275 | 203 |
! |
204 |
||
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
205 |
decodeFromLiteralArray:anArray |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
206 |
"decode an AbsoluteTime literalArray. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
207 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
208 |
anArray may be: |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
209 |
#(AbsoluteTime '200004182000.123') |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
210 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
211 |
or the deprecated old format, that is not portable between different architectures. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
212 |
We parse this for backward compatibility (will be eventually removed). |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
213 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
214 |
#(AbsoluteTime #osTime: 12345678) |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
215 |
" |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
216 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
217 |
(anArray at:2) == #osTime: ifTrue:[ |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
218 |
^ self new osTime:(anArray at:3). |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
219 |
]. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
220 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
221 |
^ self readGeneralizedFrom:(anArray at:2) onError:[self error:'literal array decoding'] |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
222 |
! |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
223 |
|
423 | 224 |
fromDate:aDate andTime:aTime |
225 |
"return an instance of the receiver, initialized from a time and a date |
|
1228 | 226 |
object. |
227 |
See also `AbsoluteTime now' and other protocol inherited |
|
228 |
from my superclass." |
|
423 | 229 |
|
230 |
^ self |
|
4679 | 231 |
year:aDate year |
232 |
month:aDate month |
|
233 |
day:aDate day |
|
234 |
hour:aTime hours |
|
235 |
minute:aTime minutes |
|
236 |
second:aTime seconds |
|
423 | 237 |
|
238 |
" |
|
1228 | 239 |
AbsoluteTime fromDate:(Date today) andTime:(Time now) |
240 |
AbsoluteTime fromDate:(Date today plusDays:1) andTime:(Time now) |
|
241 |
AbsoluteTime now |
|
423 | 242 |
" |
243 |
||
4378 | 244 |
"Modified: / 8.9.1995 / 15:07:30 / claus" |
245 |
"Modified: / 19.4.1996 / 15:25:46 / cg" |
|
246 |
"Modified: / 13.7.1999 / 12:30:47 / stefan" |
|
423 | 247 |
! |
248 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
249 |
newDay:dayInYear year:year |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
250 |
"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
|
251 |
Date protocol compatibility" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
252 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
253 |
^ (Date newDay:dayInYear year:year) asAbsoluteTime |
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 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
256 |
AbsoluteTime newDay:183 year:1996 |
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 |
"Modified: 2.7.1996 / 09:39:30 / 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 |
|
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
262 |
readFrom:aStringOrStream onError:exceptionBlock |
275 | 263 |
"return a new AbsoluteTime, reading a printed representation from aStream. |
264 |
The string is interpreted as 24 hour format, as printed. |
|
265 |
Notice, that this is not the storeString format and |
|
4898 | 266 |
is different from the format expected by readFrom:. |
267 |
The format read here is dd-mm-yyyy hh:mm:ss.iii" |
|
275 | 268 |
|
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3510
diff
changeset
|
269 |
|newTime| |
275 | 270 |
|
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3510
diff
changeset
|
271 |
ErrorSignal handle:[:ex | |
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
272 |
^ super readFrom:aStringOrStream onError:exceptionBlock |
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3510
diff
changeset
|
273 |
] do:[ |
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
274 |
newTime := self basicReadFrom:aStringOrStream. |
275 | 275 |
]. |
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3510
diff
changeset
|
276 |
^ newTime |
275 | 277 |
|
278 |
" |
|
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
279 |
AbsoluteTime readFrom:'20-2-1995 13:11:06' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
280 |
AbsoluteTime readFrom:'20-2-1995 13:11' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
281 |
AbsoluteTime readFrom:'20-2-2001 13:11' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
282 |
AbsoluteTime readFrom:'20-2-1995 13:11:06.100' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
283 |
AbsoluteTime readFrom:'32-2-1995 13:11:06.100' onError:'wrong' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
284 |
AbsoluteTime readFrom:'32-foo-1995 13:11:06.100' onError:'wrong' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
285 |
AbsoluteTime readFrom:'20-2-1995 24:01:00.100' onError:'wrong' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
286 |
AbsoluteTime readFrom:'20-2-1995 24:00:01.100' onError:'wrong' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
287 |
AbsoluteTime readFrom:'foo' onError:'wrong' |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
288 |
AbsoluteTime readFrom:(AbsoluteTime now storeString) onError:'wrong' |
275 | 289 |
" |
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
290 |
|
4378 | 291 |
"Modified: / 8.10.1996 / 19:25:59 / cg" |
292 |
"Modified: / 13.7.1999 / 12:31:14 / stefan" |
|
2311 | 293 |
! |
294 |
||
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
295 |
readGeneralizedFrom:aStringOrStream onError:exceptionBlock |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
296 |
"return a new AbsoluteTime, reading a printed representation from aStream. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
297 |
The string is interpreted as 24 hour format, as printed. |
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
298 |
|
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
299 |
Notice, that this is not the storeString format and |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
300 |
is different from the format expected by readFrom:. |
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
301 |
The format read here is yyyymmddHHMMSS.iii+uuuu, |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
302 |
which is the ASN1 GeneralizedTime format." |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
303 |
|
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
304 |
|newTime| |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
305 |
|
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
306 |
ErrorSignal handle:[:ex | |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
307 |
^ exceptionBlock value |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
308 |
] do:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
309 |
|str day month year hour min sec millis c| |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
310 |
|
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
311 |
sec := millis := 0. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
312 |
str := aStringOrStream readStream. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
313 |
|
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
314 |
year := Integer readFrom:(str next:4). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
315 |
month := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
316 |
(month between:1 and:12) ifFalse:[^ exceptionBlock value]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
317 |
day := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
318 |
(day between:1 and:31) ifFalse:[^ exceptionBlock value]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
319 |
hour:= Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
320 |
(hour between:0 and:24) ifFalse:[^ exceptionBlock value]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
321 |
min:= Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
322 |
(min between:0 and:59) ifFalse:[^ exceptionBlock value]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
323 |
str atEnd ifFalse:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
324 |
sec := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
325 |
(sec between:0 and:59) ifFalse:[^ exceptionBlock value]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
326 |
str peek == $. ifTrue:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
327 |
str next. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
328 |
millis := Integer readFrom:str. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
329 |
]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
330 |
]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
331 |
str atEnd ifTrue:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
332 |
"/ this is local time |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
333 |
newTime := self year:year month:month day:day |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
334 |
hour:hour minute:min second:sec millisecond:millis. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
335 |
] ifFalse:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
336 |
c := str next. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
337 |
c ~~ $Z ifTrue:[ |tzh tzmin| |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
338 |
tzh := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
339 |
tzmin := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
340 |
c == $+ ifTrue:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
341 |
"/ subtract minutes and minutes |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
342 |
hour := hour - tzh. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
343 |
min := min - tzmin. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
344 |
] ifFalse:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
345 |
c ~~ $- ifTrue:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
346 |
self error:'bad time offset'. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
347 |
]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
348 |
"/ add minutes and minutes |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
349 |
hour := hour + tzh. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
350 |
min := min + tzmin. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
351 |
]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
352 |
]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
353 |
"/ this is UTC time |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
354 |
newTime := self UTCYear:year month:month day:day |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
355 |
hour:hour minute:min second:sec millisecond:millis. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
356 |
]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
357 |
]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
358 |
^ newTime |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
359 |
|
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
360 |
" |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
361 |
AbsoluteTime readGeneralizedFrom:'19950220131106' onError:[] |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
362 |
AbsoluteTime readGeneralizedFrom:'199502201311' onError:[] |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
363 |
AbsoluteTime readGeneralizedFrom:'19950220131106.100' onError:[] |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
364 |
AbsoluteTime readGeneralizedFrom:'19950232131106.100' onError:'wrong' |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
365 |
AbsoluteTime readGeneralizedFrom:'19950fo2131106.100' onError:'wrong' |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
366 |
AbsoluteTime readGeneralizedFrom:'foo' onError:'wrong' |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
367 |
" |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
368 |
|
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
369 |
"Modified: / 8.10.1996 / 19:25:59 / cg" |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
370 |
"Modified: / 13.7.1999 / 12:31:14 / stefan" |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
371 |
! |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
372 |
|
2311 | 373 |
secondsSince1970:sec |
374 |
"set time from elapsed seconds since 1-1-1970, 0:0:0. |
|
375 |
This is the format used in the UNIX world" |
|
376 |
||
4378 | 377 |
^ self year:1970 month:1 day:1 hour:0 minute:0 second:sec. |
378 |
||
379 |
" |
|
4679 | 380 |
AbsoluteTime secondsSince1970:0 |
381 |
AbsoluteTime secondsSince1970:3600 |
|
4378 | 382 |
" |
383 |
||
384 |
"Created: / 21.10.1996 / 17:48:30 / stefan" |
|
385 |
"Modified: / 13.7.1999 / 12:31:22 / stefan" |
|
386 |
! |
|
387 |
||
388 |
year:y month:m day:d hour:h minute:min second:s |
|
389 |
"return an instance of the receiver, given individual components. |
|
390 |
See also `AbsoluteTime now' and other protocol inherited |
|
391 |
from my superclass." |
|
392 |
||
393 |
^ self year:y month:m day:d hour:h minute:min second:s millisecond:0 |
|
2311 | 394 |
|
395 |
" |
|
4378 | 396 |
AbsoluteTime year:1970 month:1 day:1 hour:1 minute:0 second:0 |
397 |
AbsoluteTime year:1991 month:1 day:2 hour:12 minute:30 second:0 |
|
398 |
AbsoluteTime year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100 |
|
399 |
AbsoluteTime year:2000 month:1 day:1 hour:1 minutes:0 second:0 |
|
2311 | 400 |
" |
401 |
||
4378 | 402 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
403 |
"Created: / 13.7.1999 / 12:06:39 / stefan" |
|
404 |
"Modified: / 13.7.1999 / 12:27:47 / stefan" |
|
405 |
! |
|
406 |
||
407 |
year:y month:m day:d hour:h minute:min second:s millisecond:millis |
|
408 |
"return an instance of the receiver, given individual components. |
|
409 |
See also `AbsoluteTime now' and other protocol inherited |
|
410 |
from my superclass." |
|
411 |
||
412 |
^ self basicNew |
|
4679 | 413 |
fromOSTime:(OperatingSystem |
414 |
computeOSTimeFromYear:y month:m day:d |
|
415 |
hour:h minute:min seconds:s millis:millis) |
|
4378 | 416 |
|
417 |
" |
|
418 |
AbsoluteTime year:1970 month:1 day:1 hour:1 minute:0 seconds:0 |
|
419 |
AbsoluteTime year:1991 month:1 day:2 hour:12 minute:30 second:0 |
|
420 |
AbsoluteTime year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100 |
|
421 |
AbsoluteTime year:2000 month:1 day:1 hour:1 minute:0 second:0 |
|
422 |
" |
|
423 |
||
424 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
|
425 |
"Created: / 13.7.1999 / 12:28:44 / stefan" |
|
426 |
"Modified: / 13.7.1999 / 12:37:57 / stefan" |
|
241 | 427 |
! ! |
30 | 428 |
|
429 |
!AbsoluteTime methodsFor:'accessing'! |
|
430 |
||
431 |
day |
|
92 | 432 |
"return the day-in-month of the receiver (1..31). |
275 | 433 |
For compatibility, use instances of Date for this." |
30 | 434 |
|
241 | 435 |
|d| |
436 |
||
275 | 437 |
OperatingSystem computeDatePartsOf:osTime for:[:year :month :day | |
3120 | 438 |
d := day |
241 | 439 |
]. |
440 |
^ d |
|
54 | 441 |
|
92 | 442 |
" |
241 | 443 |
AbsoluteTime now day |
92 | 444 |
" |
1501 | 445 |
|
446 |
"Modified: 1.7.1996 / 15:23:02 / cg" |
|
447 |
! |
|
448 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
449 |
dayInWeek |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
450 |
"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
|
451 |
|
3120 | 452 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) at:11 |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
453 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
454 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
455 |
AbsoluteTime now dayInWeek |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
456 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
457 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
458 |
"Modified: 2.7.1996 / 09:20:32 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
459 |
"Created: 2.7.1996 / 09:35:48 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
460 |
! |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
461 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
462 |
dayInYear |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
463 |
"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
|
464 |
|
3120 | 465 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) at:10 |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
466 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
467 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
468 |
AbsoluteTime now dayInYear |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
469 |
AbsoluteTime newDay:184 year:1996 |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
470 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
471 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
472 |
"Modified: 2.7.1996 / 10:21:02 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
473 |
! |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
474 |
|
1501 | 475 |
hour |
476 |
"return the hour (0..23). |
|
477 |
ST-80 Timestamp compatibility (I'd prefer the name #hours, for Time compatibility)." |
|
478 |
||
479 |
^ self hours |
|
480 |
||
481 |
"Created: 1.7.1996 / 15:14:50 / cg" |
|
482 |
"Modified: 1.7.1996 / 15:15:32 / cg" |
|
30 | 483 |
! |
484 |
||
241 | 485 |
hours |
486 |
"return the hours (0..23)" |
|
487 |
||
488 |
|hr| |
|
489 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
490 |
OperatingSystem computeTimePartsOf:osTime for:[:hours :minutes :secs :millis | |
3120 | 491 |
hr := hours |
241 | 492 |
]. |
493 |
^ hr |
|
54 | 494 |
|
92 | 495 |
" |
241 | 496 |
AbsoluteTime now hours |
497 |
" |
|
498 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
499 |
"Modified: 2.7.1996 / 09:20:32 / cg" |
1501 | 500 |
! |
501 |
||
502 |
millisecond |
|
503 |
"return the millisecond (0..999). |
|
504 |
ST-80 Timestamp compatibility (I'd prefer the name #milliseconds)." |
|
505 |
||
506 |
^ self milliseconds |
|
507 |
||
508 |
"Created: 1.7.1996 / 15:14:50 / cg" |
|
509 |
"Modified: 1.7.1996 / 15:15:24 / cg" |
|
510 |
! |
|
511 |
||
512 |
milliseconds |
|
513 |
"return the milliseconds (0..999)" |
|
514 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
515 |
|m| |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
516 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
517 |
OperatingSystem computeTimePartsOf:osTime for:[:hours :minutes :secs :millis | |
3120 | 518 |
m := millis |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
519 |
]. |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
520 |
^ m |
1501 | 521 |
|
522 |
" |
|
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
523 |
AbsoluteTime now milliseconds |
1501 | 524 |
" |
525 |
||
526 |
"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
|
527 |
"Modified: 2.7.1996 / 09:21:41 / cg" |
1501 | 528 |
! |
529 |
||
530 |
minute |
|
531 |
"return the minute (0..59). |
|
532 |
ST-80 Timestamp compatibility (I'd prefer the name #minutes, for Time compatibility)." |
|
533 |
||
534 |
^ self minutes |
|
535 |
||
536 |
"Created: 1.7.1996 / 15:14:29 / cg" |
|
537 |
"Modified: 1.7.1996 / 15:15:37 / cg" |
|
241 | 538 |
! |
539 |
||
540 |
minutes |
|
541 |
"return the minutes (0..59)" |
|
542 |
||
543 |
|m| |
|
544 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
545 |
OperatingSystem computeTimePartsOf:osTime for:[:hours :minutes :secs :millis | |
3120 | 546 |
m := minutes |
241 | 547 |
]. |
548 |
^ m |
|
549 |
||
550 |
" |
|
551 |
AbsoluteTime now minutes |
|
92 | 552 |
" |
241 | 553 |
|
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
554 |
"Modified: 2.7.1996 / 09:20:49 / cg" |
241 | 555 |
! |
556 |
||
699 | 557 |
month |
558 |
"return the month of the receiver (1..12). |
|
559 |
For compatibility, use instances of Date for this." |
|
560 |
||
561 |
|m| |
|
562 |
||
563 |
OperatingSystem computeDatePartsOf:osTime for:[ :year :month :day | |
|
3120 | 564 |
m := month |
699 | 565 |
]. |
566 |
^ m |
|
567 |
||
568 |
" |
|
569 |
AbsoluteTime now month |
|
570 |
" |
|
1501 | 571 |
|
572 |
"Modified: 1.7.1996 / 15:23:05 / cg" |
|
573 |
! |
|
574 |
||
4807 | 575 |
osTime:aTime |
576 |
osTime := aTime. |
|
577 |
! |
|
578 |
||
1501 | 579 |
second |
580 |
"return the second (0..59). |
|
581 |
ST-80 Timestamp compatibility (I'd prefer the name #seconds, for Time compatibility)." |
|
582 |
||
583 |
^ self seconds |
|
584 |
||
585 |
"Created: 1.7.1996 / 15:14:19 / cg" |
|
586 |
"Modified: 1.7.1996 / 15:15:49 / cg" |
|
699 | 587 |
! |
588 |
||
241 | 589 |
seconds |
590 |
"return the seconds (0..59)" |
|
591 |
||
592 |
|s| |
|
593 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
594 |
OperatingSystem computeTimePartsOf:osTime for:[:hours :minutes :secs :millis | |
3120 | 595 |
s := secs |
241 | 596 |
]. |
597 |
^ s |
|
598 |
||
599 |
" |
|
600 |
AbsoluteTime now seconds |
|
601 |
" |
|
602 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
603 |
"Modified: 2.7.1996 / 09:20:54 / cg" |
92 | 604 |
! |
605 |
||
799 | 606 |
utcOffset |
607 |
"return the difference between UTC (Greenwich Mean Time) and the local time |
|
608 |
if daylight saving time applies to ourself, take that into account. |
|
609 |
Add utcOffset bevor converting to get UTC-Time resp. UTC-Date. |
|
610 |
" |
|
611 |
||
612 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) at:7 |
|
613 |
||
614 |
" |
|
615 |
AbsoluteTime now utcOffset |
|
616 |
(AbsoluteTime day:1 month:7 year:1995 hour:12 minutes:0 seconds:0) utcOffset |
|
617 |
" |
|
618 |
||
619 |
"Modified: 20.12.1995 / 17:28:49 / stefan" |
|
1501 | 620 |
"Modified: 1.7.1996 / 15:21:29 / cg" |
799 | 621 |
! |
622 |
||
699 | 623 |
year |
624 |
"return the year of the receiver i.e. 1992. |
|
625 |
For compatibility, use instances of Date for this." |
|
241 | 626 |
|
699 | 627 |
|y| |
241 | 628 |
|
699 | 629 |
OperatingSystem computeDatePartsOf:osTime for:[:year :month :day | |
3120 | 630 |
y := year |
699 | 631 |
]. |
632 |
^ y |
|
241 | 633 |
|
634 |
" |
|
699 | 635 |
AbsoluteTime now year |
241 | 636 |
" |
1501 | 637 |
|
638 |
"Modified: 1.7.1996 / 15:23:08 / cg" |
|
241 | 639 |
! ! |
640 |
||
30 | 641 |
!AbsoluteTime methodsFor:'arithmetic'! |
642 |
||
643 |
- aTime |
|
242 | 644 |
"return the delta in seconds between 2 times." |
30 | 645 |
|
646 |
^ self getSeconds - (aTime getSeconds) |
|
647 |
! |
|
648 |
||
242 | 649 |
addDays:numberOfDays |
650 |
"return a new instance of myself, numberOfDays afterwards." |
|
651 |
||
652 |
^ self addSeconds:(numberOfDays * (60 * 60 * 24)) |
|
653 |
||
654 |
" |
|
655 |
|t| |
|
656 |
||
657 |
t := AbsoluteTime now. |
|
658 |
t printNL. |
|
659 |
(t addDays:7) printNL |
|
660 |
" |
|
661 |
! |
|
662 |
||
3122 | 663 |
addMilliseconds:nMillis |
664 |
"return a new absoluteTime instance, nMillis milliseconds after myself" |
|
665 |
||
666 |
^ (self class basicNew) setMilliseconds:(self getMilliseconds + nMillis) |
|
667 |
||
668 |
" |
|
669 |
|t1 t2| |
|
670 |
||
671 |
t1 := AbsoluteTime now. |
|
672 |
t2 := t1 addMilliseconds:10. |
|
673 |
Transcript showCR:t1. |
|
674 |
Transcript showCR:t2. |
|
675 |
" |
|
676 |
||
677 |
"Modified: / 2.12.1997 / 17:10:39 / cg" |
|
678 |
! |
|
679 |
||
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
680 |
millisecondDeltaFrom:anAbsoluteTime |
3510 | 681 |
"return the delta in milliseconds between 2 absolute times. |
682 |
The argument is supposed to be AFTER the receiver" |
|
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
683 |
|
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
684 |
^ (self getSeconds - (anAbsoluteTime getSeconds)) * 1000 |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
685 |
+ self milliseconds - anAbsoluteTime milliseconds |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
686 |
|
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
687 |
" |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
688 |
|t1 t2| |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
689 |
|
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
690 |
t1 := AbsoluteTime now. |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
691 |
Delay waitForSeconds:0.5. |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
692 |
t2 := AbsoluteTime now. |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
693 |
t2 millisecondDeltaFrom:t1 |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
694 |
" |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
695 |
|
3510 | 696 |
"Modified: / 5.6.1998 / 04:21:33 / cg" |
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
697 |
! |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
698 |
|
242 | 699 |
subtractDays:numberOfDays |
700 |
"return a new instance of myself, numberOfDays before." |
|
701 |
||
702 |
^ self subtractSeconds:(numberOfDays * (60 * 60 * 24)) |
|
703 |
||
704 |
" |
|
705 |
|t| |
|
706 |
||
707 |
t := AbsoluteTime now. |
|
708 |
t printNL. |
|
709 |
(t subtractDays:50) printNL |
|
710 |
" |
|
30 | 711 |
! ! |
712 |
||
699 | 713 |
!AbsoluteTime methodsFor:'comparing'! |
714 |
||
715 |
< aTime |
|
5390 | 716 |
"return true if the receiver is before the argument" |
699 | 717 |
|
1520
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
718 |
^ self getMilliseconds < aTime getMilliseconds |
699 | 719 |
|
1520
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
720 |
"Modified: 3.7.1996 / 13:10:17 / cg" |
699 | 721 |
! |
722 |
||
723 |
= aTime |
|
724 |
"return true if the argument, aTime represents the same time" |
|
725 |
||
726 |
(aTime species == self species) ifFalse:[^ false]. |
|
1520
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
727 |
^ (self getMilliseconds = aTime getMilliseconds) |
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
728 |
|
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
729 |
"Modified: 3.7.1996 / 13:10:24 / cg" |
699 | 730 |
! |
731 |
||
732 |
> aTime |
|
5390 | 733 |
"return true if the receiver is after the argument" |
699 | 734 |
|
1501 | 735 |
^ self getMilliseconds > aTime getMilliseconds |
699 | 736 |
|
1501 | 737 |
"Modified: 1.7.1996 / 15:24:38 / cg" |
699 | 738 |
! |
739 |
||
740 |
hash |
|
741 |
"return an integer useful for hashing on times" |
|
742 |
||
1520
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
743 |
^ osTime // 1000 |
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
744 |
|
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
745 |
"Modified: 3.7.1996 / 13:10:52 / cg" |
699 | 746 |
! ! |
747 |
||
748 |
!AbsoluteTime methodsFor:'converting'! |
|
749 |
||
750 |
asAbsoluteTime |
|
751 |
"return an AbsoluteTime object from the receiver - thats the receiver." |
|
752 |
||
753 |
^ self |
|
754 |
! |
|
755 |
||
756 |
asDate |
|
757 |
"return a Date object from the receiver. |
|
758 |
The returned date will only represent the day - not the timeOfDay." |
|
759 |
||
760 |
^ Date fromOSTime:osTime |
|
761 |
||
762 |
" |
|
763 |
AbsoluteTime now |
|
764 |
AbsoluteTime now asDate |
|
765 |
(AbsoluteTime now addTime:3600) asDate |
|
766 |
(AbsoluteTime now addTime:3600) asTime |
|
767 |
AbsoluteTime fromSeconds:(AbsoluteTime now asSeconds + 3600) |
|
768 |
(AbsoluteTime fromSeconds:(AbsoluteTime now asSeconds + 3600)) asDate |
|
769 |
" |
|
770 |
||
771 |
! |
|
772 |
||
773 |
asSeconds |
|
774 |
"return the number of seconds elapsed since whatever time the |
|
775 |
OperatingSystem bases its time upon. Since this is totally |
|
776 |
OS-dependent, do not interpret the value returned by this method. |
|
777 |
You can use it to add/subtract seconds or get time deltas, though." |
|
778 |
||
779 |
^ self getSeconds |
|
780 |
||
781 |
" |
|
782 |
AbsoluteTime now asSeconds |
|
783 |
AbsoluteTime fromSeconds:(AbsoluteTime now asSeconds + 3600) |
|
784 |
Time hour:23 minutes:33 seconds:0 |
|
785 |
Time fromSeconds:((Time hour:23 minutes:33 seconds:0) asSeconds + 3600) |
|
786 |
" |
|
787 |
! |
|
788 |
||
789 |
asTime |
|
790 |
"return a Time object from the receiver. |
|
791 |
The returned time will only represent the timeOfDay - not the day." |
|
792 |
||
793 |
^ Time fromOSTime:osTime |
|
794 |
||
795 |
" |
|
796 |
AbsoluteTime now |
|
797 |
AbsoluteTime now asTime |
|
798 |
(AbsoluteTime now addTime:3600) asTime |
|
799 |
" |
|
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
800 |
! |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
801 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
802 |
literalArrayEncoding |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
803 |
"encode myself as an array, from which a copy of the receiver |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
804 |
can be reconstructed with #decodeAsLiteralArray. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
805 |
The encoding is: |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
806 |
(#AbsoluteTime YYYYMMDDhhmmss.iii) |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
807 |
" |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
808 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
809 |
|s| |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
810 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
811 |
s := '' writeStream. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
812 |
self printGeneralizedOn:s isLocal:true. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
813 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
814 |
^ Array |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
815 |
with:self class name asSymbol |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
816 |
with:s contents |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
817 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
818 |
" |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
819 |
AbsoluteTime now literalArrayEncoding |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
820 |
AbsoluteTime decodeFromLiteralArray:AbsoluteTime now literalArrayEncoding |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
821 |
" |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
822 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
823 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
824 |
|
699 | 825 |
! ! |
826 |
||
213 | 827 |
!AbsoluteTime methodsFor:'printing & storing'! |
30 | 828 |
|
4843 | 829 |
addPrintBindingsTo:dict |
4930
edb87412f76d
month vs. mon in formatString
Claus Gittinger <cg@exept.de>
parents:
4906
diff
changeset
|
830 |
|d m y s| |
4843 | 831 |
|
832 |
OperatingSystem computeDatePartsOf:osTime for:[ |
|
833 |
:year :month :day | d := day. m := month. y := year. |
|
834 |
]. |
|
835 |
super addPrintBindingsTo:dict. |
|
836 |
dict at:#day put:(d printString leftPaddedTo:2 with:$0). |
|
837 |
dict at:#dayInWeek put:(self dayInWeek). |
|
4930
edb87412f76d
month vs. mon in formatString
Claus Gittinger <cg@exept.de>
parents:
4906
diff
changeset
|
838 |
dict at:#month put:(s := m printString leftPaddedTo:2 with:$0). |
edb87412f76d
month vs. mon in formatString
Claus Gittinger <cg@exept.de>
parents:
4906
diff
changeset
|
839 |
dict at:#mon put:s. "/ for backward compatibility only |
4843 | 840 |
dict at:#year put:(y printString leftPaddedTo:4 with:$0). |
841 |
||
842 |
dict at:#Day put:d printString. |
|
4930
edb87412f76d
month vs. mon in formatString
Claus Gittinger <cg@exept.de>
parents:
4906
diff
changeset
|
843 |
dict at:#Month put:(s := m printString). |
edb87412f76d
month vs. mon in formatString
Claus Gittinger <cg@exept.de>
parents:
4906
diff
changeset
|
844 |
dict at:#Mon put:s. "/ for backward compatibility only |
4843 | 845 |
|
846 |
" |
|
4930
edb87412f76d
month vs. mon in formatString
Claus Gittinger <cg@exept.de>
parents:
4906
diff
changeset
|
847 |
AbsoluteTime now printOn:Transcript format:'%(day):%(month)'. Transcript cr. |
4843 | 848 |
AbsoluteTime now printOn:Transcript format:'%(dayInWeek)'. Transcript cr. |
4930
edb87412f76d
month vs. mon in formatString
Claus Gittinger <cg@exept.de>
parents:
4906
diff
changeset
|
849 |
AbsoluteTime now printOn:Transcript format:'%(Day)-%(month)-%(year) %h:%m:%s.%i'. Transcript cr. |
4843 | 850 |
AbsoluteTime now printOn:Transcript. Transcript cr |
851 |
" |
|
852 |
||
853 |
||
854 |
||
855 |
! |
|
856 |
||
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
857 |
printGeneralizedOn:aStream |
5290 | 858 |
"append a representation of the receiver to aStream in a general format, |
859 |
top-down, without separtors: 'yyyymmddHHMMSS.mmm+0100' |
|
860 |
This format is used for the ASN.1 GeneralizedTime as defined in X.208 Sec. 33, |
|
861 |
so read this before changing the output format." |
|
862 |
||
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
863 |
^ self printGeneralizedOn:aStream isLocal:false. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
864 |
! |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
865 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
866 |
printGeneralizedOn:aStream isLocal:isLocal |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
867 |
"append a representation of the receiver to aStream in a general format, |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
868 |
top-down, without separtors: 'yyyymmddHHMMSS.mmm+0100' |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
869 |
This format is used for the ASN.1 GeneralizedTime as defined in X.208 Sec. 33, |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
870 |
so read this before changing the output format. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
871 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
872 |
If isLocal is true, represent as local time, otherwise add UTC time offset." |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
873 |
|
5290 | 874 |
|t off| |
875 |
||
876 |
t := OperatingSystem computeTimeAndDateFrom:osTime. |
|
877 |
||
878 |
(t at:1) printOn:aStream leftPaddedTo:4 with:$0. |
|
879 |
(t at:2) printOn:aStream leftPaddedTo:2 with:$0. |
|
880 |
(t at:3) printOn:aStream leftPaddedTo:2 with:$0. |
|
881 |
(t at:4) printOn:aStream leftPaddedTo:2 with:$0. |
|
882 |
(t at:5) printOn:aStream leftPaddedTo:2 with:$0. |
|
883 |
(t at:6) printOn:aStream leftPaddedTo:2 with:$0. |
|
884 |
aStream nextPut:$.. |
|
885 |
(t at:9) printOn:aStream leftPaddedTo:3 with:$0. |
|
886 |
||
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
887 |
isLocal ifFalse:[ |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
888 |
"/ this should be printed as non-local-time |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
889 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
890 |
off := t at:7. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
891 |
off == 0 ifTrue:[ |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
892 |
aStream nextPut:$Z. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
893 |
] ifFalse:[ |min| |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
894 |
off < 0 ifTrue:[ |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
895 |
aStream nextPut:$+. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
896 |
off := off negated. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
897 |
] ifFalse:[ |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
898 |
aStream nextPut:$-. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
899 |
]. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
900 |
min := off // 60. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
901 |
min // 60 printOn:aStream leftPaddedTo:2 with:$0. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
902 |
min \\ 60 printOn:aStream leftPaddedTo:2 with:$0. |
5290 | 903 |
]. |
904 |
]. |
|
905 |
||
906 |
||
907 |
" |
|
5291 | 908 |
AbsoluteTime now printGeneralizedOn:Transcript. Transcript cr. |
909 |
(AbsoluteTime fromSeconds:0) printGeneralizedOn:Transcript. Transcript cr. |
|
5290 | 910 |
Time now printOn:Transcript. Transcript cr. |
911 |
Date today printOn:Transcript. Transcript cr. |
|
912 |
||
5291 | 913 |
Time now asAbsoluteTime printGeneralizedOn:Transcript. Transcript cr. |
914 |
AbsoluteTime now printGeneralizedOn:Transcript. Transcript cr. |
|
5290 | 915 |
|
5291 | 916 |
Date today asAbsoluteTime printGeneralizedOn:Transcript. Transcript cr. |
5290 | 917 |
Date today printOn:Transcript. Transcript cr. |
918 |
" |
|
919 |
||
920 |
"Modified: / 1.7.1996 / 15:20:59 / cg" |
|
921 |
"Modified: / 17.1.2000 / 15:53:02 / stefan" |
|
922 |
! |
|
923 |
||
241 | 924 |
printOn:aStream |
275 | 925 |
"append a user readable representation of the receiver to aStream. |
926 |
The format is compatible with readFromString:, but not with readFrom:." |
|
927 |
||
4843 | 928 |
self printOn:aStream format:'%(Day)-%(mon)-%(year) %h:%m:%s.%i' |
92 | 929 |
|
930 |
" |
|
275 | 931 |
AbsoluteTime now printOn:Transcript. Transcript cr. |
932 |
(AbsoluteTime fromSeconds:0) printOn:Transcript. Transcript cr. |
|
933 |
Time now printOn:Transcript. Transcript cr. |
|
934 |
Date today printOn:Transcript. Transcript cr. |
|
1501 | 935 |
|
936 |
Time now asAbsoluteTime printOn:Transcript. Transcript cr. |
|
937 |
AbsoluteTime now printOn:Transcript. Transcript cr. |
|
938 |
||
939 |
Date today asAbsoluteTime printOn:Transcript. Transcript cr. |
|
940 |
Date today printOn:Transcript. Transcript cr. |
|
92 | 941 |
" |
1501 | 942 |
|
943 |
"Modified: 1.7.1996 / 15:20:59 / cg" |
|
30 | 944 |
! |
945 |
||
241 | 946 |
storeOn:aStream |
275 | 947 |
"store the receiver in a format suitable for reconstruction of the |
948 |
receiver via readFrom:" |
|
949 |
||
241 | 950 |
aStream nextPut:$(; |
242 | 951 |
nextPutAll:self class name; |
275 | 952 |
nextPutAll:' new setSeconds:'. |
953 |
self getSeconds storeOn:aStream. |
|
241 | 954 |
aStream nextPut:$). |
54 | 955 |
|
241 | 956 |
" |
275 | 957 |
AbsoluteTime now storeString |
30 | 958 |
|
275 | 959 |
AbsoluteTime readFrom:(AbsoluteTime now storeString) readStream |
241 | 960 |
" |
30 | 961 |
! ! |
699 | 962 |
|
963 |
!AbsoluteTime methodsFor:'private'! |
|
964 |
||
1501 | 965 |
fromOSTime:anUninterpretedOSTime |
699 | 966 |
"strictly private: set the seconds from an OS time (since whatever)" |
967 |
||
1501 | 968 |
osTime := anUninterpretedOSTime |
969 |
||
970 |
"Created: 1.7.1996 / 14:33:21 / cg" |
|
971 |
! |
|
972 |
||
973 |
getMilliseconds |
|
974 |
"strictly private: return the milliseconds (since whatever)" |
|
975 |
||
976 |
^ osTime |
|
977 |
||
978 |
"Created: 1.7.1996 / 14:33:56 / cg" |
|
699 | 979 |
! |
980 |
||
981 |
getSeconds |
|
982 |
"strictly private: return the seconds (since whatever)" |
|
983 |
||
1501 | 984 |
^ osTime // 1000 |
985 |
||
986 |
"Modified: 1.7.1996 / 14:33:44 / cg" |
|
699 | 987 |
! |
988 |
||
1501 | 989 |
setMilliseconds:millis |
990 |
"strictly private: set the milliseconds (since whatever)" |
|
991 |
||
992 |
osTime := millis. |
|
993 |
||
994 |
"Modified: 20.12.1995 / 11:46:36 / stefan" |
|
995 |
"Created: 1.7.1996 / 14:34:24 / cg" |
|
996 |
! |
|
997 |
||
699 | 998 |
setSeconds:secs |
999 |
"strictly private: set the seconds (since whatever)" |
|
1000 |
||
1501 | 1001 |
osTime := secs * 1000. |
795 | 1002 |
|
1003 |
"Modified: 20.12.1995 / 11:46:36 / stefan" |
|
1501 | 1004 |
"Modified: 1.7.1996 / 14:34:10 / cg" |
699 | 1005 |
! ! |
1006 |
||
2311 | 1007 |
!AbsoluteTime class methodsFor:'documentation'! |
699 | 1008 |
|
1009 |
version |
|
5390 | 1010 |
^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.52 2000-05-19 09:03:53 cg Exp $' |
699 | 1011 |
! ! |