author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 19 Aug 2009 17:14:36 +0100 | |
branch | jv |
changeset 17728 | bbc5fa73dfab |
parent 17711 | 39faaaf888b4 |
child 17732 | a1892eeca6c0 |
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 |
" |
|
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
13 |
|
8246 | 14 |
AbstractTime subclass:#Timestamp |
795 | 15 |
instanceVariableNames:'osTime' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
8246 | 18 |
category:'Magnitude-Time' |
30 | 19 |
! |
20 |
||
8246 | 21 |
!Timestamp class methodsFor:'documentation'! |
30 | 22 |
|
82 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
154 | 26 |
All Rights Reserved |
82 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
30 | 37 |
documentation |
38 |
" |
|
8264
b14c26a88e96
Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents:
8254
diff
changeset
|
39 |
This class represents time values in milliSeconds starting some |
1501 | 40 |
time in the past. |
41 |
(typically, from 1st. Jan 1970, as used in the Unix operating system, |
|
42 |
but other systems may bias the time differently. |
|
43 |
Actually, the implementation does not depend or even know which time/date |
|
44 |
the OperatingSystem bases its time upon - it is simply keeping the value(s) |
|
7671 | 45 |
as returned from the OS. |
1501 | 46 |
For conversion, these values are given back to the OS, which will know |
7671 | 47 |
how to convert these times. This has the advantage, that timestamps on files |
48 |
(such as last-access-time or last-modification-time) can be handled transparently - |
|
49 |
especially when performing comparisons). |
|
241 | 50 |
|
1501 | 51 |
You should not interpret the osTime instance variable directly, instead |
7671 | 52 |
(if at all), ask the OS to convert. |
30 | 53 |
|
7671 | 54 |
The implementation of this class is not the same as in ST-80 |
55 |
(which represents the time as seconds from Jan 1., 1901). |
|
30 | 56 |
|
241 | 57 |
This class should not be confused with Time (which only represents the |
7671 | 58 |
time within one day). Time instances cannot be used to compare times across midnight; |
8246 | 59 |
instances of Timestamp can. |
241 | 60 |
|
8264
b14c26a88e96
Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents:
8254
diff
changeset
|
61 |
Notice: this class was once called AbsoluteTime. Einstein told us in 1905, that talking |
b14c26a88e96
Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents:
8254
diff
changeset
|
62 |
about a absolute time is not a good idea (at least in our universe). So the class |
b14c26a88e96
Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents:
8254
diff
changeset
|
63 |
has been renamed to Timestamp which makes us more compatible to other ST dialects (e.g. VW) |
b14c26a88e96
Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents:
8254
diff
changeset
|
64 |
AbsoluteTime is still kept as an alias for backward compatibility. |
3479 | 65 |
|
1306 | 66 |
[author:] |
7671 | 67 |
Claus Gittinger |
1306 | 68 |
|
1282 | 69 |
[See also:] |
7671 | 70 |
Time Date |
71 |
Delay ProcessorScheduler |
|
30 | 72 |
" |
73 |
! ! |
|
74 |
||
8246 | 75 |
!Timestamp class methodsFor:'initialization'! |
76 |
||
77 |
initialize |
|
78 |
||
79 |
AbsoluteTime := self. "backward compatibility" |
|
80 |
! ! |
|
81 |
||
82 |
!Timestamp class methodsFor:'instance creation'! |
|
30 | 83 |
|
4378 | 84 |
UTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis |
1501 | 85 |
"return an instance of the receiver, given individual components. |
8246 | 86 |
See also `Timestamp now' and other protocol inherited |
1501 | 87 |
from my superclass." |
88 |
||
423 | 89 |
^ self basicNew |
8246 | 90 |
fromOSTime:(OperatingSystem |
91 |
computeOSTimeFromUTCYear:y month:m day:d |
|
92 |
hour:h minute:min second:s |
|
93 |
millisecond:millis) |
|
30 | 94 |
|
241 | 95 |
" |
8246 | 96 |
Timestamp UTCYear:1970 month:1 day:1 hour:1 minute:0 second:0 millisecond:0 |
97 |
Timestamp UTCYear:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:0 |
|
98 |
Timestamp UTCYear:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100 |
|
99 |
Timestamp UTCYear:1999 month:7 day:1 hour:1 minute:0 second:0 millisecond:0 |
|
100 |
Timestamp UTCYear:2000 month:1 day:1 hour:1 minute:0 second:0 millisecond:0 |
|
241 | 101 |
" |
1228 | 102 |
|
4378 | 103 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
104 |
"Created: / 13.7.1999 / 12:34:37 / stefan" |
|
105 |
"Modified: / 13.7.1999 / 12:42:30 / stefan" |
|
106 |
! |
|
107 |
||
108 |
day:d month:m year:y hour:h minutes:min seconds:s |
|
109 |
"This is obsolete. User #year:month:day:hour:minute:second:" |
|
110 |
||
111 |
^ self |
|
8246 | 112 |
year:y month:m day:d hour:h |
113 |
minute:min second:s millisecond:0 |
|
4378 | 114 |
|
115 |
" |
|
8246 | 116 |
Timestamp day:2 month:1 year:1991 hour:12 minute:30 second:0 |
117 |
Timestamp day:8 month:1 year:1995 hour:0 minute:43 second:48 |
|
4378 | 118 |
" |
119 |
||
120 |
"Modified: / 1.7.1996 / 15:22:26 / cg" |
|
121 |
"Modified: / 13.7.1999 / 12:29:56 / stefan" |
|
122 |
! |
|
123 |
||
124 |
day:d month:m year:y hour:h minutes:min seconds:s milliseconds:millis |
|
125 |
"This is obsolete. User #year:month:day:hour:minute:second:millisecond:" |
|
126 |
||
127 |
^ self year:y month:m day:d hour:h minute:min second:s millisecond:millis |
|
128 |
||
129 |
" |
|
8246 | 130 |
Timestamp day:1 month:1 year:1970 hour:1 minute:0 second:0 |
131 |
Timestamp day:2 month:1 year:1991 hour:12 minute:30 second:0 |
|
132 |
Timestamp day:2 month:1 year:1991 hour:12 minute:30 second:0 millisecond:100 |
|
4378 | 133 |
" |
134 |
||
135 |
"Created: / 1.7.1996 / 14:46:09 / cg" |
|
136 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
|
137 |
"Modified: / 13.7.1999 / 12:30:26 / stefan" |
|
275 | 138 |
! |
139 |
||
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
140 |
decodeFromLiteralArray:anArray |
8246 | 141 |
"decode an Timestamp literalArray. |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
142 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
143 |
anArray may be: |
8246 | 144 |
#(Timestamp '200004182000.123') |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
145 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
146 |
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
|
147 |
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
|
148 |
|
8246 | 149 |
#(Timestamp #osTime: 12345678) |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
150 |
" |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
151 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
152 |
(anArray at:2) == #osTime: ifTrue:[ |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
153 |
^ self new osTime:(anArray at:3). |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
154 |
]. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
155 |
|
11126 | 156 |
^ self |
157 |
readGeneralizedFrom:(anArray at:2) |
|
158 |
onError:[ self conversionErrorSignal |
|
159 |
raiseErrorString:'literal array decoding' ] |
|
8797 | 160 |
|
161 |
" |
|
162 |
Timestamp |
|
163 |
decodeFromLiteralArray:#(Timestamp '20050323175226.014') |
|
164 |
" |
|
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
165 |
! |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
166 |
|
423 | 167 |
fromDate:aDate andTime:aTime |
168 |
"return an instance of the receiver, initialized from a time and a date |
|
1228 | 169 |
object. |
8246 | 170 |
See also `Timestamp now' and other protocol inherited |
1228 | 171 |
from my superclass." |
423 | 172 |
|
173 |
^ self |
|
8246 | 174 |
year:aDate year |
175 |
month:aDate month |
|
176 |
day:aDate day |
|
177 |
hour:aTime hours |
|
178 |
minute:aTime minutes |
|
179 |
second:aTime seconds |
|
423 | 180 |
|
181 |
" |
|
8246 | 182 |
Timestamp fromDate:(Date today) andTime:(Time now) |
183 |
Timestamp fromDate:(Date today plusDays:1) andTime:(Time now) |
|
184 |
Timestamp now |
|
423 | 185 |
" |
186 |
||
4378 | 187 |
"Modified: / 8.9.1995 / 15:07:30 / claus" |
188 |
"Modified: / 19.4.1996 / 15:25:46 / cg" |
|
189 |
"Modified: / 13.7.1999 / 12:30:47 / stefan" |
|
423 | 190 |
! |
191 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
192 |
newDay:dayInYear year:year |
8246 | 193 |
"return a new Timestamp, given the year and the day-in-year (starting at 1). |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
194 |
Date protocol compatibility" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
195 |
|
8246 | 196 |
^ (Date newDay:dayInYear year:year) asTimestamp |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
197 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
198 |
" |
8246 | 199 |
Timestamp newDay:183 year:1996 |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
200 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
201 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
202 |
"Modified: 2.7.1996 / 09:39:30 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
203 |
! |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
204 |
|
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
205 |
readFrom:aStringOrStream onError:exceptionBlock |
8246 | 206 |
"return a new Timestamp, reading a printed representation from aStream. |
275 | 207 |
The string is interpreted as 24 hour format, as printed. |
208 |
Notice, that this is not the storeString format and |
|
4898 | 209 |
is different from the format expected by readFrom:. |
210 |
The format read here is dd-mm-yyyy hh:mm:ss.iii" |
|
275 | 211 |
|
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
212 |
|stream newTime| |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
213 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
214 |
stream := aStringOrStream readStream. |
275 | 215 |
|
7092
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7058
diff
changeset
|
216 |
Error handle:[:ex | |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
217 |
newTime := super readFrom:stream onError:exceptionBlock |
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3510
diff
changeset
|
218 |
] do:[ |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
219 |
newTime := self basicReadFrom:stream. |
275 | 220 |
]. |
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3510
diff
changeset
|
221 |
^ newTime |
275 | 222 |
|
223 |
" |
|
8246 | 224 |
Timestamp readFrom:'20-2-1995 13:11:06' |
225 |
Timestamp readFrom:'20-2-1995 13:11' |
|
226 |
Timestamp readFrom:'20-2-2001 13:11' |
|
227 |
Timestamp readFrom:'20-2-1995 13:11:06.100' |
|
228 |
Timestamp readFrom:'32-2-1995 13:11:06.100' onError:'wrong' |
|
229 |
Timestamp readFrom:'32-foo-1995 13:11:06.100' onError:'wrong' |
|
230 |
Timestamp readFrom:'20-2-1995 24:01:00.100' onError:'wrong' |
|
231 |
Timestamp readFrom:'20-2-1995 24:00:01.100' onError:'wrong' |
|
232 |
Timestamp readFrom:'2002-08-02 24:00:01.100' onError:'wrong' |
|
233 |
Timestamp readFrom:'foo' onError:'wrong' |
|
234 |
Timestamp readFrom:(Timestamp now storeString) onError:'wrong' |
|
275 | 235 |
" |
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
236 |
|
4378 | 237 |
"Modified: / 8.10.1996 / 19:25:59 / cg" |
238 |
"Modified: / 13.7.1999 / 12:31:14 / stefan" |
|
2311 | 239 |
! |
240 |
||
9620 | 241 |
readGeneralizedFrom:aStringOrStream |
242 |
"return a new Timestamp, reading a printed representation from aStream. |
|
243 |
The string is interpreted as 24 hour format, as printed. |
|
244 |
||
245 |
Notice, that this is not the storeString format and |
|
246 |
is different from the format expected by readFrom:. |
|
247 |
The format read here is either |
|
248 |
yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format. |
|
249 |
or: |
|
250 |
yyyy-mm-dd HH:MM:SS.iii +uuuu. |
|
251 |
" |
|
11126 | 252 |
^ self |
253 |
readGeneralizedFrom:aStringOrStream |
|
254 |
onError:[self conversionErrorSignal |
|
255 |
raiseErrorString:'Timestamp format error' ]. |
|
9620 | 256 |
|
257 |
"Created: / 22-08-2006 / 16:05:55 / cg" |
|
258 |
! |
|
259 |
||
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
260 |
readGeneralizedFrom:aStringOrStream onError:exceptionBlock |
8246 | 261 |
"return a new Timestamp, reading a printed representation from aStream. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
262 |
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
|
263 |
|
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
264 |
Notice, that this is not the storeString format and |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
265 |
is different from the format expected by readFrom:. |
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
266 |
The format read here is either |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
267 |
yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format. |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
268 |
or: |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
269 |
yyyy-mm-dd HH:MM:SS.iii +uuuu. |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
270 |
" |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
271 |
|
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
272 |
|newTime| |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
273 |
|
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6047
diff
changeset
|
274 |
^ [ |
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
275 |
|str day month year hour min sec millis c tzDelta| |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
276 |
|
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
277 |
sec := millis := 0. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
278 |
str := aStringOrStream readStream. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
279 |
|
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
280 |
year := Integer readFrom:(str next:4). |
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
281 |
str peek == $- ifTrue:[ str next]. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
282 |
month := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
283 |
(month between:1 and:12) ifFalse:[^ exceptionBlock value]. |
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
284 |
str peek == $- ifTrue:[ str next]. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
285 |
day := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
286 |
(day between:1 and:31) ifFalse:[^ exceptionBlock value]. |
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
287 |
|
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
288 |
str skipSeparators. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
289 |
hour:= Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
290 |
(hour between:0 and:24) ifFalse:[^ exceptionBlock value]. |
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
291 |
str peek == $: ifTrue:[ str next]. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
292 |
min:= Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
293 |
(min between:0 and:59) ifFalse:[^ exceptionBlock value]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
294 |
str atEnd ifFalse:[ |
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
295 |
str peek == $: ifTrue:[ str next]. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
296 |
sec := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
297 |
(sec between:0 and:59) ifFalse:[^ exceptionBlock value]. |
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
298 |
str atEnd ifFalse:[ |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
299 |
str peek == $. ifTrue:[ |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
300 |
str next. |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
301 |
millis := Integer readFrom:str. |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
302 |
]. |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
303 |
str skipSeparators. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
304 |
]. |
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
305 |
]. |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
306 |
|
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
307 |
str atEnd ifTrue:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
308 |
"/ this is local time |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
309 |
newTime := self year:year month:month day:day |
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
310 |
hour:hour minute:min second:sec millisecond:millis. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
311 |
] ifFalse:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
312 |
c := str next. |
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
313 |
c ~~ $Z ifTrue:[ |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
314 |
|tzh tzmin| |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
315 |
tzh := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
316 |
tzmin := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
317 |
c == $+ ifTrue:[ |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
318 |
"the timezone is ahead of UTC or EAST from Greenwich: subtract hours and minutes" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
319 |
hour := hour - tzh. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
320 |
min := min - tzmin. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
321 |
] ifFalse:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
322 |
c ~~ $- ifTrue:[ |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
323 |
^ exceptionBlock value. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
324 |
]. |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
325 |
"the timezone is behind of UTC or WEST from Greenwich: add hours and minutes" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
326 |
hour := hour + tzh. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
327 |
min := min + tzmin. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
328 |
]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
329 |
]. |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
330 |
"this is UTC time" |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
331 |
newTime := self UTCYear:year month:month day:day |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
332 |
hour:hour minute:min second:sec millisecond:millis. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
333 |
]. |
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6047
diff
changeset
|
334 |
newTime |
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6047
diff
changeset
|
335 |
] on:Error do:exceptionBlock. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
336 |
|
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
337 |
" |
5656
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
338 |
|s| |
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
339 |
s := '' writeStream. |
8246 | 340 |
Timestamp now printGeneralizedOn:s. |
341 |
Timestamp readGeneralizedFrom:s contents onError:[] |
|
5656
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
342 |
|
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
343 |
Daylight saving time: |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
344 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
345 |
Timestamp readGeneralizedFrom:'20000718120000Z' onError:[] |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
346 |
Timestamp readGeneralizedFrom:'20000718120000+0200' onError:[] |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
347 |
Timestamp readGeneralizedFrom:'20000718120000+0300' onError:[] |
5656
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
348 |
|
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
349 |
No daylight saving time: |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
350 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
351 |
Timestamp readGeneralizedFrom:'20000202120000Z' onError:[] |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
352 |
Timestamp readGeneralizedFrom:'20000202120000+0100' onError:[] |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
353 |
Timestamp readGeneralizedFrom:'20000202120000+0200' onError:[] |
5656
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
354 |
|
8246 | 355 |
Timestamp readGeneralizedFrom:'19950220131106' onError:[] |
356 |
Timestamp readGeneralizedFrom:'199502201311' onError:[] |
|
357 |
Timestamp readGeneralizedFrom:'19950220131106.100' onError:[] |
|
358 |
Timestamp readGeneralizedFrom:'19950232131106.100' onError:'wrong' |
|
359 |
Timestamp readGeneralizedFrom:'19950fo2131106.100' onError:'wrong' |
|
360 |
Timestamp readGeneralizedFrom:'foo' onError:'wrong' |
|
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
361 |
|
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
362 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00' onError:[] |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
363 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100' onError:[] |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
364 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100 +0100' onError:[] |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
365 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 -0100' onError:[] |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
366 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 +0000' onError:[] |
5292
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 |
|
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
369 |
"Modified: / 13-07-1999 / 12:31:14 / stefan" |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
370 |
"Modified: / 22-08-2006 / 12:30:11 / cg" |
5292
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 |
|
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
373 |
readIso8601FormatFrom:aStringOrStream |
8246 | 374 |
"return a new Timestamp, reading an iso8601 UTC representation from aStream. |
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
375 |
Missing month/day values are replaced with 1; i.e. 1999T24:00 |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
376 |
is the same as 1999-01-01T24:00:00. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
377 |
Missing minute, second and ms values are replaced with 0; |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
378 |
i.e. 1999T12 is the same as 1999-01-01T12:00:00.000. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
379 |
Of course, a 24 hour clock is used. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
380 |
On error, raise an exception. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
381 |
Please use this format for all external representations - its the standard." |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
382 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
383 |
^ self |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
384 |
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:nil |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
385 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
386 |
" |
8246 | 387 |
Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06' |
388 |
Timestamp readIso8601FormatFrom:'1995-02T13:11:06' |
|
389 |
Timestamp readIso8601FormatFrom:'1995T13:11:06' |
|
390 |
Timestamp readIso8601FormatFrom:'1995T13:11' |
|
391 |
Timestamp readIso8601FormatFrom:'1995T13' |
|
392 |
Timestamp readIso8601FormatFrom:'1995' |
|
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
393 |
|
8246 | 394 |
Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06' |
395 |
Timestamp readIso8601FormatFrom:'1995-02-20 13:11' |
|
396 |
Timestamp readIso8601FormatFrom:'1995-02-20 13' |
|
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
397 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
398 |
24 is allowed with ISO, and is 00:00 of the next day: |
8246 | 399 |
Timestamp readIso8601FormatFrom:'1995-02-20 24:00:00' |
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
400 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
401 |
" |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
402 |
! |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
403 |
|
8432 | 404 |
readIso8601FormatFrom:aStringOrStream onError:exceptionValue |
405 |
"return a new Timestamp, reading an iso8601 UTC representation from aStream. |
|
406 |
Missing month/day values are replaced with 1; i.e. 1999T24:00 |
|
407 |
is the same as 1999-01-01T24:00:00. |
|
408 |
Missing minute, second and ms values are replaced with 0; |
|
409 |
i.e. 1999T12 is the same as 1999-01-01T12:00:00.000. |
|
410 |
Of course, a 24 hour clock is used. |
|
411 |
On error, raise an exception. |
|
412 |
Please use this format for all external representations - its the standard." |
|
413 |
||
414 |
^ self |
|
415 |
readIso8601FormatFrom:aStringOrStream |
|
416 |
yearAlreadyRead:nil |
|
417 |
onError:exceptionValue |
|
418 |
! |
|
419 |
||
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
420 |
readRFC1123FormatFrom:rfc1123String onError:exceptionBlock |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
421 |
|parts indexModifier utcOffsetString utcOffset day year time monthName month| |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
422 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
423 |
"/ All HTTP/1.0 date/time stamps must be represented in Universal Time (UT), |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
424 |
"/ also known as Greenwich Mean Time (GMT), without exception. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
425 |
"/ This is indicated in the first two formats by the inclusion of "GMT" as the three-letter abbreviation for time zone, |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
426 |
"/ and should be assumed when reading the asctime format. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
427 |
"/ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
428 |
"/ HTTP-date = rfc1123-date | rfc850-date | asctime-date |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
429 |
"/ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
430 |
"/ rfc1123-date = wkday "," SP date1 SP time SP "GMT" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
431 |
"/ rfc850-date = weekday "," SP date2 SP time SP "GMT" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
432 |
"/ asctime-date = wkday SP date3 SP time SP 4DIGIT |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
433 |
"/ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
434 |
"/ date1 = 2DIGIT SP month SP 4DIGIT |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
435 |
"/ ; day month year (e.g., 02 Jun 1982) |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
436 |
"/ date2 = 2DIGIT "-" month "-" 2DIGIT |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
437 |
"/ ; day-month-year (e.g., 02-Jun-82) |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
438 |
"/ date3 = month SP ( 2DIGIT | ( SP 1DIGIT )) |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
439 |
"/ ; month day (e.g., Jun 2) |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
440 |
"/ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
441 |
"/ time = 2DIGIT ":" 2DIGIT ":" 2DIGIT |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
442 |
"/ ; 00:00:00 - 23:59:59 |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
443 |
"/ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
444 |
"/ wkday = "Mon" | "Tue" | "Wed" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
445 |
"/ | "Thu" | "Fri" | "Sat" | "Sun" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
446 |
"/ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
447 |
"/ weekday = "Monday" | "Tuesday" | "Wednesday" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
448 |
"/ | "Thursday" | "Friday" | "Saturday" | "Sunday" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
449 |
"/ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
450 |
"/ month = "Jan" | "Feb" | "Mar" | "Apr" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
451 |
"/ | "May" | "Jun" | "Jul" | "Aug" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
452 |
"/ | "Sep" | "Oct" | "Nov" | "Dec" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
453 |
"/ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
454 |
"/ Mon, 17 Aug 2009 11:11:15 GMT |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
455 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
456 |
rfc1123String isEmptyOrNil ifTrue:[^ exceptionBlock value]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
457 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
458 |
parts := rfc1123String subStrings:Character space. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
459 |
parts size == 6 ifTrue:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
460 |
indexModifier := 0. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
461 |
] ifFalse:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
462 |
parts size == 5 ifTrue:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
463 |
indexModifier := -1. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
464 |
] ifFalse:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
465 |
^ exceptionBlock value |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
466 |
]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
467 |
]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
468 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
469 |
utcOffsetString := (parts at:6 + indexModifier). |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
470 |
(utcOffsetString = 'GMT' or:[utcOffsetString = 'UTC']) ifFalse:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
471 |
self assert:utcOffsetString size == 5. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
472 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
473 |
utcOffset := (utcOffsetString from:4 to:5) asString asNumber * 60. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
474 |
utcOffset := utcOffset + ((utcOffsetString from:2 to:3) asString asNumber * 60 * 60). |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
475 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
476 |
(utcOffsetString at:1) asSymbol == #- ifTrue:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
477 |
utcOffset := -1 * utcOffset. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
478 |
]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
479 |
]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
480 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
481 |
day := Integer readFrom:(parts at:2 + indexModifier) onError:[^ exceptionBlock]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
482 |
year := Integer readFrom:(parts at:4 + indexModifier) onError:[^ exceptionBlock]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
483 |
time := Time readFrom:(parts at:5 + indexModifier) onError:[^ exceptionBlock]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
484 |
monthName := parts at:3 + indexModifier. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
485 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
486 |
month := (1 to:12) asOrderedCollection detect:[:i | |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
487 |
(Date abbreviatedNameOfMonth:i language:#en) sameAs:monthName |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
488 |
] ifNone:[^ exceptionBlock]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
489 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
490 |
^ (Timestamp |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
491 |
fromDate:(Date newDay:day monthIndex:month year:year) |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
492 |
andTime:time) + utcOffset |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
493 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
494 |
|
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
495 |
secondsSince1970:sec |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
496 |
"set time from elapsed seconds since 1-1-1970, 0:0:0. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
497 |
This is the format used in the UNIX world" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
498 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
499 |
|divMod| |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
500 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
501 |
divMod := sec divMod:3600. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
502 |
^ self year:1970 month:1 day:1 hour:(divMod at:1) minute:0 second:(divMod at:2) millisecond:0. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
503 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
504 |
" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
505 |
Timestamp secondsSince1970:0 |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
506 |
Timestamp secondsSince1970:3600 |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
507 |
Timestamp secondsSince1970:3600*24 |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
508 |
" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
509 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
510 |
"Created: / 21.10.1996 / 17:48:30 / stefan" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
511 |
"Modified: / 13.7.1999 / 12:31:22 / stefan" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
512 |
! |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
513 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
514 |
year:y month:m day:d hour:h minute:min second:s |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
515 |
"return an instance of the receiver, given individual components. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
516 |
See also `Timestamp now' and other protocol inherited |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
517 |
from my superclass." |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
518 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
519 |
^ self year:y month:m day:d hour:h minute:min second:s millisecond:0 |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
520 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
521 |
" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
522 |
Timestamp year:1970 month:1 day:1 hour:1 minute:0 second:0 |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
523 |
Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
524 |
Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100 |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
525 |
Timestamp year:2000 month:1 day:1 hour:1 minutes:0 second:0 |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
526 |
" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
527 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
528 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
529 |
"Created: / 13.7.1999 / 12:06:39 / stefan" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
530 |
"Modified: / 13.7.1999 / 12:27:47 / stefan" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
531 |
! |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
532 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
533 |
year:y month:m day:d hour:h minute:min second:s millisecond:millis |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
534 |
"return an instance of the receiver, given individual components. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
535 |
See also `Timestamp now' and other protocol inherited |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
536 |
from my superclass." |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
537 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
538 |
^ self basicNew |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
539 |
fromOSTime:(OperatingSystem |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
540 |
computeOSTimeFromYear:y month:m day:d |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
541 |
hour:h minute:min seconds:s millis:millis) |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
542 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
543 |
" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
544 |
Timestamp year:1970 month:1 day:1 hour:0 minute:0 second:0 |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
545 |
Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
546 |
Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100 |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
547 |
Timestamp year:2000 month:1 day:1 hour:1 minute:0 second:0 |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
548 |
" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
549 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
550 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
551 |
"Created: / 13.7.1999 / 12:28:44 / stefan" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
552 |
"Modified: / 13.7.1999 / 12:37:57 / stefan" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
553 |
! ! |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
554 |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
555 |
!Timestamp class methodsFor:'Compatibility-Squeak'! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
556 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
557 |
current |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
558 |
^ self now |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
559 |
! ! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
560 |
|
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
561 |
!Timestamp class methodsFor:'private'! |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
562 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
563 |
basicReadFrom:aStream |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
564 |
"return a new Timestamp, reading a printed representation from aStream. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
565 |
The string is interpreted as 24 hour format, as printed. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
566 |
Notice, that this is not the storeString format and |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
567 |
is different from the format expected by readFrom:. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
568 |
KLUDGE: |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
569 |
us and non-us format have different ordering of day and month; |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
570 |
The format read here is (non-us) dd-mm-yyyy hh:mm:ss.iii |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
571 |
or (us-format, for Travis) mm/dd/yyyy hh:mm:ss.iii. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
572 |
On error, raise an exception" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
573 |
|
11140
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
574 |
|firstNumber secondNumber day month year hour min sec millis usFormat possibeMonthName| |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
575 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
576 |
firstNumber := Integer readFrom:aStream onError:[ConversionError raiseErrorString:' - integer expected']. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
577 |
firstNumber > 31 ifTrue:[ |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
578 |
"/ assume iso8601 format; |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
579 |
^ self readIso8601FormatFrom:aStream yearAlreadyRead:firstNumber. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
580 |
]. |
11140
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
581 |
aStream skipSeparators. |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
582 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
583 |
"/ consider this a kludge |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
584 |
usFormat := (aStream peek == $/ ). |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
585 |
|
11140
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
586 |
[aStream peek isLetterOrDigit] whileFalse:[aStream next]. |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
587 |
aStream peek isDigit ifTrue:[ |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
588 |
secondNumber := Integer readFrom:aStream onError:-1. |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
589 |
|
11140
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
590 |
usFormat ifTrue:[ |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
591 |
month := firstNumber. |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
592 |
day := secondNumber. |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
593 |
] ifFalse:[ |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
594 |
month := secondNumber. |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
595 |
day := firstNumber. |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
596 |
]. |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
597 |
|
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
598 |
] ifFalse:[ |
11140
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
599 |
possibeMonthName := aStream throughAnyForWhich:[:ch | ch isLetter]. |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
600 |
month := Date indexOfMonth:possibeMonthName asLowercase. |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
601 |
day := firstNumber. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
602 |
]. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
603 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
604 |
(day between:1 and:31) ifFalse:[ ConversionError raiseErrorString:' - bad day' ]. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
605 |
(month between:1 and:12) ifFalse:[ ConversionError raiseErrorString:' - bad month' ]. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
606 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
607 |
[aStream peek isDigit] whileFalse:[aStream next]. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
608 |
year := Integer readFrom:aStream onError:[ ConversionError raiseErrorString:' - bad year' ]. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
609 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
610 |
aStream atEnd ifTrue:[ |
11140
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
611 |
hour := min := sec := millis := 0. |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
612 |
] ifFalse:[ |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
613 |
[aStream peek isDigit] whileFalse:[aStream next]. |
11140
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
614 |
hour := Integer readFrom:aStream onError:-1. |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
615 |
(hour between:0 and:24) ifFalse:[ ConversionError raiseErrorString:' - bad hour' ]. |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
616 |
|
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
617 |
[aStream peek isDigit] whileFalse:[aStream next]. |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
618 |
min := Integer readFrom:aStream onError:-1. |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
619 |
(min between:0 and:59) ifFalse:[ ConversionError raiseErrorString:' - bad minute' ]. |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
620 |
|
11140
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
621 |
aStream atEnd ifTrue:[ |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
622 |
sec := millis := 0. |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
623 |
] ifFalse:[ |
11140
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
624 |
[aStream peek isDigit] whileFalse:[aStream next]. |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
625 |
sec := Integer readFrom:aStream onError:-1. |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
626 |
(sec between:0 and:59) ifFalse:[ ConversionError raiseErrorString:' - bad second' ]. |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
627 |
|
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
628 |
aStream peek = $. ifTrue:[ |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
629 |
aStream next. |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
630 |
millis := Integer readFrom:aStream onError:0. |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
631 |
millis >= 1000 ifTrue:[ ConversionError raiseErrorString:' - bad millisecond' ]. |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
632 |
] ifFalse:[ |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
633 |
millis := 0. |
130dd8b62622
be more tolerant, when reading
Claus Gittinger <cg@exept.de>
parents:
11126
diff
changeset
|
634 |
]. |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
635 |
]. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
636 |
]. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
637 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
638 |
"special check - only 24:00:00 is allowed; |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
639 |
every time after that must wrap" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
640 |
hour == 24 ifTrue:[ |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
641 |
(min ~~ 0 or:[sec ~~ 0 or:[millis ~~ 0]]) ifTrue:[ ConversionError raiseErrorString:' - bad hour' ]. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
642 |
]. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
643 |
^ self year:year month:month day:day hour:hour minute:min second:sec millisecond:millis. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
644 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
645 |
" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
646 |
Timestamp basicReadFrom:'20-2-1995 13:11:06' readStream |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
647 |
Timestamp basicReadFrom:'20-2-1995 13:11:06.' readStream |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
648 |
(Timestamp basicReadFrom:'10-9-1995 13:11:06' readStream) month |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
649 |
(Timestamp basicReadFrom:'10/9/1995 13:11:06' readStream) month |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
650 |
Timestamp basicReadFrom:'20-2-1995 13:11' readStream |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
651 |
Timestamp basicReadFrom:'20-2-1995 13:11:06.100' readStream |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
652 |
Timestamp basicReadFrom:'32-2-1995 13:11:06.100' readStream |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
653 |
Timestamp basicReadFrom:'32-foo-1995 13:11:06.100' readStream |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
654 |
Timestamp basicReadFrom:'20-13-1995 13:11:06.100' readStream |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
655 |
Timestamp basicReadFrom:'20-12-1995 25:11:06.100' readStream |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
656 |
Timestamp basicReadFrom:'20-12-1995 23:61:06.100' readStream |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
657 |
Timestamp basicReadFrom:'20-12-1995 23:10:66.100' readStream |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
658 |
Timestamp basicReadFrom:'20-12-1995 23:10:00.1000' readStream |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
659 |
Timestamp basicReadFrom:'20-2-1995 24:01:00.100' readStream |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
660 |
Timestamp basicReadFrom:'20-2-1995 24:00:01.100' readStream |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
661 |
Timestamp basicReadFrom:'foo' readStream |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
662 |
Timestamp basicReadFrom:(Timestamp now printString readStream) |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
663 |
Timestamp basicReadFrom:'1995-10-20 24:00:00.000' readStream |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
664 |
Timestamp basicReadFrom:'1995-10-20 12:10:00.000' readStream |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
665 |
" |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
666 |
! |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
667 |
|
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
668 |
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
669 |
"common helper for read methods. |
8246 | 670 |
Return a new Timestamp, reading an iso8601 UTC representation from aStream. |
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
671 |
Missing month/day values are replaced with 1; i.e. 1999T24:00 |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
672 |
is the same as 1999-01-01T24:00:00. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
673 |
Missing minute, second and ms values are replaced with 0; |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
674 |
i.e. 1999T12 is the same as 1999-01-01T12:00:00.000. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
675 |
Of course, a 24 hour clock is used. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
676 |
On error, raise an exception. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
677 |
Please use this format for all external representations - its the standard." |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
678 |
|
7008 | 679 |
|str day month year hour min sec millis fraction| |
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
680 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
681 |
str := aStringOrStream readStream. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
682 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
683 |
month := day := 1. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
684 |
hour := min := sec := millis := 0. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
685 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
686 |
yearOrNil notNil ifTrue:[ |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
687 |
year := yearOrNil |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
688 |
] ifFalse:[ |
8479 | 689 |
year := Integer readFrom:str onError:nil. |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
690 |
year isNil ifTrue:[ ConversionError raiseErrorString:' - bad year' ] |
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
691 |
]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
692 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
693 |
str skipSeparators. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
694 |
str peek == $- ifTrue:[ |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
695 |
str next. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
696 |
"/ month follows. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
697 |
month := Integer readFrom:str. |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
698 |
(month between:1 and:12) ifFalse:[ ConversionError raiseErrorString:' - bad month' ]. |
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
699 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
700 |
str skipSeparators. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
701 |
str peek == $- ifTrue:[ |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
702 |
str next. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
703 |
"/ day follows. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
704 |
day := Integer readFrom:str. |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
705 |
(day between:1 and:31) ifFalse:[ ConversionError raiseErrorString:' - bad day' ]. |
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
706 |
]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
707 |
]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
708 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
709 |
str skipSeparators. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
710 |
str atEnd ifFalse:[ |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
711 |
"time follows" |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
712 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
713 |
str peek == $T ifTrue:[ |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
714 |
"we treat the T as optional here" |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
715 |
str next. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
716 |
str skipSeparators. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
717 |
]. |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
718 |
hour := Integer readFrom:str onError:-1. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
719 |
(hour between:0 and:24) ifFalse:[ ConversionError raiseErrorString:' - bad hour' ]. |
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
720 |
str skipSeparators. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
721 |
str peek == $: ifTrue:[ |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
722 |
str next. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
723 |
"/ minutes follow. |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
724 |
min := Integer readFrom:str onError:-1. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
725 |
(min between:0 and:59) ifFalse:[ ConversionError raiseErrorString:' - bad minute' ]. |
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
726 |
str skipSeparators. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
727 |
str peek == $: ifTrue:[ |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
728 |
str next. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
729 |
"/ seconds follow. |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
730 |
sec := Integer readFrom:str onError:-1. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
731 |
(sec between:0 and:59) ifFalse:[ ConversionError raiseErrorString:' - bad seconds' ]. |
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
732 |
str skipSeparators. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
733 |
str peek == $. ifTrue:[ |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
734 |
str next. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
735 |
"/ millis follow. |
8479 | 736 |
fraction := Number readMantissaFrom:str radix:10. |
737 |
millis := (1000 * fraction) rounded. "/ mhmh - should it be truncated ? |
|
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
738 |
] |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
739 |
]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
740 |
]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
741 |
]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
742 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
743 |
"special check - only 24:00:00 is allowed; |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
744 |
every time after that must wrap" |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
745 |
hour == 24 ifTrue:[ |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
746 |
(min ~~ 0 or:[sec ~~ 0 or:[millis ~~ 0]]) ifTrue:[ ConversionError raiseErrorString:' - bad hour' ]. |
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
747 |
]. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
748 |
^ self |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
749 |
year:year month:month day:day |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
750 |
hour:hour minute:min second:sec millisecond:millis. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
751 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
752 |
" |
8479 | 753 |
Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06.123' |
8246 | 754 |
Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06' |
755 |
Timestamp readIso8601FormatFrom:'1995-02T13:11:06' |
|
756 |
Timestamp readIso8601FormatFrom:'1995T13:11:06' |
|
757 |
Timestamp readIso8601FormatFrom:'1995T13:11' |
|
758 |
Timestamp readIso8601FormatFrom:'1995T13' |
|
759 |
Timestamp readIso8601FormatFrom:'1995' |
|
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
760 |
|
8246 | 761 |
Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06' |
762 |
Timestamp readIso8601FormatFrom:'1995-02-20 13:11' |
|
763 |
Timestamp readIso8601FormatFrom:'1995-02-20 13' |
|
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
764 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
765 |
24 is allowed with ISO, and is 00:00 of the next day: |
8246 | 766 |
Timestamp readIso8601FormatFrom:'1995-02-20 24:00:00' |
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
767 |
" |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
768 |
! |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
769 |
|
8432 | 770 |
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil onError:exceptionValue |
771 |
"common helper for read methods. |
|
772 |
Return a new Timestamp, reading an iso8601 UTC representation from aStream. |
|
773 |
Missing month/day values are replaced with 1; i.e. 1999T24:00 |
|
774 |
is the same as 1999-01-01T24:00:00. |
|
775 |
Missing minute, second and ms values are replaced with 0; |
|
776 |
i.e. 1999T12 is the same as 1999-01-01T12:00:00.000. |
|
777 |
Of course, a 24 hour clock is used. |
|
778 |
On error, raise an exception. |
|
779 |
Please use this format for all external representations - its the standard." |
|
780 |
||
781 |
|retVal| |
|
782 |
||
783 |
ConversionError handle:[:ex | |
|
784 |
retVal := exceptionValue value |
|
785 |
] do:[ |
|
786 |
retVal := self readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil |
|
787 |
]. |
|
788 |
^ retVal |
|
241 | 789 |
! ! |
30 | 790 |
|
8246 | 791 |
!Timestamp methodsFor:'accessing'! |
30 | 792 |
|
793 |
day |
|
92 | 794 |
"return the day-in-month of the receiver (1..31). |
275 | 795 |
For compatibility, use instances of Date for this." |
30 | 796 |
|
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
797 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) day. |
54 | 798 |
|
92 | 799 |
" |
8246 | 800 |
Timestamp now day |
92 | 801 |
" |
1501 | 802 |
|
803 |
"Modified: 1.7.1996 / 15:23:02 / cg" |
|
804 |
! |
|
805 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
806 |
dayInWeek |
7327 | 807 |
"return the week-day of the receiver - 1 for monday, 7 for sunday |
808 |
WARNING: different from ANSIs dayOfWeek (which returns 1 for sunday, ... 7 for saturday). |
|
809 |
WARNING: does not care for pre-julian dates |
|
810 |
(i.e. do not use this for dates before 1752)" |
|
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
811 |
|
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
812 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) dayInWeek |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
813 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
814 |
" |
8246 | 815 |
Timestamp now dayInWeek |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
816 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
817 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
818 |
"Modified: 2.7.1996 / 09:20:32 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
819 |
"Created: 2.7.1996 / 09:35:48 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
820 |
! |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
821 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
822 |
dayInYear |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
823 |
"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
|
824 |
|
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
825 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) dayInYear |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
826 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
827 |
" |
8246 | 828 |
Timestamp now dayInYear |
829 |
Timestamp newDay:184 year:1996 |
|
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
830 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
831 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
832 |
"Modified: 2.7.1996 / 10:21:02 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
833 |
! |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
834 |
|
1501 | 835 |
hour |
836 |
"return the hour (0..23). |
|
837 |
ST-80 Timestamp compatibility (I'd prefer the name #hours, for Time compatibility)." |
|
838 |
||
839 |
^ self hours |
|
840 |
||
841 |
"Created: 1.7.1996 / 15:14:50 / cg" |
|
842 |
"Modified: 1.7.1996 / 15:15:32 / cg" |
|
30 | 843 |
! |
844 |
||
241 | 845 |
hours |
846 |
"return the hours (0..23)" |
|
847 |
||
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
848 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) hours |
54 | 849 |
|
92 | 850 |
" |
8246 | 851 |
Timestamp now hours |
241 | 852 |
" |
853 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
854 |
"Modified: 2.7.1996 / 09:20:32 / cg" |
1501 | 855 |
! |
856 |
||
857 |
millisecond |
|
858 |
"return the millisecond (0..999). |
|
859 |
ST-80 Timestamp compatibility (I'd prefer the name #milliseconds)." |
|
860 |
||
861 |
^ self milliseconds |
|
862 |
||
863 |
"Created: 1.7.1996 / 15:14:50 / cg" |
|
864 |
"Modified: 1.7.1996 / 15:15:24 / cg" |
|
865 |
! |
|
866 |
||
867 |
milliseconds |
|
868 |
"return the milliseconds (0..999)" |
|
869 |
||
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
870 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) milliseconds |
1501 | 871 |
|
872 |
" |
|
8246 | 873 |
Timestamp now milliseconds |
1501 | 874 |
" |
875 |
||
876 |
"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
|
877 |
"Modified: 2.7.1996 / 09:21:41 / cg" |
1501 | 878 |
! |
879 |
||
880 |
minute |
|
881 |
"return the minute (0..59). |
|
882 |
ST-80 Timestamp compatibility (I'd prefer the name #minutes, for Time compatibility)." |
|
883 |
||
884 |
^ self minutes |
|
885 |
||
886 |
"Created: 1.7.1996 / 15:14:29 / cg" |
|
887 |
"Modified: 1.7.1996 / 15:15:37 / cg" |
|
241 | 888 |
! |
889 |
||
890 |
minutes |
|
891 |
"return the minutes (0..59)" |
|
892 |
||
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
893 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) minutes |
241 | 894 |
|
895 |
" |
|
8246 | 896 |
Timestamp now minutes |
92 | 897 |
" |
241 | 898 |
|
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
899 |
"Modified: 2.7.1996 / 09:20:49 / cg" |
241 | 900 |
! |
901 |
||
699 | 902 |
month |
903 |
"return the month of the receiver (1..12). |
|
904 |
For compatibility, use instances of Date for this." |
|
905 |
||
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
906 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) month |
699 | 907 |
|
908 |
" |
|
8246 | 909 |
Timestamp now month |
699 | 910 |
" |
1501 | 911 |
|
912 |
"Modified: 1.7.1996 / 15:23:05 / cg" |
|
913 |
! |
|
914 |
||
8286 | 915 |
osTime |
916 |
"get the internal representation of the time. |
|
917 |
Warning: do not depend on the value (unix vs. win32 - differences)" |
|
918 |
||
919 |
^ osTime |
|
920 |
! |
|
921 |
||
4807 | 922 |
osTime:aTime |
5726 | 923 |
"set the internal representation of the time" |
924 |
||
4807 | 925 |
osTime := aTime. |
926 |
! |
|
927 |
||
1501 | 928 |
second |
929 |
"return the second (0..59). |
|
930 |
ST-80 Timestamp compatibility (I'd prefer the name #seconds, for Time compatibility)." |
|
931 |
||
932 |
^ self seconds |
|
933 |
||
934 |
"Created: 1.7.1996 / 15:14:19 / cg" |
|
935 |
"Modified: 1.7.1996 / 15:15:49 / cg" |
|
699 | 936 |
! |
937 |
||
241 | 938 |
seconds |
939 |
"return the seconds (0..59)" |
|
940 |
||
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
941 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) seconds |
241 | 942 |
|
943 |
" |
|
8246 | 944 |
Timestamp now seconds |
241 | 945 |
" |
946 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
947 |
"Modified: 2.7.1996 / 09:20:54 / cg" |
92 | 948 |
! |
949 |
||
7734 | 950 |
timeInfo |
951 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) |
|
952 |
! |
|
953 |
||
799 | 954 |
utcOffset |
8886 | 955 |
"return the difference between UTC (Greenwich Mean Time) and the local time in seconds. |
956 |
If daylight saving time applies to ourself, take that into account. |
|
8888
4171ed260947
Fix #utcSecondsSince1970 and #utcSecondsSince1901 (wrong direction of utcOffset)
Stefan Vogel <sv@exept.de>
parents:
8886
diff
changeset
|
957 |
|
8886 | 958 |
Add utcOffset to convert from local time to UTC time. |
8888
4171ed260947
Fix #utcSecondsSince1970 and #utcSecondsSince1901 (wrong direction of utcOffset)
Stefan Vogel <sv@exept.de>
parents:
8886
diff
changeset
|
959 |
Subtract utcOffset to convert from UTC time to local time. |
8886 | 960 |
|
961 |
If utcOffset is negative, the local timezone is east of Greenwich. |
|
962 |
If utcOffset is positive, the local timezone is west of Greenwich." |
|
799 | 963 |
|
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
964 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) utcOffset |
799 | 965 |
|
966 |
" |
|
8246 | 967 |
Timestamp now utcOffset |
968 |
(Timestamp day:1 month:7 year:1995 hour:12 minutes:0 seconds:0) utcOffset |
|
799 | 969 |
" |
970 |
||
971 |
"Modified: 20.12.1995 / 17:28:49 / stefan" |
|
1501 | 972 |
"Modified: 1.7.1996 / 15:21:29 / cg" |
799 | 973 |
! |
974 |
||
699 | 975 |
year |
976 |
"return the year of the receiver i.e. 1992. |
|
977 |
For compatibility, use instances of Date for this." |
|
241 | 978 |
|
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
979 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) year |
241 | 980 |
|
981 |
" |
|
8246 | 982 |
Timestamp now year |
241 | 983 |
" |
1501 | 984 |
|
985 |
"Modified: 1.7.1996 / 15:23:08 / cg" |
|
241 | 986 |
! ! |
987 |
||
8246 | 988 |
!Timestamp methodsFor:'arithmetic'! |
30 | 989 |
|
10736 | 990 |
deltaFrom:aTimestamp |
991 |
"return the delta as a timeDuration between 2 timeStamps. |
|
992 |
The argument is supposed to be BEFORE the receiver" |
|
993 |
||
994 |
^ TimeDuration fromMilliseconds:(self getMilliseconds - (aTimestamp getMilliseconds)) |
|
995 |
||
996 |
" |
|
997 |
|t1 t2| |
|
998 |
||
999 |
t1 := Timestamp now. |
|
1000 |
Delay waitForSeconds:0.5. |
|
1001 |
t2 := Timestamp now. |
|
1002 |
t2 deltaFrom:t1 |
|
1003 |
" |
|
1004 |
||
1005 |
"Created: / 04-10-2007 / 13:34:28 / cg" |
|
1006 |
! |
|
1007 |
||
8246 | 1008 |
millisecondDeltaFrom:aTimestamp |
3510 | 1009 |
"return the delta in milliseconds between 2 absolute times. |
9056 | 1010 |
The argument is supposed to be BEFORE the receiver" |
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1011 |
|
8246 | 1012 |
^ self getMilliseconds - (aTimestamp getMilliseconds) |
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1013 |
|
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1014 |
" |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1015 |
|t1 t2| |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1016 |
|
8246 | 1017 |
t1 := Timestamp now. |
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1018 |
Delay waitForSeconds:0.5. |
8246 | 1019 |
t2 := Timestamp now. |
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1020 |
t2 millisecondDeltaFrom:t1 |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1021 |
" |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1022 |
|
3510 | 1023 |
"Modified: / 5.6.1998 / 04:21:33 / cg" |
9056 | 1024 |
! |
1025 |
||
1026 |
secondDeltaFrom:aTimestamp |
|
1027 |
"return the delta in seconds between 2 absolute times. |
|
1028 |
The argument is supposed to be BEFORE the receiver" |
|
1029 |
||
1030 |
^ self getSeconds - (aTimestamp getSeconds) |
|
1031 |
||
1032 |
" |
|
1033 |
|t1 t2| |
|
1034 |
||
1035 |
t1 := Timestamp now. |
|
1036 |
Delay waitForSeconds:5. |
|
1037 |
t2 := Timestamp now. |
|
1038 |
t2 secondDeltaFrom:t1 |
|
1039 |
" |
|
1040 |
||
1041 |
"Modified: / 5.6.1998 / 04:21:33 / cg" |
|
30 | 1042 |
! ! |
1043 |
||
8246 | 1044 |
!Timestamp methodsFor:'comparing'! |
699 | 1045 |
|
1046 |
= aTime |
|
1047 |
"return true if the argument, aTime represents the same time" |
|
1048 |
||
1049 |
(aTime species == self species) ifFalse:[^ false]. |
|
1520
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
1050 |
^ (self getMilliseconds = aTime getMilliseconds) |
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
1051 |
|
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
1052 |
"Modified: 3.7.1996 / 13:10:24 / cg" |
699 | 1053 |
! |
1054 |
||
1055 |
hash |
|
1056 |
"return an integer useful for hashing on times" |
|
1057 |
||
1520
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
1058 |
^ osTime // 1000 |
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
1059 |
|
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
1060 |
"Modified: 3.7.1996 / 13:10:52 / cg" |
699 | 1061 |
! ! |
1062 |
||
8246 | 1063 |
!Timestamp methodsFor:'converting'! |
699 | 1064 |
|
1065 |
asAbsoluteTime |
|
8254
73b6109ab982
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8246
diff
changeset
|
1066 |
"deprecated, use #asTimestamp" |
8246 | 1067 |
|
1068 |
<resource:#obsolete> |
|
699 | 1069 |
|
9061 | 1070 |
self obsoleteMethodWarning:'use #asTimestamp'. |
699 | 1071 |
^ self |
1072 |
! |
|
1073 |
||
1074 |
asDate |
|
1075 |
"return a Date object from the receiver. |
|
1076 |
The returned date will only represent the day - not the timeOfDay." |
|
1077 |
||
1078 |
^ Date fromOSTime:osTime |
|
1079 |
||
1080 |
" |
|
8246 | 1081 |
Timestamp now |
1082 |
Timestamp now asDate |
|
1083 |
(Timestamp now addTime:3600) asDate |
|
1084 |
(Timestamp now addTime:3600) asTime |
|
1085 |
Timestamp fromSeconds:(Timestamp now asSeconds + 3600) |
|
1086 |
(Timestamp fromSeconds:(Timestamp now asSeconds + 3600)) asDate |
|
699 | 1087 |
" |
1088 |
! |
|
1089 |
||
11003 | 1090 |
asLocalTimestamp |
1091 |
"convert an utc timestamp to local time " |
|
1092 |
||
1093 |
^ self - self utcOffset |
|
1094 |
||
1095 |
" |
|
1096 |
Timestamp now asUtcTimestamp |
|
1097 |
Timestamp now asUtcTimestamp asLocalTimestamp |
|
1098 |
" |
|
1099 |
! |
|
1100 |
||
7466
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1101 |
asMilliseconds |
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1102 |
"return the number of milliSeconds elapsed since whatever time the |
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1103 |
OperatingSystem bases its time upon. Since this is totally |
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1104 |
OS-dependent, do not interpret the value returned by this method. |
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1105 |
You can use it to add/subtract milliSeconds or get time deltas, though." |
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1106 |
|
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1107 |
^ self getMilliseconds |
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1108 |
! |
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1109 |
|
699 | 1110 |
asSeconds |
1111 |
"return the number of seconds elapsed since whatever time the |
|
1112 |
OperatingSystem bases its time upon. Since this is totally |
|
1113 |
OS-dependent, do not interpret the value returned by this method. |
|
1114 |
You can use it to add/subtract seconds or get time deltas, though." |
|
1115 |
||
1116 |
^ self getSeconds |
|
1117 |
||
7004 | 1118 |
" |
8246 | 1119 |
Timestamp now asSeconds |
1120 |
Timestamp fromSeconds:(Timestamp now asSeconds + 3600) |
|
699 | 1121 |
Time hour:23 minutes:33 seconds:0 |
1122 |
Time fromSeconds:((Time hour:23 minutes:33 seconds:0) asSeconds + 3600) |
|
1123 |
" |
|
1124 |
! |
|
1125 |
||
1126 |
asTime |
|
1127 |
"return a Time object from the receiver. |
|
1128 |
The returned time will only represent the timeOfDay - not the day." |
|
1129 |
||
1130 |
^ Time fromOSTime:osTime |
|
1131 |
||
1132 |
" |
|
8246 | 1133 |
Timestamp now |
1134 |
Timestamp now asTime |
|
1135 |
(Timestamp now addTime:3600) asTime |
|
699 | 1136 |
" |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1137 |
! |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1138 |
|
8246 | 1139 |
asTimestamp |
1140 |
"return an Timestamp object from the receiver - thats the receiver." |
|
1141 |
||
1142 |
^ self |
|
1143 |
! |
|
1144 |
||
9402 | 1145 |
asUtcTimestamp |
1146 |
"convert a local time timestamp to UTC" |
|
1147 |
||
1148 |
^ self + self utcOffset |
|
1149 |
||
1150 |
" |
|
11003 | 1151 |
Timestamp now asUtcTimestamp |
9402 | 1152 |
" |
1153 |
! |
|
1154 |
||
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1155 |
literalArrayEncoding |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1156 |
"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
|
1157 |
can be reconstructed with #decodeAsLiteralArray. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1158 |
The encoding is: |
8246 | 1159 |
(#Timestamp YYYYMMDDhhmmss.iii) |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1160 |
" |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1161 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1162 |
|s| |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1163 |
|
8223
56da5d8f8bc1
replaced '' writeStream by String writeStream
Claus Gittinger <cg@exept.de>
parents:
8111
diff
changeset
|
1164 |
s := WriteStream on:(String new:18). |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1165 |
self printGeneralizedOn:s isLocal:true. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1166 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1167 |
^ Array |
9416 | 1168 |
with:self class name |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1169 |
with:s contents |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1170 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1171 |
" |
9416 | 1172 |
Timestamp now literalArrayEncoding |
1173 |
decodeAsLiteralArray |
|
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1174 |
" |
7006 | 1175 |
! |
1176 |
||
1177 |
utcSecondsSince1901 |
|
1178 |
"return the number of seconds elapsed since Jan, 1st 1901" |
|
1179 |
||
9430
919e0cb2257c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
9416
diff
changeset
|
1180 |
" |
919e0cb2257c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
9416
diff
changeset
|
1181 |
secondsBetween1901and1970 := |
919e0cb2257c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
9416
diff
changeset
|
1182 |
((Date day:1 month:1 year:1970) subtractDate:(Date day:1 month:1 year:1901)) |
919e0cb2257c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
9416
diff
changeset
|
1183 |
* (24 * 60 * 60) |
919e0cb2257c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
9416
diff
changeset
|
1184 |
" |
7006 | 1185 |
|
9449
6ba774be6aa1
stc can compile large integers!
Stefan Vogel <sv@exept.de>
parents:
9433
diff
changeset
|
1186 |
^ self utcSecondsSince1970 + 2177452800. |
7006 | 1187 |
|
1188 |
" |
|
8246 | 1189 |
Timestamp now utcSecondsSince1901 |
7006 | 1190 |
" |
699 | 1191 |
! ! |
1192 |
||
8246 | 1193 |
!Timestamp methodsFor:'printing & storing'! |
30 | 1194 |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7817
diff
changeset
|
1195 |
addPrintBindingsTo:dict language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7817
diff
changeset
|
1196 |
"private print support: add bindings for printing to aDictionary |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7817
diff
changeset
|
1197 |
languageOrNil can only be #en or nil for the current language." |
5726 | 1198 |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7817
diff
changeset
|
1199 |
self asDate addPrintBindingsTo:dict language:languageOrNil. |
6795
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6686
diff
changeset
|
1200 |
|
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6686
diff
changeset
|
1201 |
self year == Date today year ifTrue:[ |
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6686
diff
changeset
|
1202 |
dict at:#yearOrTime put:(self asTime printStringFormat:'%h:%m'). |
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6686
diff
changeset
|
1203 |
]. |
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6686
diff
changeset
|
1204 |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7817
diff
changeset
|
1205 |
super addPrintBindingsTo:dict language:languageOrNil. |
4843 | 1206 |
! |
1207 |
||
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1208 |
printGeneralizedOn:aStream |
5290 | 1209 |
"append a representation of the receiver to aStream in a general format, |
9385 | 1210 |
top-down, without separators: 'yyyymmddHHMMSS.mmm+0100' |
5290 | 1211 |
This format is used for the ASN.1 GeneralizedTime as defined in X.208 Sec. 33, |
1212 |
so read this before changing the output format." |
|
1213 |
||
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1214 |
^ self printGeneralizedOn:aStream isLocal:false. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1215 |
! |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1216 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1217 |
printGeneralizedOn:aStream isLocal:isLocal |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1218 |
"append a representation of the receiver to aStream in a general format, |
11177 | 1219 |
top-down, without separators: 'yyyymmddHHMMSS.mmm+0100' |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1220 |
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
|
1221 |
so read this before changing the output format. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1222 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1223 |
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
|
1224 |
|
5290 | 1225 |
|t off| |
1226 |
||
1227 |
t := OperatingSystem computeTimeAndDateFrom:osTime. |
|
1228 |
||
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
1229 |
t year printOn:aStream leftPaddedTo:4 with:$0. |
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
1230 |
t month printOn:aStream leftPaddedTo:2 with:$0. |
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
1231 |
t day printOn:aStream leftPaddedTo:2 with:$0. |
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
1232 |
t hours printOn:aStream leftPaddedTo:2 with:$0. |
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
1233 |
t minutes printOn:aStream leftPaddedTo:2 with:$0. |
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
1234 |
t seconds printOn:aStream leftPaddedTo:2 with:$0. |
5290 | 1235 |
aStream nextPut:$.. |
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
1236 |
t milliseconds printOn:aStream leftPaddedTo:3 with:$0. |
5290 | 1237 |
|
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1238 |
isLocal ifFalse:[ |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1239 |
"/ this should be printed as non-local-time |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1240 |
|
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
1241 |
off := t utcOffset. |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1242 |
off == 0 ifTrue:[ |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1243 |
aStream nextPut:$Z. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1244 |
] ifFalse:[ |min| |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1245 |
off < 0 ifTrue:[ |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1246 |
aStream nextPut:$+. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1247 |
off := off negated. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1248 |
] ifFalse:[ |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1249 |
aStream nextPut:$-. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1250 |
]. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1251 |
min := off // 60. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1252 |
min // 60 printOn:aStream leftPaddedTo:2 with:$0. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1253 |
min \\ 60 printOn:aStream leftPaddedTo:2 with:$0. |
5290 | 1254 |
]. |
1255 |
]. |
|
1256 |
||
1257 |
" |
|
8246 | 1258 |
Timestamp now printGeneralizedOn:Transcript. Transcript cr. |
1259 |
(Timestamp fromSeconds:0) printGeneralizedOn:Transcript. Transcript cr. |
|
5290 | 1260 |
Time now printOn:Transcript. Transcript cr. |
1261 |
Date today printOn:Transcript. Transcript cr. |
|
1262 |
||
8246 | 1263 |
Time now asTimestamp printGeneralizedOn:Transcript. Transcript cr. |
1264 |
Timestamp now printGeneralizedOn:Transcript. Transcript cr. |
|
5290 | 1265 |
|
8246 | 1266 |
Date today asTimestamp printGeneralizedOn:Transcript. Transcript cr. |
5290 | 1267 |
Date today printOn:Transcript. Transcript cr. |
1268 |
" |
|
1269 |
||
1270 |
"Modified: / 1.7.1996 / 15:20:59 / cg" |
|
1271 |
"Modified: / 17.1.2000 / 15:53:02 / stefan" |
|
1272 |
! |
|
1273 |
||
8479 | 1274 |
printIso8601FormatOn:aStream |
1275 |
"append the iso8601 UTC representation of the receiver to aStream. |
|
1276 |
This format looks like: |
|
1277 |
1999-01-01T24:00:00 |
|
1278 |
or, for zero hr:min:sec, |
|
1279 |
1999-01-01 |
|
1280 |
Of course, a 24 hour clock is used." |
|
1281 |
||
1282 |
|format| |
|
1283 |
||
1284 |
format := '%(year)-%(month)-%(day)T%h:%m:%s.%i'. |
|
1285 |
self milliseconds = 0 ifTrue:[ |
|
1286 |
format := '%(year)-%(month)-%(day)T%h:%m:%s'. |
|
1287 |
self seconds = 0 ifTrue:[ |
|
1288 |
format := '%(year)-%(month)-%(day)T%h:%m'. |
|
1289 |
((self hours = 0) and:[self minutes = 0]) ifTrue:[ |
|
1290 |
format := '%(year)-%(month)-%(day)'. |
|
1291 |
] |
|
1292 |
] |
|
1293 |
]. |
|
1294 |
self printOn:aStream format:format |
|
1295 |
||
1296 |
" |
|
1297 |
Timestamp now printIso8601FormatOn:Transcript |
|
1298 |
Timestamp readIso8601FormatFrom:(Timestamp now printStringIso8601Format). |
|
1299 |
" |
|
1300 |
! |
|
1301 |
||
241 | 1302 |
printOn:aStream |
275 | 1303 |
"append a user readable representation of the receiver to aStream. |
1304 |
The format is compatible with readFromString:, but not with readFrom:." |
|
1305 |
||
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
1306 |
"/ now, use ISO format... |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
1307 |
self printOn:aStream format:'%(year)-%(mon)-%(day) %h:%m:%s.%i' |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
1308 |
"/ self printOn:aStream format:'%(Day)-%(mon)-%(year) %h:%m:%s.%i' |
5678 | 1309 |
"/ self printOn:aStream format:'%(mon)/%(Day)/%(year) %h:%m:%s.%i' |
92 | 1310 |
|
1311 |
" |
|
8246 | 1312 |
Timestamp now printOn:Transcript. Transcript cr. |
1313 |
(Timestamp fromSeconds:0) printOn:Transcript. Transcript cr. |
|
275 | 1314 |
Time now printOn:Transcript. Transcript cr. |
1315 |
Date today printOn:Transcript. Transcript cr. |
|
1501 | 1316 |
|
8246 | 1317 |
Time now asTimestamp printOn:Transcript. Transcript cr. |
1318 |
Timestamp now printOn:Transcript. Transcript cr. |
|
1501 | 1319 |
|
8246 | 1320 |
Date today asTimestamp printOn:Transcript. Transcript cr. |
1501 | 1321 |
Date today printOn:Transcript. Transcript cr. |
92 | 1322 |
" |
1501 | 1323 |
|
5719
cf09067dbd1d
can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents:
5678
diff
changeset
|
1324 |
"Modified: 1.7.1996 / 15:20:59 / cg" |
cf09067dbd1d
can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents:
5678
diff
changeset
|
1325 |
! |
30 | 1326 |
|
7474 | 1327 |
printRFC1123FormatOn:aStream |
1328 |
"append the RFC1123 representation of the receiver to aStream. |
|
1329 |
This format is used in HTTP requests and looks like: |
|
7671 | 1330 |
'Fri, 04 Jul 2003 15:56:11 GMT' |
1331 |
(always GMT and all names in english)" |
|
1332 |
||
1333 |
"/ HTTP-date = rfc1123-date | rfc850-date | asctime-date |
|
1334 |
"/ |
|
1335 |
"/ rfc1123-date = wkday "," SP date1 SP time SP "GMT" |
|
1336 |
"/ rfc850-date = weekday "," SP date2 SP time SP "GMT" |
|
1337 |
"/ asctime-date = wkday SP date3 SP time SP 4DIGIT |
|
1338 |
"/ |
|
1339 |
"/ date1 = 2DIGIT SP month SP 4DIGIT |
|
1340 |
"/ ; day month year (e.g., 02 Jun 1982) |
|
1341 |
"/ date2 = 2DIGIT "-" month "-" 2DIGIT |
|
1342 |
"/ ; day-month-year (e.g., 02-Jun-82) |
|
1343 |
"/ date3 = month SP ( 2DIGIT | ( SP 1DIGIT )) |
|
1344 |
"/ ; month day (e.g., Jun 2) |
|
1345 |
"/ |
|
1346 |
"/ time = 2DIGIT ":" 2DIGIT ":" 2DIGIT |
|
1347 |
"/ ; 00:00:00 - 23:59:59 |
|
1348 |
"/ |
|
1349 |
"/ wkday = "Mon" | "Tue" | "Wed" |
|
1350 |
"/ | "Thu" | "Fri" | "Sat" | "Sun" |
|
1351 |
"/ |
|
1352 |
"/ weekday = "Monday" | "Tuesday" | "Wednesday" |
|
1353 |
"/ | "Thursday" | "Friday" | "Saturday" | "Sunday" |
|
1354 |
"/ |
|
1355 |
"/ month = "Jan" | "Feb" | "Mar" | "Apr" |
|
1356 |
"/ | "May" | "Jun" | "Jul" | "Aug" |
|
1357 |
"/ | "Sep" | "Oct" | "Nov" | "Dec" |
|
7474 | 1358 |
|
7734 | 1359 |
|meUTC timeInfo| |
7474 | 1360 |
|
8246 | 1361 |
meUTC := self class fromSeconds:((self asSeconds) + (self utcOffset)). |
7734 | 1362 |
timeInfo := meUTC timeInfo. |
7474 | 1363 |
|
7734 | 1364 |
aStream nextPutAll:(#('Mon' 'Tue' 'Wed' 'Thu' 'Fri' 'Sat' 'Sun') at:timeInfo dayInWeek); |
7671 | 1365 |
nextPutAll:', '. |
7734 | 1366 |
timeInfo day printOn:aStream leftPaddedTo:2 with:$0. |
7671 | 1367 |
aStream space. |
7734 | 1368 |
aStream nextPutAll:(#('Jan' 'Feb' 'Mar' 'Apr' 'May' 'Jun' 'Jul' 'Aug' 'Sep' 'Oct' 'Nov' 'Dec') at:timeInfo month). |
7671 | 1369 |
|
1370 |
"/ The following line is wrong, because the names are printed in the current locale!! |
|
7734 | 1371 |
"/ timeInfo printOn:aStream format:'%(ShortDayName), %(day) %(ShortMonthName) %y %h:%m:%s GMT'. |
7474 | 1372 |
|
7677 | 1373 |
"/ the following is too slow for heavy use |
7734 | 1374 |
"/ timeInfo printOn:aStream format:' %y %h:%m:%s GMT'. |
7677 | 1375 |
|
1376 |
aStream nextPut:Character space. |
|
7734 | 1377 |
timeInfo year printOn:aStream. |
7677 | 1378 |
aStream nextPut:Character space. |
7734 | 1379 |
timeInfo hours printOn:aStream leftPaddedTo:2 with:$0. |
7677 | 1380 |
aStream nextPut:$:. |
7734 | 1381 |
timeInfo minutes printOn:aStream leftPaddedTo:2 with:$0. |
7677 | 1382 |
aStream nextPut:$:. |
7734 | 1383 |
timeInfo seconds printOn:aStream leftPaddedTo:2 with:$0. |
7677 | 1384 |
aStream nextPutAll:' GMT'. |
1385 |
||
7474 | 1386 |
" |
8414 | 1387 |
Timestamp now printRFC1123FormatOn:Transcript |
7474 | 1388 |
" |
1389 |
! |
|
1390 |
||
8479 | 1391 |
printStringIso8601Format |
1392 |
"return the Iso8601 representation of the receiver. |
|
1393 |
This format looks like: |
|
1394 |
1999-01-01T24:00:00 |
|
1395 |
or, for zero hr:min:sec, |
|
1396 |
1999-01-01 |
|
1397 |
Of course, a 24 hour clock is used." |
|
1398 |
||
1399 |
^ String streamContents:[:s | self printIso8601FormatOn:s] |
|
1400 |
||
1401 |
" |
|
1402 |
Timestamp now printStringIso8601Format |
|
1403 |
" |
|
1404 |
! |
|
1405 |
||
7474 | 1406 |
printStringRFC1123Format |
1407 |
"return the RFC1123 representation of the receiver. |
|
1408 |
This format is used in HTTP requests and looks like: |
|
7671 | 1409 |
'Fri, 04 Jul 2003 15:56:11 GMT' |
7474 | 1410 |
(always GMT)" |
1411 |
||
1412 |
^ String streamContents:[:s | self printRFC1123FormatOn:s] |
|
1413 |
||
1414 |
" |
|
8246 | 1415 |
Timestamp now printStringRFC1123Format |
7474 | 1416 |
" |
1417 |
! |
|
1418 |
||
241 | 1419 |
storeOn:aStream |
275 | 1420 |
"store the receiver in a format suitable for reconstruction of the |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1421 |
receiver via readFrom: |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1422 |
Use a OS/architecture independent format" |
275 | 1423 |
|
241 | 1424 |
aStream nextPut:$(; |
8246 | 1425 |
nextPutAll:self class name; |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1426 |
nextPutAll:' readIso8601FormatFrom:'''. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1427 |
self printIso8601FormatOn:aStream. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1428 |
aStream nextPutAll:''')'. |
54 | 1429 |
|
241 | 1430 |
" |
8246 | 1431 |
Timestamp now storeString |
30 | 1432 |
|
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1433 |
Object readFrom:(Timestamp now storeString) readStream |
8246 | 1434 |
Timestamp readFrom:(Timestamp now storeString) readStream |
241 | 1435 |
" |
30 | 1436 |
! ! |
699 | 1437 |
|
8246 | 1438 |
!Timestamp methodsFor:'private'! |
699 | 1439 |
|
1501 | 1440 |
fromOSTime:anUninterpretedOSTime |
699 | 1441 |
"strictly private: set the seconds from an OS time (since whatever)" |
1442 |
||
1501 | 1443 |
osTime := anUninterpretedOSTime |
1444 |
||
1445 |
"Created: 1.7.1996 / 14:33:21 / cg" |
|
1446 |
! |
|
1447 |
||
1448 |
getMilliseconds |
|
1449 |
"strictly private: return the milliseconds (since whatever)" |
|
1450 |
||
1451 |
^ osTime |
|
1452 |
||
1453 |
"Created: 1.7.1996 / 14:33:56 / cg" |
|
699 | 1454 |
! |
1455 |
||
1456 |
getSeconds |
|
1457 |
"strictly private: return the seconds (since whatever)" |
|
1458 |
||
1501 | 1459 |
^ osTime // 1000 |
699 | 1460 |
! |
1461 |
||
1501 | 1462 |
setMilliseconds:millis |
1463 |
"strictly private: set the milliseconds (since whatever)" |
|
1464 |
||
1465 |
osTime := millis. |
|
1466 |
||
1467 |
"Modified: 20.12.1995 / 11:46:36 / stefan" |
|
1468 |
"Created: 1.7.1996 / 14:34:24 / cg" |
|
1469 |
! |
|
1470 |
||
699 | 1471 |
setSeconds:secs |
1472 |
"strictly private: set the seconds (since whatever)" |
|
1473 |
||
1501 | 1474 |
osTime := secs * 1000. |
795 | 1475 |
|
1476 |
"Modified: 20.12.1995 / 11:46:36 / stefan" |
|
1501 | 1477 |
"Modified: 1.7.1996 / 14:34:10 / cg" |
5853 | 1478 |
! |
1479 |
||
1480 |
utcSecondsSince1970 |
|
1481 |
"return the UTC seconds since 1970" |
|
1482 |
||
9430
919e0cb2257c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
9416
diff
changeset
|
1483 |
^ self getSeconds |
5853 | 1484 |
|
1485 |
" |
|
8246 | 1486 |
Timestamp now utcSecondsSince1970 |
5853 | 1487 |
" |
699 | 1488 |
! ! |
1489 |
||
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1490 |
|
8396
b13503dbc53c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8286
diff
changeset
|
1491 |
!Timestamp methodsFor:'visiting'! |
b13503dbc53c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8286
diff
changeset
|
1492 |
|
b13503dbc53c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8286
diff
changeset
|
1493 |
acceptVisitor:aVisitor with:aParameter |
b13503dbc53c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8286
diff
changeset
|
1494 |
|
b13503dbc53c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8286
diff
changeset
|
1495 |
^ aVisitor visitTimestamp:self with:aParameter |
b13503dbc53c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8286
diff
changeset
|
1496 |
! ! |
b13503dbc53c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8286
diff
changeset
|
1497 |
|
8246 | 1498 |
!Timestamp class methodsFor:'documentation'! |
699 | 1499 |
|
1500 |
version |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
1501 |
^ '$Id: Timestamp.st 10467 2009-08-19 16:14:36Z vranyj1 $' |
699 | 1502 |
! ! |
8246 | 1503 |
|
1504 |
Timestamp initialize! |