author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Thu, 19 Jan 2012 11:46:00 +0000 | |
branch | jv |
changeset 17911 | a99f15c5efa5 |
parent 17910 | 8d796ca8bd1d |
child 17976 | 50c2416f962a |
permissions | -rw-r--r-- |
30 | 1 |
" |
2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
17815 | 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 |
17847 | 15 |
instanceVariableNames:'osTime' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Magnitude-Time' |
|
30 | 19 |
! |
20 |
||
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
21 |
Object subclass:#TimestampBuilderAbstract |
17847 | 22 |
instanceVariableNames:'year month day hour minute second millisecond isUtcTime' |
23 |
classVariableNames:'' |
|
24 |
poolDictionaries:'' |
|
25 |
privateIn:Timestamp |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
26 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
27 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
28 |
Timestamp::TimestampBuilderAbstract subclass:#TimestampISO8601Builder |
17847 | 29 |
instanceVariableNames:'stream' |
30 |
classVariableNames:'' |
|
31 |
poolDictionaries:'' |
|
32 |
privateIn:Timestamp |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
33 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
34 |
|
8246 | 35 |
!Timestamp class methodsFor:'documentation'! |
30 | 36 |
|
82 | 37 |
copyright |
38 |
" |
|
39 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
17815 | 40 |
All Rights Reserved |
82 | 41 |
|
42 |
This software is furnished under a license and may be used |
|
43 |
only in accordance with the terms of that license and with the |
|
44 |
inclusion of the above copyright notice. This software may not |
|
45 |
be provided or otherwise made available to, or used by, any |
|
46 |
other person. No title to or ownership of the software is |
|
47 |
hereby transferred. |
|
48 |
" |
|
49 |
! |
|
50 |
||
30 | 51 |
documentation |
52 |
" |
|
8264
b14c26a88e96
Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents:
8254
diff
changeset
|
53 |
This class represents time values in milliSeconds starting some |
17815 | 54 |
time in the past. When printing an accessing values like #hour, the timestamp will be |
55 |
interpreted in the local timezone. |
|
56 |
||
57 |
(The internal representation, osTime, will typically start with 1970-01-01 0:00, |
|
58 |
as used in the Unix operating system, but other systems may bias the time differently. |
|
1501 | 59 |
Actually, the implementation does not depend or even know which time/date |
60 |
the OperatingSystem bases its time upon - it is simply keeping the value(s) |
|
7671 | 61 |
as returned from the OS. |
1501 | 62 |
For conversion, these values are given back to the OS, which will know |
7671 | 63 |
how to convert these times. This has the advantage, that timestamps on files |
64 |
(such as last-access-time or last-modification-time) can be handled transparently - |
|
65 |
especially when performing comparisons). |
|
241 | 66 |
|
1501 | 67 |
You should not interpret the osTime instance variable directly, instead |
7671 | 68 |
(if at all), ask the OS to convert. |
30 | 69 |
|
7671 | 70 |
The implementation of this class is not the same as in ST-80 |
71 |
(which represents the time as seconds from Jan 1., 1901). |
|
30 | 72 |
|
241 | 73 |
This class should not be confused with Time (which only represents the |
7671 | 74 |
time within one day). Time instances cannot be used to compare times across midnight; |
8246 | 75 |
instances of Timestamp can. |
241 | 76 |
|
8264
b14c26a88e96
Change AbsoluteTime to Timestamp
Stefan Vogel <sv@exept.de>
parents:
8254
diff
changeset
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
AbsoluteTime is still kept as an alias for backward compatibility. |
3479 | 81 |
|
1306 | 82 |
[author:] |
7671 | 83 |
Claus Gittinger |
1306 | 84 |
|
1282 | 85 |
[See also:] |
17815 | 86 |
UtcTimestamp Time Date |
7671 | 87 |
Delay ProcessorScheduler |
30 | 88 |
" |
89 |
! ! |
|
90 |
||
8246 | 91 |
!Timestamp class methodsFor:'initialization'! |
92 |
||
93 |
initialize |
|
94 |
||
95 |
AbsoluteTime := self. "backward compatibility" |
|
17850 | 96 |
DateAndTime isNil ifTrue:[ |
97 |
DateAndTime := self |
|
98 |
]. |
|
99 |
||
100 |
"Modified: / 20-08-2011 / 18:43:51 / cg" |
|
8246 | 101 |
! ! |
102 |
||
103 |
!Timestamp class methodsFor:'instance creation'! |
|
30 | 104 |
|
4378 | 105 |
UTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis |
17815 | 106 |
"return an instance of the receiver, given individual components, |
107 |
interpreted in the UTC timezone." |
|
1501 | 108 |
|
423 | 109 |
^ self basicNew |
8246 | 110 |
fromOSTime:(OperatingSystem |
111 |
computeOSTimeFromUTCYear:y month:m day:d |
|
112 |
hour:h minute:min second:s |
|
113 |
millisecond:millis) |
|
30 | 114 |
|
241 | 115 |
" |
17757 | 116 |
Timestamp UTCYear:1970 month:1 day:1 hour:0 minute:0 second:0 millisecond:0 |
8246 | 117 |
Timestamp UTCYear:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:0 |
118 |
Timestamp UTCYear:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100 |
|
119 |
Timestamp UTCYear:1999 month:7 day:1 hour:1 minute:0 second:0 millisecond:0 |
|
120 |
Timestamp UTCYear:2000 month:1 day:1 hour:1 minute:0 second:0 millisecond:0 |
|
17815 | 121 |
|
122 |
UtcTimestamp UTCYear:2000 month:1 day:1 hour:1 minute:0 second:0 millisecond:0 |
|
241 | 123 |
" |
1228 | 124 |
|
4378 | 125 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
126 |
"Created: / 13.7.1999 / 12:34:37 / stefan" |
|
127 |
"Modified: / 13.7.1999 / 12:42:30 / stefan" |
|
128 |
! |
|
129 |
||
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
130 |
decodeFromLiteralArray:anArray |
8246 | 131 |
"decode an Timestamp literalArray. |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
132 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
133 |
anArray may be: |
8246 | 134 |
#(Timestamp '200004182000.123') |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
135 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
136 |
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
|
137 |
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
|
138 |
|
8246 | 139 |
#(Timestamp #osTime: 12345678) |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
140 |
" |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
141 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
142 |
(anArray at:2) == #osTime: ifTrue:[ |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
143 |
^ self new osTime:(anArray at:3). |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
144 |
]. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
145 |
|
11126 | 146 |
^ self |
147 |
readGeneralizedFrom:(anArray at:2) |
|
148 |
onError:[ self conversionErrorSignal |
|
149 |
raiseErrorString:'literal array decoding' ] |
|
8797 | 150 |
|
151 |
" |
|
152 |
Timestamp |
|
153 |
decodeFromLiteralArray:#(Timestamp '20050323175226.014') |
|
154 |
" |
|
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
155 |
! |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
156 |
|
423 | 157 |
fromDate:aDate andTime:aTime |
158 |
"return an instance of the receiver, initialized from a time and a date |
|
1228 | 159 |
object. |
8246 | 160 |
See also `Timestamp now' and other protocol inherited |
1228 | 161 |
from my superclass." |
423 | 162 |
|
163 |
^ self |
|
8246 | 164 |
year:aDate year |
165 |
month:aDate month |
|
166 |
day:aDate day |
|
167 |
hour:aTime hours |
|
168 |
minute:aTime minutes |
|
169 |
second:aTime seconds |
|
17757 | 170 |
millisecond:0 |
423 | 171 |
" |
8246 | 172 |
Timestamp fromDate:(Date today) andTime:(Time now) |
173 |
Timestamp fromDate:(Date today plusDays:1) andTime:(Time now) |
|
174 |
Timestamp now |
|
423 | 175 |
" |
176 |
||
4378 | 177 |
"Modified: / 8.9.1995 / 15:07:30 / claus" |
178 |
"Modified: / 19.4.1996 / 15:25:46 / cg" |
|
179 |
"Modified: / 13.7.1999 / 12:30:47 / stefan" |
|
423 | 180 |
! |
181 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
182 |
newDay:dayInYear year:year |
8246 | 183 |
"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
|
184 |
Date protocol compatibility" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
185 |
|
8246 | 186 |
^ (Date newDay:dayInYear year:year) asTimestamp |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
187 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
188 |
" |
8246 | 189 |
Timestamp newDay:183 year:1996 |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
190 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
191 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
192 |
"Modified: 2.7.1996 / 09:39:30 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
193 |
! |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
194 |
|
17815 | 195 |
secondsSince1970:secs |
196 |
"set time from elapsed seconds since 1-1-1970, 0:0:0. |
|
197 |
This is the format used in the UNIX world" |
|
198 |
||
199 |
^ self basicNew setSeconds:secs. |
|
200 |
||
201 |
" |
|
202 |
Timestamp secondsSince1970:0 |
|
203 |
Timestamp secondsSince1970:3600 |
|
204 |
Timestamp secondsSince1970:3600*24 |
|
205 |
(Timestamp year:2010 month:7 day:1 hour:0 minute:0 second:0) |
|
206 |
= |
|
207 |
(Timestamp secondsSince1970:1277935200) |
|
208 |
" |
|
209 |
||
210 |
"Created: / 21-10-1996 / 17:48:30 / stefan" |
|
211 |
"Modified: / 13-07-1999 / 12:31:22 / stefan" |
|
212 |
"Modified: / 08-01-2011 / 16:06:28 / cg" |
|
213 |
! |
|
214 |
||
215 |
utcMillisecondsSince1970:secs |
|
216 |
"set time from elapsed milliseconds since 1-1-1970, 0:0:0." |
|
217 |
||
218 |
^ self basicNew setMilliseconds:secs |
|
219 |
||
220 |
"Created: / 08-01-2011 / 16:09:32 / cg" |
|
221 |
! |
|
222 |
||
223 |
utcNow |
|
224 |
^ UtcTimestamp now |
|
225 |
||
226 |
" |
|
227 |
Timestamp now |
|
228 |
Timestamp utcNow |
|
229 |
" |
|
230 |
! |
|
231 |
||
232 |
utcSecondsSince1970:secs |
|
233 |
"set time from elapsed seconds since 1-1-1970, 0:0:0. |
|
234 |
This is the format used in the UNIX world" |
|
235 |
||
236 |
^ self secondsSince1970:secs |
|
237 |
||
238 |
"/ |divMod| |
|
239 |
"/ |
|
240 |
"/ divMod := secs divMod:3600. |
|
241 |
"/ ^ self year:1970 month:1 day:1 hour:(divMod at:1) minute:0 second:(divMod at:2) millisecond:0. |
|
242 |
||
243 |
" |
|
244 |
Timestamp secondsSince1970:0 |
|
245 |
Timestamp secondsSince1970:3600 |
|
246 |
Timestamp secondsSince1970:3600*24 |
|
247 |
" |
|
248 |
||
249 |
"Modified: / 13-07-1999 / 12:31:22 / stefan" |
|
250 |
"Created: / 08-01-2011 / 16:05:09 / cg" |
|
251 |
! |
|
252 |
||
253 |
year:y month:m day:d hour:h minute:min second:s |
|
254 |
"return an instance of the receiver, given individual components. |
|
255 |
See also `Timestamp now' and other protocol inherited |
|
256 |
from my superclass." |
|
257 |
||
258 |
^ self year:y month:m day:d hour:h minute:min second:s millisecond:0 |
|
259 |
||
260 |
" |
|
261 |
Timestamp year:1970 month:1 day:1 hour:1 minute:0 second:0 |
|
262 |
Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 |
|
263 |
Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100 |
|
264 |
Timestamp year:2000 month:7 day:1 hour:1 minute:0 second:0 |
|
265 |
" |
|
266 |
||
267 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
|
268 |
"Created: / 13.7.1999 / 12:06:39 / stefan" |
|
269 |
"Modified: / 13.7.1999 / 12:27:47 / stefan" |
|
270 |
! |
|
271 |
||
272 |
year:y month:m day:d hour:h minute:min second:s millisecond:millis |
|
273 |
"return an instance of the receiver, given individual components. |
|
274 |
See also `Timestamp now' and other protocol inherited |
|
275 |
from my superclass." |
|
276 |
||
277 |
^ self basicNew |
|
278 |
year:y month:m day:d hour:h minute:min second:s millisecond:millis |
|
279 |
" |
|
280 |
Timestamp year:1970 month:1 day:1 hour:0 minute:0 second:0 |
|
281 |
Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 |
|
282 |
Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100 |
|
283 |
Timestamp year:2000 month:7 day:1 hour:1 minute:0 second:0 |
|
284 |
UtcTimestamp year:2000 month:7 day:1 hour:1 minute:0 second:0 |
|
285 |
" |
|
286 |
||
287 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
|
288 |
"Created: / 13.7.1999 / 12:28:44 / stefan" |
|
289 |
"Modified: / 13.7.1999 / 12:37:57 / stefan" |
|
290 |
! ! |
|
291 |
||
17865 | 292 |
|
17815 | 293 |
!Timestamp class methodsFor:'Compatibility-Squeak'! |
294 |
||
295 |
current |
|
296 |
^ self now |
|
17850 | 297 |
! |
298 |
||
299 |
fromString: aString |
|
300 |
"Answer a new instance for the value given by aString" |
|
301 |
||
302 |
^ self readFrom: (ReadStream on: aString). |
|
303 |
||
304 |
" |
|
305 |
Timestamp fromString: '1-10-2000 11:55:00 am'. |
|
306 |
" |
|
307 |
||
308 |
"Modified (format): / 20-08-2011 / 16:51:53 / cg" |
|
309 |
! |
|
310 |
||
311 |
readFrom:aStringOrStream |
|
312 |
"Answer a new instance for the value given by aStringOrStream" |
|
313 |
||
314 |
^ self |
|
315 |
readFrom:aStringOrStream |
|
316 |
onError:[ ConversionError raiseRequestErrorString:'conversion error'] |
|
317 |
||
318 |
" |
|
319 |
self readFrom:'23-jun-2000 15:00' |
|
320 |
self readFrom:'23-jun-2000 ' |
|
321 |
" |
|
322 |
||
323 |
"Modified (comment): / 20-08-2011 / 16:52:10 / cg" |
|
17815 | 324 |
! ! |
325 |
||
17862 | 326 |
!Timestamp class methodsFor:'format strings'! |
327 |
||
328 |
defaultFormatString |
|
329 |
^ '%(year)-%(month)-%(day) %h:%m:%s.%i' |
|
330 |
||
331 |
"Created: / 16-01-2011 / 11:23:36 / cg" |
|
332 |
! ! |
|
333 |
||
17815 | 334 |
!Timestamp class methodsFor:'obsolete'! |
335 |
||
336 |
day:d month:m year:y hour:h minutes:min seconds:s |
|
337 |
<resource: #obsolete> |
|
338 |
"This is obsolete. User #year:month:day:hour:minute:second:" |
|
339 |
||
340 |
^ self |
|
341 |
year:y month:m day:d hour:h |
|
342 |
minute:min second:s millisecond:0 |
|
343 |
||
344 |
||
345 |
"Modified: / 1.7.1996 / 15:22:26 / cg" |
|
346 |
"Modified: / 13.7.1999 / 12:29:56 / stefan" |
|
347 |
! |
|
348 |
||
349 |
day:d month:m year:y hour:h minutes:min seconds:s milliseconds:millis |
|
350 |
<resource: #obsolete> |
|
351 |
"This is obsolete. User #year:month:day:hour:minute:second:millisecond:" |
|
352 |
||
353 |
^ self year:y month:m day:d hour:h minute:min second:s millisecond:millis |
|
354 |
||
355 |
" |
|
356 |
Timestamp day:1 month:1 year:1970 hour:1 minute:0 second:0 |
|
357 |
Timestamp day:2 month:1 year:1991 hour:12 minute:30 second:0 |
|
358 |
Timestamp day:2 month:1 year:1991 hour:12 minute:30 second:0 millisecond:100 |
|
359 |
" |
|
360 |
||
361 |
"Created: / 1.7.1996 / 14:46:09 / cg" |
|
362 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
|
363 |
"Modified: / 13.7.1999 / 12:30:26 / stefan" |
|
364 |
! ! |
|
365 |
||
366 |
!Timestamp class methodsFor:'private'! |
|
367 |
||
368 |
basicReadFrom:aStream |
|
369 |
"return a new Timestamp, reading a printed representation from aStream. |
|
370 |
The string is interpreted as 24 hour format, as printed. |
|
371 |
Notice, that this is not the storeString format and |
|
372 |
is different from the format expected by readFrom:. |
|
373 |
KLUDGE: |
|
374 |
us and non-us format have different ordering of day and month; |
|
375 |
The format read here is (non-us) dd-mm-yyyy hh:mm:ss.iii |
|
376 |
or (us-format, for Travis) mm/dd/yyyy hh:mm:ss.iii. |
|
377 |
On error, raise an exception" |
|
378 |
||
379 |
|firstNumber secondNumber day month year hour min sec millis usFormat possibeMonthName| |
|
380 |
||
381 |
firstNumber := Integer readFrom:aStream onError:[TimeConversionError raiseErrorString:' - integer expected']. |
|
382 |
firstNumber > 31 ifTrue:[ |
|
383 |
"/ assume iso8601 format; |
|
384 |
^ self readIso8601FormatFrom:aStream yearAlreadyRead:firstNumber. |
|
385 |
]. |
|
386 |
aStream skipSeparators. |
|
387 |
||
388 |
"/ consider this a kludge |
|
389 |
usFormat := (aStream peek == $/ ). |
|
390 |
||
391 |
[aStream peek isLetterOrDigit] whileFalse:[aStream next]. |
|
392 |
aStream peek isDigit ifTrue:[ |
|
393 |
secondNumber := Integer readFrom:aStream onError:-1. |
|
394 |
||
395 |
usFormat ifTrue:[ |
|
396 |
month := firstNumber. |
|
397 |
day := secondNumber. |
|
398 |
] ifFalse:[ |
|
399 |
month := secondNumber. |
|
400 |
day := firstNumber. |
|
401 |
]. |
|
402 |
||
403 |
] ifFalse:[ |
|
404 |
possibeMonthName := aStream throughAnyForWhich:[:ch | ch isLetter]. |
|
405 |
month := Date indexOfMonth:possibeMonthName asLowercase. |
|
406 |
day := firstNumber. |
|
407 |
]. |
|
408 |
||
409 |
(day between:1 and:31) ifFalse:[ TimeConversionError raiseErrorString:' - bad day' ]. |
|
410 |
(month between:1 and:12) ifFalse:[ TimeConversionError raiseErrorString:' - bad month' ]. |
|
411 |
||
412 |
[aStream peek isDigit] whileFalse:[aStream next]. |
|
413 |
year := Integer readFrom:aStream onError:[ TimeConversionError raiseErrorString:' - bad year' ]. |
|
414 |
||
415 |
aStream atEnd ifTrue:[ |
|
416 |
hour := min := sec := millis := 0. |
|
417 |
] ifFalse:[ |
|
418 |
[aStream peek isDigit] whileFalse:[aStream next]. |
|
419 |
hour := Integer readFrom:aStream onError:-1. |
|
420 |
(hour between:0 and:24) ifFalse:[ TimeConversionError raiseErrorString:' - bad hour' ]. |
|
421 |
||
422 |
[aStream peek isDigit] whileFalse:[aStream next]. |
|
423 |
min := Integer readFrom:aStream onError:-1. |
|
424 |
(min between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad minute' ]. |
|
425 |
||
426 |
aStream atEnd ifTrue:[ |
|
427 |
sec := millis := 0. |
|
428 |
] ifFalse:[ |
|
429 |
[aStream peek isDigit] whileFalse:[aStream next]. |
|
430 |
sec := Integer readFrom:aStream onError:-1. |
|
431 |
(sec between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad second' ]. |
|
432 |
||
433 |
aStream peek = $. ifTrue:[ |
|
434 |
aStream next. |
|
435 |
millis := Integer readFrom:aStream onError:0. |
|
436 |
millis >= 1000 ifTrue:[ TimeConversionError raiseErrorString:' - bad millisecond' ]. |
|
437 |
] ifFalse:[ |
|
438 |
millis := 0. |
|
439 |
]. |
|
440 |
]. |
|
441 |
]. |
|
442 |
||
443 |
"special check - only 24:00:00 is allowed; |
|
444 |
every time after that must wrap" |
|
445 |
hour == 24 ifTrue:[ |
|
446 |
(min ~~ 0 or:[sec ~~ 0 or:[millis ~~ 0]]) ifTrue:[ TimeConversionError raiseErrorString:' - bad hour' ]. |
|
447 |
]. |
|
448 |
^ self year:year month:month day:day hour:hour minute:min second:sec millisecond:millis. |
|
449 |
||
450 |
" |
|
451 |
Timestamp basicReadFrom:'20-2-1995 13:11:06' readStream |
|
452 |
Timestamp basicReadFrom:'20-2-1995 13:11:06.' readStream |
|
453 |
(Timestamp basicReadFrom:'10-9-1995 13:11:06' readStream) month |
|
454 |
(Timestamp basicReadFrom:'10/9/1995 13:11:06' readStream) month |
|
455 |
Timestamp basicReadFrom:'20-2-1995 13:11' readStream |
|
456 |
Timestamp basicReadFrom:'20-2-1995 13:11:06.100' readStream |
|
457 |
Timestamp basicReadFrom:'32-2-1995 13:11:06.100' readStream |
|
458 |
Timestamp basicReadFrom:'32-foo-1995 13:11:06.100' readStream |
|
459 |
Timestamp basicReadFrom:'20-13-1995 13:11:06.100' readStream |
|
460 |
Timestamp basicReadFrom:'20-12-1995 25:11:06.100' readStream |
|
461 |
Timestamp basicReadFrom:'20-12-1995 23:61:06.100' readStream |
|
462 |
Timestamp basicReadFrom:'20-12-1995 23:10:66.100' readStream |
|
463 |
Timestamp basicReadFrom:'20-12-1995 23:10:00.1000' readStream |
|
464 |
Timestamp basicReadFrom:'20-2-1995 24:01:00.100' readStream |
|
465 |
Timestamp basicReadFrom:'20-2-1995 24:00:01.100' readStream |
|
466 |
Timestamp basicReadFrom:'foo' readStream |
|
467 |
Timestamp basicReadFrom:(Timestamp now printString readStream) |
|
468 |
Timestamp basicReadFrom:'1995-10-20 24:00:00.000' readStream |
|
469 |
Timestamp basicReadFrom:'1995-10-20 12:10:00.000' readStream |
|
470 |
||
471 |
UtcTimestamp basicReadFrom:'1995-10-20 12:10:00.000' readStream |
|
472 |
" |
|
473 |
! |
|
474 |
||
475 |
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil |
|
476 |
"common helper for read methods. |
|
477 |
Return a new Timestamp, reading an iso8601 representation from aStream. |
|
478 |
||
479 |
If the time ends with a 'Z' it is the UTC (or zulu) time, |
|
480 |
othrwise it is local time. |
|
481 |
||
482 |
Missing month/day values are replaced with 1; i.e. 1999T24:00 |
|
483 |
is the same as 1999-01-01T24:00:00. |
|
484 |
Missing minute, second and ms values are replaced with 0; |
|
485 |
i.e. 1999T12 is the same as 1999-01-01T12:00:00.000. |
|
486 |
Of course, a 24 hour clock is used. |
|
487 |
On error, raise an exception. |
|
488 |
Please use this format for all external representations - its the standard." |
|
489 |
||
490 |
|str day month year hour min sec millis fraction isUtcTime peekChar| |
|
491 |
||
492 |
str := aStringOrStream readStream. |
|
493 |
||
494 |
month := day := 1. |
|
495 |
hour := min := sec := millis := 0. |
|
496 |
isUtcTime := false. |
|
497 |
||
498 |
yearOrNil notNil ifTrue:[ |
|
499 |
year := yearOrNil |
|
500 |
] ifFalse:[ |
|
501 |
year := Integer readFrom:str onError:nil. |
|
502 |
year isNil ifTrue:[ TimeConversionError raiseErrorString:' - bad year' ] |
|
503 |
]. |
|
504 |
||
505 |
str skipSeparators. |
|
506 |
str peek == $- ifTrue:[ |
|
507 |
str next. |
|
508 |
"/ month follows. |
|
509 |
month := Integer readFrom:str. |
|
510 |
(month between:1 and:12) ifFalse:[ TimeConversionError raiseErrorString:' - bad month' ]. |
|
511 |
||
512 |
str skipSeparators. |
|
513 |
str peek == $- ifTrue:[ |
|
514 |
str next. |
|
515 |
"/ day follows. |
|
516 |
day := Integer readFrom:str. |
|
517 |
(day between:1 and:31) ifFalse:[ TimeConversionError raiseErrorString:' - bad day' ]. |
|
518 |
]. |
|
519 |
]. |
|
520 |
||
521 |
str skipSeparators. |
|
522 |
str atEnd ifFalse:[ |
|
523 |
"time follows" |
|
524 |
||
525 |
str peek == $T ifTrue:[ |
|
526 |
"we treat the T as optional here" |
|
527 |
str next. |
|
528 |
str skipSeparators. |
|
529 |
]. |
|
530 |
hour := Integer readFrom:str onError:-1. |
|
531 |
(hour between:0 and:24) ifFalse:[ TimeConversionError raiseErrorString:' - bad hour' ]. |
|
532 |
str skipSeparators. |
|
533 |
str peekOrNil == $: ifTrue:[ |
|
534 |
str next. |
|
535 |
"/ minutes follow. |
|
536 |
min := Integer readFrom:str onError:-1. |
|
537 |
(min between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad minute' ]. |
|
538 |
str skipSeparators. |
|
539 |
str peekOrNil == $: ifTrue:[ |
|
540 |
str next. |
|
541 |
"/ seconds follow. |
|
542 |
sec := Integer readFrom:str onError:-1. |
|
543 |
(sec between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad seconds' ]. |
|
544 |
str skipSeparators. |
|
545 |
str peekOrNil == $. ifTrue:[ |
|
546 |
str next. |
|
547 |
"/ millis follow. |
|
548 |
fraction := Number readMantissaFrom:str radix:10. |
|
549 |
millis := (1000 * fraction) rounded. "/ mhmh - should it be truncated ? |
|
550 |
] |
|
551 |
]. |
|
552 |
]. |
|
553 |
||
554 |
peekChar := str peekOrNil. |
|
555 |
peekChar notNil ifTrue:[ |
|
556 |
peekChar == $Z ifTrue:[ |
|
557 |
str next. |
|
558 |
isUtcTime := true. |
|
559 |
] |
|
560 |
"/ Todo |
|
561 |
"/ ifFalse:[peekChar == $+ ifTrue:[ |
|
562 |
"/ str next. |
|
563 |
"/ isUtcTime := true. |
|
564 |
"/ ] ifFalse:[peekChar == $- ifTrue:[ |
|
565 |
"/ str next. |
|
566 |
"/ isUtcTime := true. |
|
567 |
"/ ]]] |
|
568 |
]. |
|
569 |
]. |
|
570 |
||
571 |
"special check - only 24:00:00 is allowed; |
|
572 |
every time after that must wrap" |
|
573 |
hour == 24 ifTrue:[ |
|
574 |
(min ~~ 0 or:[sec ~~ 0 or:[millis ~~ 0]]) ifTrue:[ TimeConversionError raiseErrorString:' - bad hour' ]. |
|
575 |
]. |
|
576 |
||
577 |
isUtcTime ifTrue:[ |
|
578 |
^ self |
|
579 |
UTCYear:year month:month day:day |
|
580 |
hour:hour minute:min second:sec millisecond:millis. |
|
581 |
] ifFalse:[ |
|
582 |
^ self |
|
583 |
year:year month:month day:day |
|
584 |
hour:hour minute:min second:sec millisecond:millis. |
|
585 |
] |
|
586 |
||
587 |
" |
|
588 |
Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06.123' |
|
589 |
Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06' |
|
590 |
Timestamp readIso8601FormatFrom:'1995-02T13:11:06' |
|
591 |
Timestamp readIso8601FormatFrom:'1995T13:11:06' |
|
592 |
Timestamp readIso8601FormatFrom:'1995T13:11' |
|
593 |
Timestamp readIso8601FormatFrom:'1995T13' |
|
594 |
Timestamp readIso8601FormatFrom:'1995' |
|
595 |
||
596 |
Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06' |
|
597 |
Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06Z' |
|
598 |
||
599 |
Timestamp readIso8601FormatFrom:'1995-02-20 13:11' |
|
600 |
Timestamp readIso8601FormatFrom:'1995-02-20 13' |
|
601 |
||
602 |
24 is allowed with ISO, and is 00:00 of the next day: |
|
603 |
Timestamp readIso8601FormatFrom:'1995-02-20 24:00:00' |
|
604 |
" |
|
605 |
! |
|
606 |
||
607 |
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil onError:exceptionValue |
|
608 |
"common helper for read methods." |
|
609 |
||
610 |
|retVal| |
|
611 |
||
612 |
ConversionError handle:[:ex | |
|
613 |
retVal := exceptionValue value |
|
614 |
] do:[ |
|
615 |
retVal := self readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil |
|
616 |
]. |
|
617 |
^ retVal |
|
618 |
! ! |
|
619 |
||
620 |
!Timestamp class methodsFor:'reading'! |
|
621 |
||
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
622 |
readFrom:aStringOrStream onError:exceptionBlock |
8246 | 623 |
"return a new Timestamp, reading a printed representation from aStream. |
275 | 624 |
The string is interpreted as 24 hour format, as printed. |
625 |
Notice, that this is not the storeString format and |
|
4898 | 626 |
is different from the format expected by readFrom:. |
627 |
The format read here is dd-mm-yyyy hh:mm:ss.iii" |
|
275 | 628 |
|
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
629 |
|stream newTime| |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
630 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
631 |
stream := aStringOrStream readStream. |
275 | 632 |
|
7092
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7058
diff
changeset
|
633 |
Error handle:[:ex | |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
634 |
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
|
635 |
] do:[ |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
636 |
newTime := self basicReadFrom:stream. |
275 | 637 |
]. |
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3510
diff
changeset
|
638 |
^ newTime |
275 | 639 |
|
640 |
" |
|
8246 | 641 |
Timestamp readFrom:'20-2-1995 13:11:06' |
642 |
Timestamp readFrom:'20-2-1995 13:11' |
|
643 |
Timestamp readFrom:'20-2-2001 13:11' |
|
644 |
Timestamp readFrom:'20-2-1995 13:11:06.100' |
|
645 |
Timestamp readFrom:'32-2-1995 13:11:06.100' onError:'wrong' |
|
646 |
Timestamp readFrom:'32-foo-1995 13:11:06.100' onError:'wrong' |
|
647 |
Timestamp readFrom:'20-2-1995 24:01:00.100' onError:'wrong' |
|
648 |
Timestamp readFrom:'20-2-1995 24:00:01.100' onError:'wrong' |
|
649 |
Timestamp readFrom:'2002-08-02 24:00:01.100' onError:'wrong' |
|
650 |
Timestamp readFrom:'foo' onError:'wrong' |
|
651 |
Timestamp readFrom:(Timestamp now storeString) onError:'wrong' |
|
275 | 652 |
" |
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
653 |
|
4378 | 654 |
"Modified: / 8.10.1996 / 19:25:59 / cg" |
655 |
"Modified: / 13.7.1999 / 12:31:14 / stefan" |
|
2311 | 656 |
! |
657 |
||
9620 | 658 |
readGeneralizedFrom:aStringOrStream |
659 |
"return a new Timestamp, reading a printed representation from aStream. |
|
660 |
The format read here is either |
|
661 |
yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format. |
|
662 |
or: |
|
663 |
yyyy-mm-dd HH:MM:SS.iii +uuuu. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
664 |
The string is interpreted as 24 hour format, as printed. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
665 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
666 |
This format is used for BER specification of the ASN.1 GeneralizedTime as defined in X.208 Sec. 33, |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
667 |
so read this before changing anything here. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
668 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
669 |
Notice, that this is not the storeString format and |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
670 |
is different from the format expected by readFrom:. |
9620 | 671 |
" |
11126 | 672 |
^ self |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
673 |
readGeneralizedFrom:aStringOrStream |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
674 |
short:false |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
675 |
onError:[ |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
676 |
self conversionErrorSignal raiseErrorString:'Timestamp format error' |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
677 |
]. |
9620 | 678 |
|
679 |
"Created: / 22-08-2006 / 16:05:55 / cg" |
|
680 |
! |
|
681 |
||
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
682 |
readGeneralizedFrom:aStringOrStream onError:exceptionBlock |
8246 | 683 |
"return a new Timestamp, reading a printed representation from aStream. |
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
684 |
The format read here is either |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
685 |
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
|
686 |
or: |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
687 |
yyyy-mm-dd HH:MM:SS.iii +uuuu. |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
688 |
The string is interpreted as 24 hour format, as printed. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
689 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
690 |
This format is used for BER specification of the ASN.1 GeneralizedTime as defined in X.208 Sec. 33, |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
691 |
so read this before changing anything here. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
692 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
693 |
Notice, that this is not the storeString format and |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
694 |
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
|
695 |
" |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
696 |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
697 |
^ self readGeneralizedFrom:aStringOrStream short:false onError:exceptionBlock |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
698 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
699 |
" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
700 |
|s| |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
701 |
s := '' writeStream. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
702 |
Timestamp now printGeneralizedOn:s. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
703 |
Timestamp readGeneralizedFrom:s contents onError:[] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
704 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
705 |
Daylight saving time: |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
706 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
707 |
Timestamp readGeneralizedFrom:'20000718120000Z' onError:[] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
708 |
Timestamp readGeneralizedFrom:'20000718120000+0200' onError:[] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
709 |
Timestamp readGeneralizedFrom:'20000718120000+0300' onError:[] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
710 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
711 |
No daylight saving time: |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
712 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
713 |
Timestamp readGeneralizedFrom:'20000202120000Z' onError:[] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
714 |
Timestamp readGeneralizedFrom:'20000202120000+0100' onError:[] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
715 |
Timestamp readGeneralizedFrom:'20000202120000+0200' onError:[] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
716 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
717 |
Timestamp readGeneralizedFrom:'19950220131106' onError:[] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
718 |
Timestamp readGeneralizedFrom:'199502201311' onError:[] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
719 |
Timestamp readGeneralizedFrom:'19950220131106.100' onError:[] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
720 |
Timestamp readGeneralizedFrom:'19950232131106.100' onError:'wrong' |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
721 |
Timestamp readGeneralizedFrom:'19950fo2131106.100' onError:'wrong' |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
722 |
Timestamp readGeneralizedFrom:'foo' onError:'wrong' |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
723 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
724 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00' onError:[] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
725 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100' onError:[] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
726 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100 +0100' onError:[] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
727 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 -0100' onError:[] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
728 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 +0000' onError:[] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
729 |
" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
730 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
731 |
"Modified: / 13-07-1999 / 12:31:14 / stefan" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
732 |
"Modified: / 22-08-2006 / 12:30:11 / cg" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
733 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
734 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
735 |
readGeneralizedFrom:aStringOrStream short:shortFormat onError:exceptionBlock |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
736 |
"return a new Timestamp, reading a printed representation from aStream. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
737 |
The long format read here is either |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
738 |
yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
739 |
or: |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
740 |
yyyy-mm-dd HH:MM:SS.iii +uuuu. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
741 |
The (not recommended) short forms are: |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
742 |
yymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
743 |
or: |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
744 |
yy-mm-dd HH:MM:SS.iii +uuuu. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
745 |
The string is interpreted as 24 hour format, as printed. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
746 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
747 |
This format is used for BER specification of the ASN.1 GeneralizedTime and |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
748 |
UTCTime as defined in X.208 Sec. 33, so read this before changing anything here. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
749 |
The short form is no longer recommended. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
750 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
751 |
Notice, that this is not the storeString format and |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
752 |
is different from the format expected by readFrom:. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
753 |
" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
754 |
|
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
755 |
|
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6047
diff
changeset
|
756 |
^ [ |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
757 |
|newTime str day month year hour min sec millis c| |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
758 |
|
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
759 |
sec := millis := 0. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
760 |
str := aStringOrStream readStream. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
761 |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
762 |
shortFormat ifTrue:[ |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
763 |
year := Integer readFrom:(str next:2). |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
764 |
year < 50 ifTrue:[ |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
765 |
year := year + 2000. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
766 |
] ifFalse:[ |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
767 |
year := year + 1900. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
768 |
]. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
769 |
] ifFalse:[ |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
770 |
year := Integer readFrom:(str next:4). |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
771 |
]. |
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
772 |
str peek == $- ifTrue:[ str next]. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
773 |
month := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
774 |
(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
|
775 |
str peek == $- ifTrue:[ str next]. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
776 |
day := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
777 |
(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
|
778 |
|
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
779 |
str skipSeparators. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
780 |
hour:= Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
781 |
(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
|
782 |
str peek == $: ifTrue:[ str next]. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
783 |
min:= Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
784 |
(min between:0 and:59) ifFalse:[^ exceptionBlock value]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
785 |
str atEnd ifFalse:[ |
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
786 |
str peek == $: ifTrue:[ str next]. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
787 |
sec := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
788 |
(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
|
789 |
str atEnd ifFalse:[ |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
790 |
str peek == $. ifTrue:[ |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
791 |
str next. |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
792 |
millis := Integer readFrom:str. |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
793 |
]. |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
794 |
str skipSeparators. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
795 |
]. |
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
796 |
]. |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
797 |
|
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
798 |
str atEnd ifTrue:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
799 |
"/ this is local time |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
800 |
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
|
801 |
hour:hour minute:min second:sec millisecond:millis. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
802 |
] ifFalse:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
803 |
c := str next. |
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
804 |
c ~~ $Z ifTrue:[ |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
805 |
|tzh tzmin| |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
806 |
tzh := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
807 |
tzmin := Integer readFrom:(str next:2). |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
808 |
c == $+ ifTrue:[ |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
809 |
"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
|
810 |
hour := hour - tzh. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
811 |
min := min - tzmin. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
812 |
] ifFalse:[ |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
813 |
c ~~ $- ifTrue:[ |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
814 |
^ exceptionBlock value. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
815 |
]. |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
816 |
"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
|
817 |
hour := hour + tzh. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
818 |
min := min + tzmin. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
819 |
]. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
820 |
]. |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
821 |
"this is UTC time" |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
822 |
newTime := self UTCYear:year month:month day:day |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
823 |
hour:hour minute:min second:sec millisecond:millis. |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
824 |
]. |
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6047
diff
changeset
|
825 |
newTime |
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6047
diff
changeset
|
826 |
] on:Error do:exceptionBlock. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
827 |
|
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
828 |
" |
5656
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
829 |
|s| |
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
830 |
s := '' writeStream. |
8246 | 831 |
Timestamp now printGeneralizedOn:s. |
832 |
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
|
833 |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
834 |
Timestamp readGeneralizedFrom:'20080718120000+0300' short:false onError:[] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
835 |
Timestamp readGeneralizedFrom:'080718120000+0300' short:true onError:[] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
836 |
Timestamp readGeneralizedFrom:'990718120000+0300' short:true onError:[] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
837 |
|
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
838 |
Daylight saving time: |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
839 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
840 |
Timestamp readGeneralizedFrom:'20000718120000Z' onError:[] |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
841 |
Timestamp readGeneralizedFrom:'20000718120000+0200' onError:[] |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
842 |
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
|
843 |
|
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
844 |
No daylight saving time: |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
845 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
846 |
Timestamp readGeneralizedFrom:'20000202120000Z' onError:[] |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
847 |
Timestamp readGeneralizedFrom:'20000202120000+0100' onError:[] |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
848 |
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
|
849 |
|
8246 | 850 |
Timestamp readGeneralizedFrom:'19950220131106' onError:[] |
851 |
Timestamp readGeneralizedFrom:'199502201311' onError:[] |
|
852 |
Timestamp readGeneralizedFrom:'19950220131106.100' onError:[] |
|
853 |
Timestamp readGeneralizedFrom:'19950232131106.100' onError:'wrong' |
|
854 |
Timestamp readGeneralizedFrom:'19950fo2131106.100' onError:'wrong' |
|
855 |
Timestamp readGeneralizedFrom:'foo' onError:'wrong' |
|
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
856 |
|
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
857 |
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
|
858 |
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
|
859 |
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
|
860 |
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
|
861 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 +0000' onError:[] |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
862 |
" |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
863 |
|
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
864 |
"Modified: / 13-07-1999 / 12:31:14 / stefan" |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
865 |
"Modified: / 22-08-2006 / 12:30:11 / cg" |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
866 |
! |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
867 |
|
17815 | 868 |
readISO8601From: stringOrStream |
869 |
||
870 |
^ TimestampISO8601Builder read:stringOrStream withClass:self |
|
871 |
||
872 |
"Created: / 16-06-2005 / 16:13:36 / masca" |
|
873 |
! |
|
874 |
||
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
875 |
readIso8601FormatFrom:aStringOrStream |
8246 | 876 |
"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
|
877 |
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
|
878 |
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
|
879 |
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
|
880 |
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
|
881 |
Of course, a 24 hour clock is used. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
882 |
On error, raise an exception. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
883 |
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
|
884 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
885 |
^ self |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
886 |
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:nil |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
887 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
888 |
" |
8246 | 889 |
Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06' |
890 |
Timestamp readIso8601FormatFrom:'1995-02T13:11:06' |
|
891 |
Timestamp readIso8601FormatFrom:'1995T13:11:06' |
|
892 |
Timestamp readIso8601FormatFrom:'1995T13:11' |
|
893 |
Timestamp readIso8601FormatFrom:'1995T13' |
|
894 |
Timestamp readIso8601FormatFrom:'1995' |
|
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
895 |
|
8246 | 896 |
Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06' |
897 |
Timestamp readIso8601FormatFrom:'1995-02-20 13:11' |
|
898 |
Timestamp readIso8601FormatFrom:'1995-02-20 13' |
|
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
899 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
900 |
24 is allowed with ISO, and is 00:00 of the next day: |
8246 | 901 |
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
|
902 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
903 |
" |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
904 |
! |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
905 |
|
8432 | 906 |
readIso8601FormatFrom:aStringOrStream onError:exceptionValue |
907 |
"return a new Timestamp, reading an iso8601 UTC representation from aStream. |
|
908 |
Missing month/day values are replaced with 1; i.e. 1999T24:00 |
|
909 |
is the same as 1999-01-01T24:00:00. |
|
910 |
Missing minute, second and ms values are replaced with 0; |
|
911 |
i.e. 1999T12 is the same as 1999-01-01T12:00:00.000. |
|
912 |
Of course, a 24 hour clock is used. |
|
913 |
On error, raise an exception. |
|
914 |
Please use this format for all external representations - its the standard." |
|
915 |
||
916 |
^ self |
|
917 |
readIso8601FormatFrom:aStringOrStream |
|
918 |
yearAlreadyRead:nil |
|
919 |
onError:exceptionValue |
|
920 |
! |
|
921 |
||
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
922 |
readRFC1123FormatFrom:rfc1123String onError:exceptionBlock |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
923 |
|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
|
924 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
925 |
"/ 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
|
926 |
"/ 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
|
927 |
"/ 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
|
928 |
"/ 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
|
929 |
"/ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
930 |
"/ HTTP-date = rfc1123-date | rfc850-date | asctime-date |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
931 |
"/ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
932 |
"/ 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
|
933 |
"/ 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
|
934 |
"/ 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
|
935 |
"/ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
936 |
"/ date1 = 2DIGIT SP month SP 4DIGIT |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
937 |
"/ ; day month year (e.g., 02 Jun 1982) |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
938 |
"/ date2 = 2DIGIT "-" month "-" 2DIGIT |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
939 |
"/ ; day-month-year (e.g., 02-Jun-82) |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
940 |
"/ date3 = month SP ( 2DIGIT | ( SP 1DIGIT )) |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
941 |
"/ ; month day (e.g., Jun 2) |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
942 |
"/ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
943 |
"/ time = 2DIGIT ":" 2DIGIT ":" 2DIGIT |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
944 |
"/ ; 00:00:00 - 23:59:59 |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
945 |
"/ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
946 |
"/ wkday = "Mon" | "Tue" | "Wed" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
947 |
"/ | "Thu" | "Fri" | "Sat" | "Sun" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
948 |
"/ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
949 |
"/ weekday = "Monday" | "Tuesday" | "Wednesday" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
950 |
"/ | "Thursday" | "Friday" | "Saturday" | "Sunday" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
951 |
"/ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
952 |
"/ month = "Jan" | "Feb" | "Mar" | "Apr" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
953 |
"/ | "May" | "Jun" | "Jul" | "Aug" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
954 |
"/ | "Sep" | "Oct" | "Nov" | "Dec" |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
955 |
"/ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
956 |
"/ Mon, 17 Aug 2009 11:11:15 GMT |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
957 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
958 |
rfc1123String isEmptyOrNil ifTrue:[^ exceptionBlock value]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
959 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
960 |
parts := rfc1123String subStrings:Character space. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
961 |
parts size == 6 ifTrue:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
962 |
indexModifier := 0. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
963 |
] ifFalse:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
964 |
parts size == 5 ifTrue:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
965 |
indexModifier := -1. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
966 |
] ifFalse:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
967 |
^ exceptionBlock value |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
968 |
]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
969 |
]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
970 |
|
17807 | 971 |
utcOffset := 0. |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
972 |
utcOffsetString := (parts at:6 + indexModifier). |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
973 |
((utcOffsetString sameAs:'GMT') or:[utcOffsetString sameAs:'UTC']) ifFalse:[ |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
974 |
self assert:utcOffsetString size == 5. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
975 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
976 |
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
|
977 |
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
|
978 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
979 |
(utcOffsetString at:1) asSymbol == #- ifTrue:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
980 |
utcOffset := -1 * utcOffset. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
981 |
]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
982 |
]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
983 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
984 |
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
|
985 |
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
|
986 |
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
|
987 |
monthName := parts at:3 + indexModifier. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
988 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
989 |
month := (1 to:12) asOrderedCollection detect:[:i | |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
990 |
(Date abbreviatedNameOfMonth:i language:#en) sameAs:monthName |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
991 |
] ifNone:[^ exceptionBlock]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
992 |
|
17815 | 993 |
^ (self |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
994 |
fromDate:(Date newDay:day monthIndex:month year:year) |
17807 | 995 |
andTime:time) + utcOffset |
996 |
||
997 |
"Modified: / 05-10-2010 / 16:05:32 / cg" |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
998 |
! ! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
999 |
|
17862 | 1000 |
|
8246 | 1001 |
!Timestamp methodsFor:'accessing'! |
30 | 1002 |
|
1003 |
day |
|
92 | 1004 |
"return the day-in-month of the receiver (1..31). |
275 | 1005 |
For compatibility, use instances of Date for this." |
30 | 1006 |
|
17815 | 1007 |
^ self timeInfo day. |
54 | 1008 |
|
92 | 1009 |
" |
8246 | 1010 |
Timestamp now day |
92 | 1011 |
" |
1501 | 1012 |
|
1013 |
"Modified: 1.7.1996 / 15:23:02 / cg" |
|
1014 |
! |
|
1015 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1016 |
dayInWeek |
7327 | 1017 |
"return the week-day of the receiver - 1 for monday, 7 for sunday |
1018 |
WARNING: different from ANSIs dayOfWeek (which returns 1 for sunday, ... 7 for saturday). |
|
1019 |
WARNING: does not care for pre-julian dates |
|
1020 |
(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
|
1021 |
|
17815 | 1022 |
^ self timeInfo dayInWeek |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1023 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1024 |
" |
8246 | 1025 |
Timestamp now dayInWeek |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1026 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1027 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1028 |
"Modified: 2.7.1996 / 09:20:32 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1029 |
"Created: 2.7.1996 / 09:35:48 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1030 |
! |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1031 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1032 |
dayInYear |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1033 |
"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
|
1034 |
|
17815 | 1035 |
^ self timeInfo dayInYear |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1036 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1037 |
" |
8246 | 1038 |
Timestamp now dayInYear |
1039 |
Timestamp newDay:184 year:1996 |
|
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1040 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1041 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1042 |
"Modified: 2.7.1996 / 10:21:02 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1043 |
! |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1044 |
|
17815 | 1045 |
dayOfMonth |
1046 |
"Answer the day of the month represented by me. |
|
1047 |
Same as day; for ST-80 compatibility." |
|
1048 |
||
1049 |
^ self asDate dayOfMonth |
|
1050 |
||
1051 |
" |
|
1052 |
Timestamp now dayOfMonth |
|
1053 |
(Timestamp newDay:184 year:1996) dayOfMonth |
|
1054 |
" |
|
1055 |
||
1056 |
"Created: / 20-01-2011 / 12:26:54 / cg" |
|
1057 |
! |
|
1058 |
||
1059 |
dayOfWeekName |
|
1060 |
"return the week-day of the receiver as a string. |
|
1061 |
The returned string depends on the language setting. |
|
1062 |
Expect things like 'monday', 'tuesday' ..." |
|
1063 |
||
1064 |
^ self asDate dayOfWeekName |
|
1065 |
||
1066 |
" |
|
1067 |
Timestamp now dayOfWeekName |
|
1068 |
(Timestamp newDay:184 year:1996) dayOfWeekName |
|
1069 |
" |
|
1070 |
||
1071 |
"Created: / 20-01-2011 / 12:28:46 / cg" |
|
1072 |
! |
|
1073 |
||
1501 | 1074 |
hour |
1075 |
"return the hour (0..23). |
|
1076 |
ST-80 Timestamp compatibility (I'd prefer the name #hours, for Time compatibility)." |
|
1077 |
||
1078 |
^ self hours |
|
1079 |
||
1080 |
"Created: 1.7.1996 / 15:14:50 / cg" |
|
1081 |
"Modified: 1.7.1996 / 15:15:32 / cg" |
|
30 | 1082 |
! |
1083 |
||
241 | 1084 |
hours |
1085 |
"return the hours (0..23)" |
|
1086 |
||
17815 | 1087 |
^ self timeInfo hours |
54 | 1088 |
|
92 | 1089 |
" |
8246 | 1090 |
Timestamp now hours |
241 | 1091 |
" |
1092 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1093 |
"Modified: 2.7.1996 / 09:20:32 / cg" |
1501 | 1094 |
! |
1095 |
||
1096 |
millisecond |
|
1097 |
"return the millisecond (0..999). |
|
1098 |
ST-80 Timestamp compatibility (I'd prefer the name #milliseconds)." |
|
1099 |
||
1100 |
^ self milliseconds |
|
1101 |
||
1102 |
"Created: 1.7.1996 / 15:14:50 / cg" |
|
1103 |
"Modified: 1.7.1996 / 15:15:24 / cg" |
|
1104 |
! |
|
1105 |
||
1106 |
milliseconds |
|
1107 |
"return the milliseconds (0..999)" |
|
1108 |
||
17815 | 1109 |
^ self timeInfo milliseconds |
1501 | 1110 |
|
1111 |
" |
|
8246 | 1112 |
Timestamp now milliseconds |
1501 | 1113 |
" |
1114 |
||
1115 |
"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
|
1116 |
"Modified: 2.7.1996 / 09:21:41 / cg" |
1501 | 1117 |
! |
1118 |
||
1119 |
minute |
|
1120 |
"return the minute (0..59). |
|
1121 |
ST-80 Timestamp compatibility (I'd prefer the name #minutes, for Time compatibility)." |
|
1122 |
||
1123 |
^ self minutes |
|
1124 |
||
1125 |
"Created: 1.7.1996 / 15:14:29 / cg" |
|
1126 |
"Modified: 1.7.1996 / 15:15:37 / cg" |
|
241 | 1127 |
! |
1128 |
||
1129 |
minutes |
|
1130 |
"return the minutes (0..59)" |
|
1131 |
||
17815 | 1132 |
^ self timeInfo minutes |
241 | 1133 |
|
1134 |
" |
|
8246 | 1135 |
Timestamp now minutes |
92 | 1136 |
" |
241 | 1137 |
|
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1138 |
"Modified: 2.7.1996 / 09:20:49 / cg" |
241 | 1139 |
! |
1140 |
||
699 | 1141 |
month |
1142 |
"return the month of the receiver (1..12). |
|
1143 |
For compatibility, use instances of Date for this." |
|
1144 |
||
17815 | 1145 |
^ self timeInfo month |
699 | 1146 |
|
1147 |
" |
|
8246 | 1148 |
Timestamp now month |
699 | 1149 |
" |
1501 | 1150 |
|
1151 |
"Modified: 1.7.1996 / 15:23:05 / cg" |
|
1152 |
! |
|
1153 |
||
8286 | 1154 |
osTime |
1155 |
"get the internal representation of the time. |
|
1156 |
Warning: do not depend on the value (unix vs. win32 - differences)" |
|
1157 |
||
1158 |
^ osTime |
|
1159 |
! |
|
1160 |
||
4807 | 1161 |
osTime:aTime |
5726 | 1162 |
"set the internal representation of the time" |
1163 |
||
4807 | 1164 |
osTime := aTime. |
1165 |
! |
|
1166 |
||
1501 | 1167 |
second |
1168 |
"return the second (0..59). |
|
1169 |
ST-80 Timestamp compatibility (I'd prefer the name #seconds, for Time compatibility)." |
|
1170 |
||
1171 |
^ self seconds |
|
1172 |
||
1173 |
"Created: 1.7.1996 / 15:14:19 / cg" |
|
1174 |
"Modified: 1.7.1996 / 15:15:49 / cg" |
|
699 | 1175 |
! |
1176 |
||
241 | 1177 |
seconds |
1178 |
"return the seconds (0..59)" |
|
1179 |
||
17815 | 1180 |
^ self timeInfo seconds |
241 | 1181 |
|
1182 |
" |
|
8246 | 1183 |
Timestamp now seconds |
241 | 1184 |
" |
1185 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
1186 |
"Modified: 2.7.1996 / 09:20:54 / cg" |
92 | 1187 |
! |
1188 |
||
7734 | 1189 |
timeInfo |
17815 | 1190 |
^ OperatingSystem computeTimeAndDateFrom:osTime |
1191 |
! |
|
1192 |
||
1193 |
timeZoneDeltaInMinutes |
|
1194 |
"answer the number of minutes between local time and utc time. |
|
1195 |
Delta is positive if local time is ahead of utc, negative if behind utc." |
|
1196 |
||
1197 |
^ self utcOffset negated // 60 |
|
1198 |
||
1199 |
" |
|
1200 |
Timestamp now timeZoneDeltaInMinutes |
|
1201 |
(Timestamp day:1 month:7 year:1995 hour:12 minutes:0 seconds:0) timeZoneDeltaInMinutes |
|
1202 |
" |
|
1203 |
||
1204 |
"Modified: 20.12.1995 / 17:28:49 / stefan" |
|
1205 |
"Modified: 1.7.1996 / 15:21:29 / cg" |
|
7734 | 1206 |
! |
1207 |
||
799 | 1208 |
utcOffset |
8886 | 1209 |
"return the difference between UTC (Greenwich Mean Time) and the local time in seconds. |
1210 |
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
|
1211 |
|
8886 | 1212 |
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
|
1213 |
Subtract utcOffset to convert from UTC time to local time. |
8886 | 1214 |
|
1215 |
If utcOffset is negative, the local timezone is east of Greenwich. |
|
1216 |
If utcOffset is positive, the local timezone is west of Greenwich." |
|
799 | 1217 |
|
17815 | 1218 |
^ self timeInfo utcOffset |
799 | 1219 |
|
1220 |
" |
|
8246 | 1221 |
Timestamp now utcOffset |
1222 |
(Timestamp day:1 month:7 year:1995 hour:12 minutes:0 seconds:0) utcOffset |
|
799 | 1223 |
" |
1224 |
||
1225 |
"Modified: 20.12.1995 / 17:28:49 / stefan" |
|
1501 | 1226 |
"Modified: 1.7.1996 / 15:21:29 / cg" |
799 | 1227 |
! |
1228 |
||
17815 | 1229 |
weekInYear |
1230 |
"return the week number of the receiver - 1 for Jan, 1st." |
|
1231 |
||
1232 |
^ Date weekInYearOf:self |
|
1233 |
||
1234 |
" |
|
1235 |
(Timestamp newDay:1 year:2000) weekInYear |
|
1236 |
(Timestamp newDay:2 year:2000) weekInYear |
|
1237 |
(Timestamp newDay:3 year:2000) weekInYear |
|
1238 |
" |
|
1239 |
! |
|
1240 |
||
699 | 1241 |
year |
1242 |
"return the year of the receiver i.e. 1992. |
|
1243 |
For compatibility, use instances of Date for this." |
|
241 | 1244 |
|
17815 | 1245 |
^ self timeInfo year |
241 | 1246 |
|
1247 |
" |
|
8246 | 1248 |
Timestamp now year |
241 | 1249 |
" |
1501 | 1250 |
|
1251 |
"Modified: 1.7.1996 / 15:23:08 / cg" |
|
241 | 1252 |
! ! |
1253 |
||
8246 | 1254 |
!Timestamp methodsFor:'arithmetic'! |
30 | 1255 |
|
17815 | 1256 |
ceilingSecond |
1257 |
"return a timestamp which represents the next full second" |
|
1258 |
||
1259 |
|offs| |
|
1260 |
||
1261 |
offs := (self milliseconds / 1000) ceiling. |
|
1262 |
^ self class basicNew setSeconds:(self getSeconds + offs). |
|
1263 |
||
1264 |
" |
|
1265 |
|t1 t2| |
|
1266 |
||
1267 |
t1 := Timestamp now. |
|
1268 |
t2 := t1 ceilingSecond. |
|
1269 |
self halt |
|
1270 |
" |
|
1271 |
||
1272 |
"Created: / 08-01-2011 / 16:23:03 / cg" |
|
1273 |
! |
|
1274 |
||
10736 | 1275 |
deltaFrom:aTimestamp |
1276 |
"return the delta as a timeDuration between 2 timeStamps. |
|
17780 | 1277 |
The argument is supposed to be BEFORE the receiver, |
1278 |
computes self - aTimestamp" |
|
10736 | 1279 |
|
1280 |
^ TimeDuration fromMilliseconds:(self getMilliseconds - (aTimestamp getMilliseconds)) |
|
1281 |
||
1282 |
" |
|
1283 |
|t1 t2| |
|
1284 |
||
1285 |
t1 := Timestamp now. |
|
1286 |
Delay waitForSeconds:0.5. |
|
1287 |
t2 := Timestamp now. |
|
1288 |
t2 deltaFrom:t1 |
|
1289 |
" |
|
1290 |
||
1291 |
"Created: / 04-10-2007 / 13:34:28 / cg" |
|
17780 | 1292 |
"Modified: / 10-07-2010 / 09:37:01 / cg" |
10736 | 1293 |
! |
1294 |
||
17815 | 1295 |
floorSecond |
1296 |
"return a timestamp truncated to the last full second" |
|
1297 |
||
1298 |
^ self class basicNew setSeconds:(self getSeconds). |
|
1299 |
||
1300 |
" |
|
1301 |
|t1 t2| |
|
1302 |
||
1303 |
t1 := Timestamp now. |
|
1304 |
t2 := t1 floorSecond. |
|
1305 |
self halt |
|
1306 |
" |
|
1307 |
||
1308 |
"Created: / 08-01-2011 / 16:20:55 / cg" |
|
1309 |
! |
|
1310 |
||
8246 | 1311 |
millisecondDeltaFrom:aTimestamp |
3510 | 1312 |
"return the delta in milliseconds between 2 absolute times. |
17780 | 1313 |
The argument is supposed to be BEFORE the receiver, |
1314 |
computes self - aTimestamp" |
|
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1315 |
|
8246 | 1316 |
^ self getMilliseconds - (aTimestamp getMilliseconds) |
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1317 |
|
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1318 |
" |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1319 |
|t1 t2| |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1320 |
|
8246 | 1321 |
t1 := Timestamp now. |
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1322 |
Delay waitForSeconds:0.5. |
8246 | 1323 |
t2 := Timestamp now. |
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1324 |
t2 millisecondDeltaFrom:t1 |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1325 |
" |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
1326 |
|
17780 | 1327 |
"Modified: / 10-07-2010 / 09:37:18 / cg" |
9056 | 1328 |
! |
1329 |
||
17815 | 1330 |
roundedToSecond |
1331 |
"return a timestamp which represents the time rounded to the nearest full second" |
|
1332 |
||
1333 |
|offs| |
|
1334 |
||
1335 |
offs := (self milliseconds / 1000) rounded. |
|
1336 |
^ self class basicNew setSeconds:(self getSeconds + offs). |
|
1337 |
||
1338 |
" |
|
1339 |
|t1 t2| |
|
1340 |
||
1341 |
t1 := Timestamp now. |
|
1342 |
t2 := t1 roundedToSecond. |
|
1343 |
self halt |
|
1344 |
" |
|
1345 |
||
1346 |
"Created: / 08-01-2011 / 16:24:12 / cg" |
|
1347 |
! |
|
1348 |
||
9056 | 1349 |
secondDeltaFrom:aTimestamp |
1350 |
"return the delta in seconds between 2 absolute times. |
|
17780 | 1351 |
The argument is supposed to be BEFORE the receiver, |
1352 |
computes self - aTimestamp" |
|
9056 | 1353 |
|
1354 |
^ self getSeconds - (aTimestamp getSeconds) |
|
1355 |
||
1356 |
" |
|
1357 |
|t1 t2| |
|
1358 |
||
1359 |
t1 := Timestamp now. |
|
1360 |
Delay waitForSeconds:5. |
|
1361 |
t2 := Timestamp now. |
|
1362 |
t2 secondDeltaFrom:t1 |
|
1363 |
" |
|
1364 |
||
17780 | 1365 |
"Modified: / 10-07-2010 / 09:37:24 / cg" |
30 | 1366 |
! ! |
1367 |
||
8246 | 1368 |
!Timestamp methodsFor:'comparing'! |
699 | 1369 |
|
1370 |
= aTime |
|
1371 |
"return true if the argument, aTime represents the same time" |
|
1372 |
||
17815 | 1373 |
aTime isTimestamp ifFalse:[^ false]. |
1520
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
1374 |
^ (self getMilliseconds = aTime getMilliseconds) |
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
1375 |
|
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
1376 |
"Modified: 3.7.1996 / 13:10:24 / cg" |
699 | 1377 |
! |
1378 |
||
1379 |
hash |
|
1380 |
"return an integer useful for hashing on times" |
|
1381 |
||
1520
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
1382 |
^ osTime // 1000 |
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
1383 |
|
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
1384 |
"Modified: 3.7.1996 / 13:10:52 / cg" |
699 | 1385 |
! ! |
1386 |
||
8246 | 1387 |
!Timestamp methodsFor:'converting'! |
699 | 1388 |
|
1389 |
asAbsoluteTime |
|
8254
73b6109ab982
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
8246
diff
changeset
|
1390 |
"deprecated, use #asTimestamp" |
8246 | 1391 |
|
1392 |
<resource:#obsolete> |
|
699 | 1393 |
|
9061 | 1394 |
self obsoleteMethodWarning:'use #asTimestamp'. |
699 | 1395 |
^ self |
1396 |
! |
|
1397 |
||
1398 |
asDate |
|
1399 |
"return a Date object from the receiver. |
|
1400 |
The returned date will only represent the day - not the timeOfDay." |
|
1401 |
||
17815 | 1402 |
^ self timeInfo asDate |
699 | 1403 |
|
1404 |
" |
|
8246 | 1405 |
Timestamp now |
1406 |
Timestamp now asDate |
|
1407 |
(Timestamp now addTime:3600) asDate |
|
1408 |
(Timestamp now addTime:3600) asTime |
|
1409 |
Timestamp fromSeconds:(Timestamp now asSeconds + 3600) |
|
1410 |
(Timestamp fromSeconds:(Timestamp now asSeconds + 3600)) asDate |
|
699 | 1411 |
" |
1412 |
! |
|
1413 |
||
11003 | 1414 |
asLocalTimestamp |
17815 | 1415 |
"represent myself as a timestamp in the local timezone" |
1416 |
||
1417 |
^ self |
|
11003 | 1418 |
|
1419 |
" |
|
1420 |
Timestamp now asUtcTimestamp |
|
1421 |
Timestamp now asUtcTimestamp asLocalTimestamp |
|
1422 |
" |
|
1423 |
! |
|
1424 |
||
7466
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1425 |
asMilliseconds |
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1426 |
"return the number of milliSeconds elapsed since whatever time the |
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1427 |
OperatingSystem bases its time upon. Since this is totally |
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1428 |
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
|
1429 |
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
|
1430 |
|
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1431 |
^ self getMilliseconds |
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1432 |
! |
87775b24d5ea
category and comment change;
Claus Gittinger <cg@exept.de>
parents:
7327
diff
changeset
|
1433 |
|
699 | 1434 |
asSeconds |
1435 |
"return the number of seconds elapsed since whatever time the |
|
1436 |
OperatingSystem bases its time upon. Since this is totally |
|
1437 |
OS-dependent, do not interpret the value returned by this method. |
|
1438 |
You can use it to add/subtract seconds or get time deltas, though." |
|
1439 |
||
1440 |
^ self getSeconds |
|
1441 |
||
7004 | 1442 |
" |
8246 | 1443 |
Timestamp now asSeconds |
1444 |
Timestamp fromSeconds:(Timestamp now asSeconds + 3600) |
|
699 | 1445 |
Time hour:23 minutes:33 seconds:0 |
1446 |
Time fromSeconds:((Time hour:23 minutes:33 seconds:0) asSeconds + 3600) |
|
1447 |
" |
|
1448 |
! |
|
1449 |
||
1450 |
asTime |
|
1451 |
"return a Time object from the receiver. |
|
1452 |
The returned time will only represent the timeOfDay - not the day." |
|
1453 |
||
17815 | 1454 |
^ self timeInfo asTime |
699 | 1455 |
|
1456 |
" |
|
8246 | 1457 |
Timestamp now |
1458 |
Timestamp now asTime |
|
17815 | 1459 |
UtcTimestamp now asTime |
8246 | 1460 |
(Timestamp now addTime:3600) asTime |
699 | 1461 |
" |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1462 |
! |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1463 |
|
8246 | 1464 |
asTimestamp |
1465 |
"return an Timestamp object from the receiver - thats the receiver." |
|
1466 |
||
1467 |
^ self |
|
1468 |
! |
|
1469 |
||
9402 | 1470 |
asUtcTimestamp |
17815 | 1471 |
"represent myself as a timestamp in the UTC timezone" |
1472 |
||
1473 |
^ UtcTimestamp fromOSTime:osTime |
|
9402 | 1474 |
|
1475 |
" |
|
11003 | 1476 |
Timestamp now asUtcTimestamp |
17815 | 1477 |
Timestamp now asUtcTimestamp asLocalTimestamp |
9402 | 1478 |
" |
1479 |
! |
|
1480 |
||
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1481 |
literalArrayEncoding |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1482 |
"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
|
1483 |
can be reconstructed with #decodeAsLiteralArray. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1484 |
The encoding is: |
8246 | 1485 |
(#Timestamp YYYYMMDDhhmmss.iii) |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1486 |
" |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1487 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1488 |
|s| |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1489 |
|
8223
56da5d8f8bc1
replaced '' writeStream by String writeStream
Claus Gittinger <cg@exept.de>
parents:
8111
diff
changeset
|
1490 |
s := WriteStream on:(String new:18). |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1491 |
self printGeneralizedOn:s isLocal:true. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1492 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1493 |
^ Array |
9416 | 1494 |
with:self class name |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1495 |
with:s contents |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1496 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1497 |
" |
9416 | 1498 |
Timestamp now literalArrayEncoding |
1499 |
decodeAsLiteralArray |
|
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1500 |
" |
7006 | 1501 |
! |
1502 |
||
1503 |
utcSecondsSince1901 |
|
1504 |
"return the number of seconds elapsed since Jan, 1st 1901" |
|
1505 |
||
9430
919e0cb2257c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
9416
diff
changeset
|
1506 |
" |
919e0cb2257c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
9416
diff
changeset
|
1507 |
secondsBetween1901and1970 := |
919e0cb2257c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
9416
diff
changeset
|
1508 |
((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
|
1509 |
* (24 * 60 * 60) |
919e0cb2257c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
9416
diff
changeset
|
1510 |
" |
7006 | 1511 |
|
9449
6ba774be6aa1
stc can compile large integers!
Stefan Vogel <sv@exept.de>
parents:
9433
diff
changeset
|
1512 |
^ self utcSecondsSince1970 + 2177452800. |
7006 | 1513 |
|
1514 |
" |
|
8246 | 1515 |
Timestamp now utcSecondsSince1901 |
7006 | 1516 |
" |
699 | 1517 |
! ! |
1518 |
||
17847 | 1519 |
!Timestamp methodsFor:'double dispatching'! |
1520 |
||
1521 |
differenceFromTimestamp:aTimestamp |
|
1522 |
"/ the correct thing to do (and I will, in the future) is to |
|
1523 |
"/ return a TimeDuration: |
|
1524 |
"/ |
|
1525 |
"/ ^ TimeDuration fromMilliseconds:(self getMilliseconds - (aTimestamp getMilliseconds)) |
|
1526 |
"/ which is the same as: deltaFrom:aTimestamp |
|
1527 |
"/ |
|
1528 |
"/ however, there might me old code around, which might not be prepared for |
|
1529 |
"/ getting a non-number (the seconds). Therefore, for the meantime, |
|
1530 |
"/ we return: |
|
1531 |
||
1532 |
^ aTimestamp getSeconds - self getSeconds |
|
1533 |
"/ which is the same as: secondDeltaFrom:aTimestamp |
|
1534 |
||
1535 |
"/ be prepared for a change here. |
|
1536 |
||
1537 |
"Created: / 01-08-2011 / 16:38:10 / cg" |
|
1538 |
! ! |
|
1539 |
||
17815 | 1540 |
!Timestamp methodsFor:'initialization'! |
1541 |
||
1542 |
year:y month:m day:d hour:h minute:min second:s millisecond:millis |
|
1543 |
osTime := OperatingSystem |
|
1544 |
computeOSTimeFromYear:y |
|
1545 |
month:m |
|
1546 |
day:d |
|
1547 |
hour:h |
|
1548 |
minute:min |
|
1549 |
seconds:s |
|
1550 |
millis:millis |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1551 |
! ! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1552 |
|
17847 | 1553 |
|
8246 | 1554 |
!Timestamp methodsFor:'printing & storing'! |
30 | 1555 |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7817
diff
changeset
|
1556 |
addPrintBindingsTo:dict language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7817
diff
changeset
|
1557 |
"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
|
1558 |
languageOrNil can only be #en or nil for the current language." |
5726 | 1559 |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7817
diff
changeset
|
1560 |
self asDate addPrintBindingsTo:dict language:languageOrNil. |
6795
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6686
diff
changeset
|
1561 |
|
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6686
diff
changeset
|
1562 |
self year == Date today year ifTrue:[ |
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6686
diff
changeset
|
1563 |
dict at:#yearOrTime put:(self asTime printStringFormat:'%h:%m'). |
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6686
diff
changeset
|
1564 |
]. |
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6686
diff
changeset
|
1565 |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7817
diff
changeset
|
1566 |
super addPrintBindingsTo:dict language:languageOrNil. |
4843 | 1567 |
! |
1568 |
||
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1569 |
printGeneralizedOn:aStream |
5290 | 1570 |
"append a representation of the receiver to aStream in a general format, |
9385 | 1571 |
top-down, without separators: 'yyyymmddHHMMSS.mmm+0100' |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1572 |
|
5290 | 1573 |
This format is used for the ASN.1 GeneralizedTime as defined in X.208 Sec. 33, |
1574 |
so read this before changing the output format." |
|
1575 |
||
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1576 |
^ self printGeneralizedOn:aStream isLocal:false short:false. |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1577 |
! |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1578 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1579 |
printGeneralizedOn:aStream isLocal:isLocal |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1580 |
"append a representation of the receiver to aStream in a general format, |
11177 | 1581 |
top-down, without separators: 'yyyymmddHHMMSS.mmm+0100' |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1582 |
|
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1583 |
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
|
1584 |
so read this before changing the output format. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1585 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1586 |
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
|
1587 |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1588 |
self printGeneralizedOn:aStream isLocal:isLocal short:false |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1589 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1590 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1591 |
"Modified: / 1.7.1996 / 15:20:59 / cg" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1592 |
"Modified: / 17.1.2000 / 15:53:02 / stefan" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1593 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1594 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1595 |
printGeneralizedOn:aStream isLocal:isLocal short:shortFormat |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1596 |
"append a representation of the receiver to aStream in a general format, |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1597 |
top-down, without separators; |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1598 |
long format: 'yyyymmddHHMMSS.mmm+0100' |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1599 |
short format: 'yymmddHHMMSS.mmm+0100' |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1600 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1601 |
This format is used for the ASN.1 GeneralizedTime and UTCTime |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1602 |
as defined in X.208 Sec. 33, so read this before changing the output format. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1603 |
The short format is no longer recommended. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1604 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1605 |
If isLocal is true, represent as local time, otherwise add UTC time offset." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1606 |
|
5290 | 1607 |
|t off| |
1608 |
||
17757 | 1609 |
isLocal ifTrue:[ |
17815 | 1610 |
t := self timeInfo. |
17757 | 1611 |
] ifFalse:[ |
17815 | 1612 |
t := self asUtcTimestamp timeInfo. |
17757 | 1613 |
]. |
1614 |
||
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1615 |
shortFormat ifTrue:[ |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1616 |
self assert:(t year between:1951 and:2049). |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1617 |
(t year \\ 100) printOn:aStream leftPaddedTo:2 with:$0. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1618 |
] ifFalse:[ |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1619 |
t year printOn:aStream leftPaddedTo:4 with:$0. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1620 |
]. |
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
1621 |
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
|
1622 |
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
|
1623 |
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
|
1624 |
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
|
1625 |
t seconds printOn:aStream leftPaddedTo:2 with:$0. |
5290 | 1626 |
aStream nextPut:$.. |
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
1627 |
t milliseconds printOn:aStream leftPaddedTo:3 with:$0. |
5290 | 1628 |
|
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1629 |
isLocal ifFalse:[ |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1630 |
"/ this should be printed as non-local-time |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1631 |
|
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
1632 |
off := t utcOffset. |
17815 | 1633 |
(self isUtcTimestamp or:[off == 0]) ifTrue:[ |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1634 |
aStream nextPut:$Z. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1635 |
] ifFalse:[ |min| |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1636 |
off < 0 ifTrue:[ |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1637 |
aStream nextPut:$+. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1638 |
off := off negated. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1639 |
] ifFalse:[ |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1640 |
aStream nextPut:$-. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1641 |
]. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1642 |
min := off // 60. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1643 |
min // 60 printOn:aStream leftPaddedTo:2 with:$0. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
1644 |
min \\ 60 printOn:aStream leftPaddedTo:2 with:$0. |
5290 | 1645 |
]. |
1646 |
]. |
|
1647 |
||
1648 |
" |
|
8246 | 1649 |
Timestamp now printGeneralizedOn:Transcript. Transcript cr. |
17757 | 1650 |
Timestamp now printGeneralizedOn:Transcript isLocal:true. Transcript cr. |
8246 | 1651 |
(Timestamp fromSeconds:0) printGeneralizedOn:Transcript. Transcript cr. |
5290 | 1652 |
Time now printOn:Transcript. Transcript cr. |
1653 |
Date today printOn:Transcript. Transcript cr. |
|
1654 |
||
17815 | 1655 |
Timestamp now printGeneralizedOn:Transcript isLocal:false short:false. Transcript cr. |
1656 |
UtcTimestamp now printGeneralizedOn:Transcript isLocal:false short:false. Transcript cr. |
|
5290 | 1657 |
|
8246 | 1658 |
Date today asTimestamp printGeneralizedOn:Transcript. Transcript cr. |
5290 | 1659 |
Date today printOn:Transcript. Transcript cr. |
1660 |
" |
|
1661 |
||
1662 |
"Modified: / 1.7.1996 / 15:20:59 / cg" |
|
1663 |
"Modified: / 17.1.2000 / 15:53:02 / stefan" |
|
1664 |
! |
|
1665 |
||
17815 | 1666 |
printISO8601 |
1667 |
||
1668 |
^ TimestampISO8601Builder print: self |
|
1669 |
||
1670 |
" |
|
1671 |
Timestamp now printISO8601 |
|
1672 |
" |
|
1673 |
||
1674 |
"Created: / 16-06-2005 / 16:11:15 / masca" |
|
1675 |
! |
|
1676 |
||
1677 |
printISO8601Compressed |
|
1678 |
||
1679 |
^ TimestampISO8601Builder printCompressed: self |
|
1680 |
||
1681 |
" |
|
1682 |
Timestamp now printISO8601Compressed |
|
1683 |
" |
|
1684 |
||
1685 |
"Created: / 16-06-2005 / 16:11:31 / masca" |
|
1686 |
! |
|
1687 |
||
1688 |
printISO8601CompressedOn: aStream |
|
1689 |
||
1690 |
TimestampISO8601Builder printCompressed: self on: aStream |
|
1691 |
||
1692 |
"Created: / 16-06-2005 / 16:11:50 / masca" |
|
1693 |
! |
|
1694 |
||
1695 |
printISO8601On: aStream |
|
1696 |
||
1697 |
TimestampISO8601Builder print: self on: aStream |
|
1698 |
||
1699 |
"Created: / 16-06-2005 / 16:11:07 / masca" |
|
1700 |
! |
|
1701 |
||
8479 | 1702 |
printIso8601FormatOn:aStream |
17815 | 1703 |
"append the iso8601 representation of the receiver to aStream. |
8479 | 1704 |
This format looks like: |
1705 |
1999-01-01T24:00:00 |
|
1706 |
or, for zero hr:min:sec, |
|
1707 |
1999-01-01 |
|
17815 | 1708 |
Of course, a 24 hour clock is used. |
1709 |
||
1710 |
No timezone information (eg. Z or +0100) is added, so the reader will read as local time." |
|
8479 | 1711 |
|
1712 |
|format| |
|
1713 |
||
1714 |
format := '%(year)-%(month)-%(day)T%h:%m:%s.%i'. |
|
1715 |
self milliseconds = 0 ifTrue:[ |
|
1716 |
format := '%(year)-%(month)-%(day)T%h:%m:%s'. |
|
1717 |
self seconds = 0 ifTrue:[ |
|
1718 |
format := '%(year)-%(month)-%(day)T%h:%m'. |
|
1719 |
((self hours = 0) and:[self minutes = 0]) ifTrue:[ |
|
1720 |
format := '%(year)-%(month)-%(day)'. |
|
1721 |
] |
|
1722 |
] |
|
1723 |
]. |
|
1724 |
self printOn:aStream format:format |
|
1725 |
||
1726 |
" |
|
1727 |
Timestamp now printIso8601FormatOn:Transcript |
|
1728 |
Timestamp readIso8601FormatFrom:(Timestamp now printStringIso8601Format). |
|
1729 |
" |
|
1730 |
! |
|
1731 |
||
241 | 1732 |
printOn:aStream |
275 | 1733 |
"append a user readable representation of the receiver to aStream. |
1734 |
The format is compatible with readFromString:, but not with readFrom:." |
|
1735 |
||
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
1736 |
"/ now, use ISO format... |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
1737 |
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
|
1738 |
"/ self printOn:aStream format:'%(Day)-%(mon)-%(year) %h:%m:%s.%i' |
5678 | 1739 |
"/ self printOn:aStream format:'%(mon)/%(Day)/%(year) %h:%m:%s.%i' |
92 | 1740 |
|
1741 |
" |
|
8246 | 1742 |
Timestamp now printOn:Transcript. Transcript cr. |
1743 |
(Timestamp fromSeconds:0) printOn:Transcript. Transcript cr. |
|
275 | 1744 |
Time now printOn:Transcript. Transcript cr. |
1745 |
Date today printOn:Transcript. Transcript cr. |
|
1501 | 1746 |
|
8246 | 1747 |
Time now asTimestamp printOn:Transcript. Transcript cr. |
1748 |
Timestamp now printOn:Transcript. Transcript cr. |
|
1501 | 1749 |
|
8246 | 1750 |
Date today asTimestamp printOn:Transcript. Transcript cr. |
1501 | 1751 |
Date today printOn:Transcript. Transcript cr. |
92 | 1752 |
" |
1501 | 1753 |
|
5719
cf09067dbd1d
can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents:
5678
diff
changeset
|
1754 |
"Modified: 1.7.1996 / 15:20:59 / cg" |
cf09067dbd1d
can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents:
5678
diff
changeset
|
1755 |
! |
30 | 1756 |
|
7474 | 1757 |
printRFC1123FormatOn:aStream |
1758 |
"append the RFC1123 representation of the receiver to aStream. |
|
1759 |
This format is used in HTTP requests and looks like: |
|
7671 | 1760 |
'Fri, 04 Jul 2003 15:56:11 GMT' |
1761 |
(always GMT and all names in english)" |
|
1762 |
||
1763 |
"/ HTTP-date = rfc1123-date | rfc850-date | asctime-date |
|
1764 |
"/ |
|
1765 |
"/ rfc1123-date = wkday "," SP date1 SP time SP "GMT" |
|
1766 |
"/ rfc850-date = weekday "," SP date2 SP time SP "GMT" |
|
1767 |
"/ asctime-date = wkday SP date3 SP time SP 4DIGIT |
|
1768 |
"/ |
|
1769 |
"/ date1 = 2DIGIT SP month SP 4DIGIT |
|
1770 |
"/ ; day month year (e.g., 02 Jun 1982) |
|
1771 |
"/ date2 = 2DIGIT "-" month "-" 2DIGIT |
|
1772 |
"/ ; day-month-year (e.g., 02-Jun-82) |
|
1773 |
"/ date3 = month SP ( 2DIGIT | ( SP 1DIGIT )) |
|
1774 |
"/ ; month day (e.g., Jun 2) |
|
1775 |
"/ |
|
1776 |
"/ time = 2DIGIT ":" 2DIGIT ":" 2DIGIT |
|
1777 |
"/ ; 00:00:00 - 23:59:59 |
|
1778 |
"/ |
|
1779 |
"/ wkday = "Mon" | "Tue" | "Wed" |
|
1780 |
"/ | "Thu" | "Fri" | "Sat" | "Sun" |
|
1781 |
"/ |
|
1782 |
"/ weekday = "Monday" | "Tuesday" | "Wednesday" |
|
1783 |
"/ | "Thursday" | "Friday" | "Saturday" | "Sunday" |
|
1784 |
"/ |
|
1785 |
"/ month = "Jan" | "Feb" | "Mar" | "Apr" |
|
1786 |
"/ | "May" | "Jun" | "Jul" | "Aug" |
|
1787 |
"/ | "Sep" | "Oct" | "Nov" | "Dec" |
|
7474 | 1788 |
|
17815 | 1789 |
|timeInfo| |
1790 |
||
1791 |
timeInfo := self asUtcTimestamp timeInfo. |
|
7474 | 1792 |
|
7734 | 1793 |
aStream nextPutAll:(#('Mon' 'Tue' 'Wed' 'Thu' 'Fri' 'Sat' 'Sun') at:timeInfo dayInWeek); |
7671 | 1794 |
nextPutAll:', '. |
7734 | 1795 |
timeInfo day printOn:aStream leftPaddedTo:2 with:$0. |
7671 | 1796 |
aStream space. |
7734 | 1797 |
aStream nextPutAll:(#('Jan' 'Feb' 'Mar' 'Apr' 'May' 'Jun' 'Jul' 'Aug' 'Sep' 'Oct' 'Nov' 'Dec') at:timeInfo month). |
7671 | 1798 |
|
7677 | 1799 |
"/ the following is too slow for heavy use |
17815 | 1800 |
"/ timeInfo printOn:aStream format:'%(ShortDayName), %(day) %(ShortMonthName) %y %h:%m:%s GMT' language:#en. |
7677 | 1801 |
|
1802 |
aStream nextPut:Character space. |
|
7734 | 1803 |
timeInfo year printOn:aStream. |
7677 | 1804 |
aStream nextPut:Character space. |
7734 | 1805 |
timeInfo hours printOn:aStream leftPaddedTo:2 with:$0. |
7677 | 1806 |
aStream nextPut:$:. |
7734 | 1807 |
timeInfo minutes printOn:aStream leftPaddedTo:2 with:$0. |
7677 | 1808 |
aStream nextPut:$:. |
7734 | 1809 |
timeInfo seconds printOn:aStream leftPaddedTo:2 with:$0. |
7677 | 1810 |
aStream nextPutAll:' GMT'. |
1811 |
||
7474 | 1812 |
" |
17815 | 1813 |
String streamContents:[:s| Timestamp now printRFC1123FormatOn:s] |
7474 | 1814 |
" |
1815 |
! |
|
1816 |
||
8479 | 1817 |
printStringIso8601Format |
1818 |
"return the Iso8601 representation of the receiver. |
|
1819 |
This format looks like: |
|
1820 |
1999-01-01T24:00:00 |
|
1821 |
or, for zero hr:min:sec, |
|
1822 |
1999-01-01 |
|
1823 |
Of course, a 24 hour clock is used." |
|
1824 |
||
1825 |
^ String streamContents:[:s | self printIso8601FormatOn:s] |
|
1826 |
||
1827 |
" |
|
1828 |
Timestamp now printStringIso8601Format |
|
1829 |
" |
|
1830 |
! |
|
1831 |
||
7474 | 1832 |
printStringRFC1123Format |
1833 |
"return the RFC1123 representation of the receiver. |
|
1834 |
This format is used in HTTP requests and looks like: |
|
7671 | 1835 |
'Fri, 04 Jul 2003 15:56:11 GMT' |
7474 | 1836 |
(always GMT)" |
1837 |
||
1838 |
^ String streamContents:[:s | self printRFC1123FormatOn:s] |
|
1839 |
||
1840 |
" |
|
8246 | 1841 |
Timestamp now printStringRFC1123Format |
7474 | 1842 |
" |
1843 |
! |
|
1844 |
||
241 | 1845 |
storeOn:aStream |
275 | 1846 |
"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
|
1847 |
receiver via readFrom: |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1848 |
Use a OS/architecture independent format" |
275 | 1849 |
|
241 | 1850 |
aStream nextPut:$(; |
8246 | 1851 |
nextPutAll:self class name; |
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1852 |
nextPutAll:' readIso8601FormatFrom:'''. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1853 |
self printIso8601FormatOn:aStream. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1854 |
aStream nextPutAll:''')'. |
54 | 1855 |
|
241 | 1856 |
" |
8246 | 1857 |
Timestamp now storeString |
30 | 1858 |
|
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1859 |
Object readFrom:(Timestamp now storeString) readStream |
8246 | 1860 |
Timestamp readFrom:(Timestamp now storeString) readStream |
241 | 1861 |
" |
30 | 1862 |
! ! |
699 | 1863 |
|
8246 | 1864 |
!Timestamp methodsFor:'private'! |
699 | 1865 |
|
1501 | 1866 |
fromOSTime:anUninterpretedOSTime |
699 | 1867 |
"strictly private: set the seconds from an OS time (since whatever)" |
1868 |
||
1501 | 1869 |
osTime := anUninterpretedOSTime |
1870 |
||
1871 |
"Created: 1.7.1996 / 14:33:21 / cg" |
|
1872 |
! |
|
1873 |
||
1874 |
getMilliseconds |
|
1875 |
"strictly private: return the milliseconds (since whatever)" |
|
1876 |
||
1877 |
^ osTime |
|
1878 |
||
1879 |
"Created: 1.7.1996 / 14:33:56 / cg" |
|
699 | 1880 |
! |
1881 |
||
1882 |
getSeconds |
|
1883 |
"strictly private: return the seconds (since whatever)" |
|
1884 |
||
1501 | 1885 |
^ osTime // 1000 |
699 | 1886 |
! |
1887 |
||
1501 | 1888 |
setMilliseconds:millis |
1889 |
"strictly private: set the milliseconds (since whatever)" |
|
1890 |
||
1891 |
osTime := millis. |
|
1892 |
||
1893 |
"Modified: 20.12.1995 / 11:46:36 / stefan" |
|
1894 |
"Created: 1.7.1996 / 14:34:24 / cg" |
|
1895 |
! |
|
1896 |
||
699 | 1897 |
setSeconds:secs |
1898 |
"strictly private: set the seconds (since whatever)" |
|
1899 |
||
1501 | 1900 |
osTime := secs * 1000. |
795 | 1901 |
|
1902 |
"Modified: 20.12.1995 / 11:46:36 / stefan" |
|
1501 | 1903 |
"Modified: 1.7.1996 / 14:34:10 / cg" |
5853 | 1904 |
! |
1905 |
||
1906 |
utcSecondsSince1970 |
|
1907 |
"return the UTC seconds since 1970" |
|
1908 |
||
9430
919e0cb2257c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
9416
diff
changeset
|
1909 |
^ self getSeconds |
5853 | 1910 |
|
1911 |
" |
|
8246 | 1912 |
Timestamp now utcSecondsSince1970 |
5853 | 1913 |
" |
699 | 1914 |
! ! |
1915 |
||
17862 | 1916 |
|
1917 |
||
17815 | 1918 |
!Timestamp methodsFor:'testing'! |
1919 |
||
1920 |
isTimestamp |
|
1921 |
^ true |
|
1922 |
! |
|
1923 |
||
1924 |
isUtcTimestamp |
|
1925 |
^ false |
|
1926 |
! ! |
|
1927 |
||
8396
b13503dbc53c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8286
diff
changeset
|
1928 |
!Timestamp methodsFor:'visiting'! |
b13503dbc53c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8286
diff
changeset
|
1929 |
|
b13503dbc53c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8286
diff
changeset
|
1930 |
acceptVisitor:aVisitor with:aParameter |
b13503dbc53c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8286
diff
changeset
|
1931 |
^ aVisitor visitTimestamp:self with:aParameter |
b13503dbc53c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8286
diff
changeset
|
1932 |
! ! |
b13503dbc53c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8286
diff
changeset
|
1933 |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1934 |
!Timestamp::TimestampBuilderAbstract methodsFor:'error reporting'! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1935 |
|
17815 | 1936 |
malformed:aString |
1937 |
TimeConversionError raiseErrorString:(' - ', aString) |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1938 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1939 |
"Created: / 15-06-2005 / 15:54:04 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1940 |
! ! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1941 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1942 |
!Timestamp::TimestampBuilderAbstract methodsFor:'support'! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1943 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1944 |
addHoursAndMinutes: arrayWithHoursAndMinutes |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1945 |
"Add the given number of hours and minutes to the current timestamp state. If the time |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1946 |
is to be subtracted, both numbers in the array must be negated. When the are not the same |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1947 |
sign, the behavior may be strange. It's intended only for time zone corrections, where |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1948 |
not more than 12 (in fact, 23) hours is added or subtracted (ie. date can be modified only |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1949 |
one day forward or backward)." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1950 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1951 |
| hours minutes | |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1952 |
hours := arrayWithHoursAndMinutes first. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1953 |
minutes := arrayWithHoursAndMinutes second. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1954 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1955 |
minutes isZero ifFalse: [ |
17815 | 1956 |
minute := minute + minutes. |
1957 |
minute >= 60 ifTrue: [ |
|
1958 |
hours := hours + minute // 60. |
|
1959 |
minute := minute \\ 60. |
|
1960 |
]. |
|
1961 |
minute < 0 ifTrue: [ |
|
1962 |
hours := hours + minute // 60. |
|
1963 |
minute := (minute \\ 60) negated |
|
1964 |
] |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1965 |
]. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1966 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1967 |
"Hours may get zero by time zone specification or by minutes modifications above." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1968 |
hours isZero ifTrue: [^self]. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1969 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1970 |
"Add or subtract the hour and make date corrections if necessary." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1971 |
hour := hour + hours. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1972 |
hour < 0 ifTrue: [ |
17815 | 1973 |
"Oops, got to previous day, must adjust even the date." |
1974 |
hour := 24 - ((hour negated) \\ 24). |
|
1975 |
day := day - 1. |
|
1976 |
day <= 0 ifTrue: [ |
|
1977 |
"Got to previous month..." |
|
1978 |
month := month - 1. |
|
1979 |
month <= 0 ifTrue: [year := year - 1. month := 12]. |
|
1980 |
day := self lastDayInMonth: month] |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1981 |
]. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1982 |
hour >= 24 ifTrue: [ |
17815 | 1983 |
hour := hour \\ 24. |
1984 |
day := day + 1. |
|
1985 |
day > (self lastDayInMonth: month) ifTrue: [ |
|
1986 |
month := month + 1. |
|
1987 |
month > 12 ifTrue: [year := year + 1. month := 1]. |
|
1988 |
day := 1] |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1989 |
] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1990 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1991 |
"Created: / 15-06-2005 / 16:45:49 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1992 |
"Modified: / 16-06-2005 / 15:04:45 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1993 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1994 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1995 |
dateFromDayNumber: anInteger |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1996 |
"Set month and day from an absolute number of the day in the year. 1.1. is day number one." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1997 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1998 |
| leap | |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
1999 |
leap := self isLeapYear: year. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2000 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2001 |
(anInteger between: 1 and: 365) ifFalse: [ |
17815 | 2002 |
(leap and: [anInteger = 366]) |
2003 |
ifFalse: [self malformed: 'Bad day number: ' , anInteger printString] |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2004 |
]. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2005 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2006 |
self shouldImplement |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2007 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2008 |
"Created: / 15-06-2005 / 11:27:35 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2009 |
"Modified: / 16-06-2005 / 12:31:37 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2010 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2011 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2012 |
dateFromWeek: weekInteger andWeekday: dayInteger |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2013 |
"Compute the month and day. Find the first day (weekday) in the year, maybe even |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2014 |
adjust the year. Both week and day are 1-based, the first week in a year is the one |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2015 |
with thursday (or the one containing 4.1.)." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2016 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2017 |
"Check numbers. Year may be checked if it contains 53 weeks or 52 weeks only." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2018 |
(dayInteger between: 1 and: 7) ifFalse: [self malformed: 'Bad weekday number: ' , dayInteger printString]. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2019 |
(weekInteger between: 1 and: 53) ifFalse: [self malformed: 'Bad week number: ' , weekInteger printString]. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2020 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2021 |
self shouldImplement |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2022 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2023 |
"Created: / 15-06-2005 / 11:29:42 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2024 |
"Modified: / 15-06-2005 / 16:42:33 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2025 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2026 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2027 |
isAllowedDay: anInteger |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2028 |
"Answer whether the given day is allowed in the current month." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2029 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2030 |
^anInteger between: 1 and: (self lastDayInMonth: month) |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2031 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2032 |
"Created: / 15-06-2005 / 16:22:51 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2033 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2034 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2035 |
isLeapYear: anInteger |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2036 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2037 |
^(anInteger bitAnd: 3) = 0 and: [anInteger \\ 100 > 0 or: [anInteger \\ 400 = 0]] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2038 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2039 |
"Created: / 15-06-2005 / 16:16:31 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2040 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2041 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2042 |
lastDayInMonth: anInteger |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2043 |
"Answer the number of the last day of the given month in the current year." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2044 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2045 |
^anInteger = 2 |
17815 | 2046 |
ifTrue: [(self isLeapYear: year) ifTrue: [29] ifFalse: [28]] |
2047 |
ifFalse: [#(31 28 31 30 31 30 31 31 30 31 30 31) at: month] |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2048 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2049 |
"Created: / 15-06-2005 / 17:12:31 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2050 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2051 |
|
17815 | 2052 |
timestampWithClass:timestampClass |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2053 |
"Answer the timestamp as it has been parsed." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2054 |
"Notes: |
17815 | 2055 |
- When reading, the time has either been adjusted to UTZ/zulu time, |
2056 |
or is a local time. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2057 |
- On UNIX, timestamps can only hold dates between 1970-01-01T01:00:00Z and 2038-01-19T00:00:00Z" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2058 |
|
17815 | 2059 |
isUtcTime ifTrue:[ |
2060 |
^ timestampClass |
|
2061 |
UTCYear: year month: month day: day |
|
2062 |
hour: hour minute: minute second: second millisecond: millisecond |
|
2063 |
] ifFalse:[ |
|
2064 |
^ timestampClass |
|
2065 |
year: year month: month day: day |
|
2066 |
hour: hour minute: minute second: second millisecond: millisecond |
|
2067 |
] |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2068 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2069 |
"Created: / 15-06-2005 / 15:39:24 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2070 |
"Modified: / 30-06-2005 / 16:48:25 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2071 |
! ! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2072 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2073 |
!Timestamp::TimestampISO8601Builder class methodsFor:'documentation'! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2074 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2075 |
documentation |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2076 |
" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2077 |
TimestampISO8601Builder is designed to read any (almost) format of ISO 8601 encoded timestamp. Also, class |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2078 |
methods can be used to print but the main reading job is done in instance protocol. It has been |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2079 |
written because of insufficient abilities of Timestamp #readIso8601FormatFrom: method. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2080 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2081 |
It produces timestamps, ie. when the string (or stream) contains only a time, an error will result |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2082 |
(it may also pass in some cases but with the time undestood as date). It survives incomplete dates, |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2083 |
broken years, incomplete times and timezones. All times read with timezone difference are recomputed |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2084 |
to UTC before the timestamp is created (even passing across new year boundary is handled correctly). |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2085 |
Unknown offsets (usually local) are considered UTC - this may be wrong and more work is probably needed. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2086 |
All data is checked for validity (including leap years, leap seconds,...) during reading and as soon as |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2087 |
possible. For an example of what the builder can read, see the examples method and ISO 8601 itself. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2088 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2089 |
[author:] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2090 |
Martin Dvorak (masca@volny.cz) |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2091 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2092 |
[instance variables:] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2093 |
stream A stream the builder operates on. Assigned on each call to instance method #read:, |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2094 |
so the builder instance can be reused (by at most one thread). |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2095 |
year Current timestamp year. No default value, date must be present. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2096 |
month Current timestamp month. May change during parsing. Defaults to 1. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2097 |
day Current timestamp day. Defaults to 1. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2098 |
hour Current timestamp hour. Defaults to 0. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2099 |
minute Current timestamp minute. Defaults to 0. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2100 |
second Current timestamp second. Defaults to 0. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2101 |
millisecond Current timestamp millisecond. Defaults to 0. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2102 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2103 |
[see also:] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2104 |
Timestamp |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2105 |
" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2106 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2107 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2108 |
examples |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2109 |
" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2110 |
See the testing protocol on instance protocol (should be turned into a TestCase). |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2111 |
It covers the main features this builder has. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2112 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2113 |
Just to introduce some coding examples, try: |
17815 | 2114 |
Timestamp readISO8601From: (TimestampISO8601Builder print: Timestamp now) |
2115 |
UtcTimestamp readISO8601From: (TimestampISO8601Builder print: UtcTimestamp now) |
|
2116 |
Timestamp readISO8601From: (TimestampISO8601Builder print: UtcTimestamp now) |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2117 |
" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2118 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2119 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2120 |
history |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2121 |
"Created: / 16-06-2005 / 16:28:38 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2122 |
! ! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2123 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2124 |
!Timestamp::TimestampISO8601Builder class methodsFor:'parsing'! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2125 |
|
17815 | 2126 |
read: stringOrStream withClass:timestampClass |
2127 |
^ self new read:stringOrStream withClass:timestampClass |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2128 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2129 |
"Created: / 15-06-2005 / 17:52:03 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2130 |
! ! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2131 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2132 |
!Timestamp::TimestampISO8601Builder class methodsFor:'printing'! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2133 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2134 |
print: aTimestamp |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2135 |
"Print the given timestamp in general ISO8601 format." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2136 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2137 |
| stream | |
17815 | 2138 |
stream := '' writeStream. |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2139 |
self print: aTimestamp on: stream. |
17815 | 2140 |
^ stream contents |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2141 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2142 |
"Created: / 15-06-2005 / 17:52:29 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2143 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2144 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2145 |
print: aTimestamp on: aStream |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2146 |
"Print the given timestamp in general ISO8601 format." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2147 |
|
17815 | 2148 |
|timeInfo| |
2149 |
||
2150 |
timeInfo := aTimestamp asUtcTimestamp timeInfo. |
|
2151 |
||
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2152 |
aStream |
17815 | 2153 |
nextPutAll: (timeInfo year printStringRadix: 10 size: 4 fill: $0); |
2154 |
nextPut: $-; |
|
2155 |
nextPutAll: (timeInfo month printStringRadix: 10 size: 2 fill: $0); |
|
2156 |
nextPut: $-; |
|
2157 |
nextPutAll: (timeInfo day printStringRadix: 10 size: 2 fill: $0); |
|
2158 |
nextPut: $T; |
|
2159 |
nextPutAll: (timeInfo hours printStringRadix: 10 size: 2 fill: $0); |
|
2160 |
nextPut: $:; |
|
2161 |
nextPutAll: (timeInfo minutes printStringRadix: 10 size: 2 fill: $0); |
|
2162 |
nextPut: $:; |
|
2163 |
nextPutAll: (timeInfo seconds printStringRadix: 10 size: 2 fill: $0); |
|
2164 |
nextPut: $Z |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2165 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2166 |
"Created: / 15-06-2005 / 17:56:51 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2167 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2168 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2169 |
printCompressed: aTimestamp |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2170 |
"Print in special compressed format for timestamp interchange with mobile devices." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2171 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2172 |
| stream | |
17815 | 2173 |
stream := '' writeStream. |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2174 |
self printCompressed: aTimestamp on: stream. |
17815 | 2175 |
^ stream contents |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2176 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2177 |
"Created: / 15-06-2005 / 17:52:52 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2178 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2179 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2180 |
printCompressed: aTimestamp on: aStream |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2181 |
|
17815 | 2182 |
|timeInfo| |
2183 |
||
2184 |
timeInfo := aTimestamp asUtcTimestamp timeInfo. |
|
2185 |
||
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2186 |
aStream |
17815 | 2187 |
nextPutAll: (timeInfo year printStringRadix: 10 size: 4 fill: $0); |
2188 |
nextPutAll: (timeInfo month printStringRadix: 10 size: 2 fill: $0); |
|
2189 |
nextPutAll: (timeInfo day printStringRadix: 10 size: 2 fill: $0); |
|
2190 |
nextPut: $T; |
|
2191 |
nextPutAll: (timeInfo hours printStringRadix: 10 size: 2 fill: $0); |
|
2192 |
nextPutAll: (timeInfo minutes printStringRadix: 10 size: 2 fill: $0); |
|
2193 |
nextPutAll: (timeInfo seconds printStringRadix: 10 size: 2 fill: $0); |
|
2194 |
nextPut: $Z |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2195 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2196 |
"Created: / 15-06-2005 / 17:54:17 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2197 |
! ! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2198 |
|
17815 | 2199 |
!Timestamp::TimestampISO8601Builder class methodsFor:'testing'! |
2200 |
||
2201 |
test |
|
2202 |
||
2203 |
self test_date. |
|
2204 |
self test_time. |
|
2205 |
self test_timezone. |
|
2206 |
self test_edge. |
|
2207 |
||
2208 |
" |
|
2209 |
TimestampISO8601Builder test |
|
2210 |
" |
|
2211 |
||
2212 |
"Created: / 15-06-2005 / 17:51:16 / masca" |
|
2213 |
"Modified: / 16-06-2005 / 10:15:55 / masca" |
|
2214 |
! |
|
2215 |
||
2216 |
test_date |
|
2217 |
||
2218 |
| ts | |
|
2219 |
ts := UtcTimestamp |
|
2220 |
year: 2005 month: 6 day: 15 |
|
2221 |
hour: 0 minute: 0 second: 0 millisecond: 0. |
|
2222 |
||
2223 |
"Test common dates" |
|
2224 |
self assert: ts = (self read: '20050615' withClass:Timestamp). |
|
2225 |
self assert: ts = (self read: '2005-06-15' withClass:Timestamp). |
|
2226 |
self assert: ts = (self read: '05-06-15' withClass:Timestamp). |
|
2227 |
self assert: ts = (self read: '05-0615' withClass:Timestamp). "/ Is this correct? |
|
2228 |
self assert: ts = (self read: ':50615' withClass:Timestamp). "/ Should not happen and should not appear after 2009 |
|
2229 |
self assert: ts = (self read: '200506-15' withClass:Timestamp). "/ Is this corect? |
|
2230 |
self assert: ts = (self read: '105-06-15' withClass:Timestamp). "/ Should not happen |
|
2231 |
||
2232 |
"Test week numbers" |
|
2233 |
"/self assert: ts = (self read: '05W243' withClass:Timestamp). |
|
2234 |
"/self assert: ts = (self read: '2005W24-3' withClass:Timestamp). |
|
2235 |
||
2236 |
"Test day numbers" |
|
2237 |
"self assert: ts = (self read: '2005-166' withClass:Timestamp). |
|
2238 |
||
2239 |
ts := Timestamp year: 2004 month: 12 day: 31 hour: 0 minute: 0 second: 0 millisecond: 0. |
|
2240 |
self assert: ts = (self read: '2004-366' withClass:Timestamp). |
|
2241 |
||
2242 |
ts := Timestamp year: 2005 month: 12 day: 31 hour: 0 minute: 0 second: 0 millisecond: 0. |
|
2243 |
self assert: ts = (self read: '2004-365' withClass:Timestamp)." |
|
2244 |
||
2245 |
"Test february" |
|
2246 |
ts := UtcTimestamp year: 2000 month: 2 day: 28 hour: 0 minute: 0 second: 0 millisecond: 0. |
|
2247 |
self assert: ts = (self read: '20000228' withClass:Timestamp). |
|
2248 |
||
2249 |
ts := UtcTimestamp year: 2000 month: 2 day: 29 hour: 0 minute: 0 second: 0 millisecond: 0. |
|
2250 |
self assert: ts = (self read: '20000229' withClass:Timestamp). |
|
2251 |
||
2252 |
" |
|
2253 |
TimestampISO8601Builder new test_date |
|
2254 |
" |
|
2255 |
||
2256 |
||
2257 |
"Created: / 15-06-2005 / 17:21:56 / masca" |
|
2258 |
"Modified: / 16-06-2005 / 11:50:04 / masca" |
|
2259 |
! |
|
2260 |
||
2261 |
test_edge |
|
2262 |
||
2263 |
| ts | |
|
2264 |
||
2265 |
self test_mustFail: [self read: '20050229' withClass:Timestamp]. |
|
2266 |
self test_mustFail: [self read: '20050029' withClass:Timestamp]. |
|
2267 |
self test_mustFail: [self read: '20050332' withClass:Timestamp]. |
|
2268 |
self test_mustFail: [self read: '2005-366' withClass:Timestamp]. |
|
2269 |
||
2270 |
ts := UtcTimestamp year: 2005 month: 1 day: 1 hour: 0 minute: 0 second: 0 millisecond: 0. |
|
2271 |
self assert: ts = (self read: '20041231T22-0200' withClass:Timestamp). |
|
2272 |
||
2273 |
ts := UtcTimestamp year: 2004 month: 12 day: 31 hour: 22 minute: 0 second: 0 millisecond: 0. |
|
2274 |
self assert: ts = (self read: '20050101T0000+0200' withClass:Timestamp). |
|
2275 |
||
2276 |
" |
|
2277 |
TimestampISO8601Builder new test_edge |
|
2278 |
" |
|
2279 |
||
2280 |
||
2281 |
"Created: / 16-06-2005 / 09:44:34 / masca" |
|
2282 |
"Modified: / 16-06-2005 / 11:48:59 / masca" |
|
2283 |
! |
|
2284 |
||
2285 |
test_mustFail: aBlock |
|
2286 |
||
2287 |
TimeConversionError |
|
2288 |
handle: [:ex | ex return] |
|
2289 |
do: [ |
|
2290 |
aBlock value. |
|
2291 |
self error: 'Assertion failed' |
|
2292 |
] |
|
2293 |
||
2294 |
"Created: / 16-06-2005 / 09:43:37 / masca" |
|
2295 |
! |
|
2296 |
||
2297 |
test_time |
|
2298 |
||
2299 |
| ts | |
|
2300 |
||
2301 |
ts := UtcTimestamp year: 2005 month: 6 day: 15 hour: 17 minute: 37 second: 0 millisecond: 0. |
|
2302 |
self assert: ts = (self read: '2005-06-15 17:37' withClass:Timestamp). |
|
2303 |
self assert: ts = (self read: '20050615T1737' withClass:Timestamp). |
|
2304 |
self assert: ts = (self read: '05-0615T17:3700' withClass:Timestamp). |
|
2305 |
||
2306 |
ts := UtcTimestamp year: 2005 month: 6 day: 15 hour: 17 minute: 37 second: 0 millisecond: 30. |
|
2307 |
self assert: ts = (self read: '05-0615T17:3700.03' withClass:Timestamp). |
|
2308 |
self assert: ts = (self read: '2005-06-15T17:37:00.0305486-00:00' withClass:Timestamp). |
|
2309 |
||
2310 |
" |
|
2311 |
TimestampISO8601Builder new test_time |
|
2312 |
" |
|
2313 |
||
2314 |
"Created: / 15-06-2005 / 17:39:26 / masca" |
|
2315 |
"Modified: / 16-06-2005 / 11:54:30 / masca" |
|
2316 |
! |
|
2317 |
||
2318 |
test_timezone |
|
2319 |
||
2320 |
| ts | |
|
2321 |
ts := UtcTimestamp |
|
2322 |
year: 2005 month: 6 day: 15 |
|
2323 |
hour: 17 minute: 37 second: 0 millisecond: 0. |
|
2324 |
||
2325 |
self assert: ts = (self read: '2005-06-15T17:37Z' withClass:UtcTimestamp). |
|
2326 |
self assert: ts = (self read: '2005-06-15T17:37+0000' withClass:Timestamp). |
|
2327 |
self assert: ts = (self read: '2005-06-15T17:37-00:00' withClass:Timestamp). |
|
2328 |
self assert: ts = (self read: '2005-06-15T15:37:00-0200' withClass:Timestamp). |
|
2329 |
self assert: ts = (self read: '2005-06-15T19:37:00+0200'withClass:Timestamp). |
|
2330 |
||
2331 |
" |
|
2332 |
TimestampISO8601Builder new test_timezone |
|
2333 |
" |
|
2334 |
||
2335 |
"Created: / 15-06-2005 / 17:40:23 / masca" |
|
2336 |
"Modified: / 16-06-2005 / 10:17:57 / masca" |
|
2337 |
! ! |
|
2338 |
||
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2339 |
!Timestamp::TimestampISO8601Builder methodsFor:'private-reading'! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2340 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2341 |
nextDigit |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2342 |
| char | |
17815 | 2343 |
char := stream peekOrNil. |
2344 |
char isNil ifTrue: [^-1]. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2345 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2346 |
^char isDigit |
17815 | 2347 |
ifTrue: [ |
2348 |
stream next. |
|
2349 |
char codePoint - $0 codePoint] |
|
2350 |
ifFalse: [-1] |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2351 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2352 |
"Created: / 14-06-2005 / 11:48:52 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2353 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2354 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2355 |
nextDigitOrError |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2356 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2357 |
| digit | |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2358 |
digit := self nextDigit. |
17815 | 2359 |
^ digit < 0 |
2360 |
ifTrue: [self malformed: 'No digit found'] |
|
2361 |
ifFalse: [digit] |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2362 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2363 |
"Created: / 15-06-2005 / 10:57:00 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2364 |
"Modified: / 15-06-2005 / 17:22:52 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2365 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2366 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2367 |
nextDigits: anInteger |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2368 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2369 |
| char number | |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2370 |
number := 0. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2371 |
anInteger timesRepeat: [ |
17815 | 2372 |
char := stream peekOrNil. |
2373 |
char ifNil: [self malformed: 'Stream does not contain all ' , anInteger printString , ' digits']. |
|
2374 |
char isDigit |
|
2375 |
ifTrue: [ |
|
2376 |
stream next. |
|
2377 |
number := number * 10 + char codePoint - $0 codePoint] |
|
2378 |
ifFalse: [self malformed: 'Requested ' , anInteger printString , ' digits not found'] |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2379 |
]. |
17815 | 2380 |
^ number |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2381 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2382 |
"Created: / 14-06-2005 / 11:57:22 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2383 |
"Modified: / 15-06-2005 / 15:54:29 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2384 |
! ! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2385 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2386 |
!Timestamp::TimestampISO8601Builder methodsFor:'processing'! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2387 |
|
17815 | 2388 |
read:stringOrStream withClass:timestampClass |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2389 |
| peek | |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2390 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2391 |
stream := stringOrStream readStream. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2392 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2393 |
month := day := 1. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2394 |
hour := minute := second := millisecond := 0. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2395 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2396 |
"Read the year. This will read and swallow up to four year digits." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2397 |
self readYear. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2398 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2399 |
"Check if date has been read, ie. T or space necountered. If yes, read the time. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2400 |
There is possible inconsistency - a dash may be read followed by T, which is not |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2401 |
valid. But don't mind that, timestamps will be well-formatted in most cases." |
17815 | 2402 |
peek := stream peekOrNil. |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2403 |
peek ifNil: [ |
17815 | 2404 |
"End of stream, only year has been read." |
2405 |
^self timestampWithClass:timestampClass]. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2406 |
peek = $- ifTrue: [ |
17815 | 2407 |
"Skip the dash after year, if present." |
2408 |
stream next. |
|
2409 |
peek := stream peekOrNil]. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2410 |
peek := peek asUppercase. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2411 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2412 |
(peek = $T or: [peek = Character space]) |
17815 | 2413 |
ifTrue: [ |
2414 |
"Got time signature. Skip the signature, read time and answer the timestamp." |
|
2415 |
stream next. |
|
2416 |
self readTime. |
|
2417 |
self readTimezone. |
|
2418 |
^ self timestampWithClass:timestampClass] |
|
2419 |
ifFalse: [ |
|
2420 |
"Date not read completely yet, expecting month/day or week/day or day" |
|
2421 |
peek = $W |
|
2422 |
ifTrue: [ |
|
2423 |
"Parse week number and (possibly) day number." |
|
2424 |
stream next. |
|
2425 |
self readWeekNumber] |
|
2426 |
ifFalse: [ |
|
2427 |
"Got digit, read month number followed by day or day number." |
|
2428 |
self readMonthOrDay] |
|
2429 |
]. |
|
2430 |
||
2431 |
peek := stream peekOrNil. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2432 |
peek ifNil: [ |
17815 | 2433 |
"End of stream, only year has been read." |
2434 |
^ self timestampWithClass:timestampClass]. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2435 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2436 |
(peek asUppercase = $T or: [peek = Character space]) |
17815 | 2437 |
ifTrue: [ |
2438 |
"Got time signature, expecting time follows. Otherwise only date was in the stream." |
|
2439 |
stream next. |
|
2440 |
self readTime. |
|
2441 |
self readTimezone]. |
|
2442 |
||
2443 |
^ self timestampWithClass:timestampClass |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2444 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2445 |
"Created: / 14-06-2005 / 11:45:04 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2446 |
"Modified: / 16-06-2005 / 10:15:35 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2447 |
! ! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2448 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2449 |
!Timestamp::TimestampISO8601Builder methodsFor:'reading'! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2450 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2451 |
readMilliseconds |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2452 |
"Read an arbitrary number of digits representing milliseconds. As the timestamp can |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2453 |
hold only integer amounts of milliseconds, don't mind the rest of the digits." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2454 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2455 |
| digit factor | |
17815 | 2456 |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2457 |
factor := 100. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2458 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2459 |
[ |
17815 | 2460 |
digit := self nextDigit. |
2461 |
digit >= 0 |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2462 |
] whileTrue: [ |
17815 | 2463 |
factor > 0 ifTrue: [ |
2464 |
"Factor still > 0, did not read all three digits of mantissa." |
|
2465 |
millisecond := digit * factor + millisecond. |
|
2466 |
factor := (factor / 10) integerPart |
|
2467 |
] |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2468 |
]. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2469 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2470 |
factor = 100 ifTrue: [self malformed: 'No digits after millisecond separator'] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2471 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2472 |
"Created: / 15-06-2005 / 15:25:45 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2473 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2474 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2475 |
readMonthOrDay |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2476 |
"Read month number, optionally followed by day, or absolute day number (three digit)." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2477 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2478 |
| dayDigit1 dayDigit2 | |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2479 |
month := self nextDigits: 2. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2480 |
|
17815 | 2481 |
stream peekOrNil = $- |
2482 |
ifTrue: [ |
|
2483 |
"Got dash. Day number must follow." |
|
2484 |
stream next. |
|
2485 |
day := self nextDigits: 2. |
|
2486 |
(self isAllowedDay: day) ifFalse: [self malformed: 'Bad day: ' , day printString]. |
|
2487 |
^self]. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2488 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2489 |
dayDigit1 := self nextDigit. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2490 |
dayDigit1 < 0 ifTrue: [ |
17815 | 2491 |
"No more digits than month, leave day unspecified." |
2492 |
(month between: 1 and: 12) ifFalse: [self malformed: 'Bad month: ' , month printString]. |
|
2493 |
^self]. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2494 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2495 |
dayDigit2 := self nextDigit. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2496 |
dayDigit2 < 0 |
17815 | 2497 |
ifTrue: [ |
2498 |
"Read only three digits, this is absolute day number in a year." |
|
2499 |
self dateFromDayNumber: month * 10 + dayDigit1] |
|
2500 |
ifFalse: [ |
|
2501 |
"Read four digits. So there's month and day." |
|
2502 |
(month between: 1 and: 12) ifFalse: [self malformed: 'Bad month: ' , month printString]. |
|
2503 |
day := dayDigit1 * 10 + dayDigit2. |
|
2504 |
(self isAllowedDay: day) ifFalse: [self malformed: 'Bad day: ' , day printString]] |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2505 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2506 |
"Created: / 15-06-2005 / 11:12:02 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2507 |
"Modified: / 16-06-2005 / 11:47:34 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2508 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2509 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2510 |
readTime |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2511 |
"Date read, don't mind it. Read only the time value." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2512 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2513 |
| peek | |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2514 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2515 |
hour := self nextDigits: 2. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2516 |
(hour between: 0 and: 24) ifFalse: [self malformed: 'Bad hour: ' , hour printString]. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2517 |
|
17815 | 2518 |
peek := stream peekOrNil. |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2519 |
peek = $: |
17815 | 2520 |
ifTrue: [stream next] |
2521 |
ifFalse: [(peek notNil and: [peek isDigit]) ifFalse: [^self]]. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2522 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2523 |
minute := self nextDigits: 2. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2524 |
(minute between: 0 and: 59) ifFalse: [self malformed: 'Bad minute: ' , minute printString]. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2525 |
|
17815 | 2526 |
peek := stream peekOrNil. |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2527 |
peek = $: |
17815 | 2528 |
ifTrue: [stream next] |
2529 |
ifFalse: [(peek notNil and: [peek isDigit]) ifFalse: [^self]]. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2530 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2531 |
second := self nextDigits: 2. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2532 |
(second between: 0 and: 59) ifFalse: [ |
17815 | 2533 |
"Seconds are usually in this range, do a special check for leap seconds." |
2534 |
second <= 61 |
|
2535 |
ifTrue: [ |
|
2536 |
"Leap seconds can occur only on midnight on 31.12. or 30.6. Dont' check year |
|
2537 |
as it's not deterministic." |
|
2538 |
(minute = 59 and: [hour = 23 and: [(month = 12 and: [day = 31]) or: [month = 6 and: [day = 30]]]]) |
|
2539 |
ifFalse: [self malformed: 'Bad leap second']] |
|
2540 |
ifFalse: [self malformed: 'Bad second: ' , second printString] |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2541 |
]. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2542 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2543 |
"Hour, minute and second read. Read appendices." |
17815 | 2544 |
stream peekOrNil = $. |
2545 |
ifTrue: [ |
|
2546 |
"Read dot. Skip it and read milliseconds." |
|
2547 |
stream next. |
|
2548 |
self readMilliseconds]. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2549 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2550 |
hour = 24 ifTrue: [ |
17815 | 2551 |
(minute = 0 and: [second = 0 and: [millisecond = 0]]) |
2552 |
ifTrue: [ |
|
2553 |
"On 24 hour, advance to the next day." |
|
2554 |
"hour := 0. |
|
2555 |
self addMinutes: 1440"] |
|
2556 |
ifFalse: [self malformed: 'Bad 24 hour (minutes, seconds and millis not 0)'] |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2557 |
] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2558 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2559 |
"Created: / 14-06-2005 / 17:27:00 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2560 |
"Modified: / 30-06-2005 / 11:34:38 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2561 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2562 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2563 |
readTimezone |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2564 |
"Read time zone information. There are three possibilities of what can occur. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2565 |
If there is nothing more to read, the offset is unknown - this is treated as |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2566 |
Zulu time as this may not be true." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2567 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2568 |
| peek | |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2569 |
peek := stream peek. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2570 |
peek ifNil: [^self]. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2571 |
peek := peek asUppercase. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2572 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2573 |
"If the time is in Zulu, don't modify the timestamp. This makes the machine |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2574 |
run in Zulu time zone, maybe some corrections would be nice." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2575 |
peek = $Z |
17815 | 2576 |
ifTrue: [ |
2577 |
"Time read, skip Zulu signature and exit." |
|
2578 |
isUtcTime := true. |
|
2579 |
stream next. |
|
2580 |
^ self]. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2581 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2582 |
peek = $+ |
17815 | 2583 |
ifTrue: [ |
2584 |
"Read a plus, expect a negative time zone difference." |
|
2585 |
isUtcTime := true. |
|
2586 |
stream next. |
|
2587 |
self addHoursAndMinutes: (self readTimezoneOffset collect: [:e | e negated]). |
|
2588 |
^ self]. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2589 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2590 |
peek = $- |
17815 | 2591 |
ifTrue: [ |
2592 |
"Read a minus, expect positive time zone difference or unknown offset." |
|
2593 |
isUtcTime := true. |
|
2594 |
stream next. |
|
2595 |
self addHoursAndMinutes: self readTimezoneOffset. |
|
2596 |
^ self]. |
|
2597 |
||
2598 |
"This is local time" |
|
2599 |
isUtcTime := false. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2600 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2601 |
"Created: / 16-06-2005 / 09:54:21 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2602 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2603 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2604 |
readTimezoneOffset |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2605 |
"Read time zone offset as a number minutes. Generally, there should be hours only |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2606 |
but as the format introduces minutes in offsets, we must accept them." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2607 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2608 |
| hours digit | |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2609 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2610 |
"Read hours." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2611 |
hours := self nextDigits: 2. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2612 |
(hours between: 0 and: 12) ifFalse: [self malformed: 'Bad offset hour: ' , hours printString]. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2613 |
|
17815 | 2614 |
stream peekOrNil = $: |
2615 |
ifTrue: [ |
|
2616 |
"Colon read, minutes must follow." |
|
2617 |
stream next. |
|
2618 |
digit := self nextDigits: 2. |
|
2619 |
(digit between: 0 and: 59) ifFalse: [self malformed: 'Bad offset minute: ' , digit printString]. |
|
2620 |
^Array with: hours with: digit]. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2621 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2622 |
"Read next digit and check whether minutes follow. If not, return only with hours. If yes, |
17815 | 2623 |
check boundaries." |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2624 |
digit := self nextDigit. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2625 |
digit < 0 ifTrue: [^Array with: hours with: 0]. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2626 |
digit >= 6 ifTrue: [self malformed: 'Bad offset minute: ' , (digit * 10) printString]. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2627 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2628 |
"Read the last digit of offset, it must be present." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2629 |
^Array with: hours with: digit * 10 + self nextDigitOrError |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2630 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2631 |
"Created: / 15-06-2005 / 15:35:41 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2632 |
"Modified: / 15-06-2005 / 17:45:58 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2633 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2634 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2635 |
readWeekNumber |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2636 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2637 |
| week day digit | |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2638 |
"Read week number. It is always two digits long." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2639 |
week := self nextDigits: 2. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2640 |
|
17815 | 2641 |
stream peekOrNil = $- |
2642 |
ifTrue: [ |
|
2643 |
"Got dash, day number must follow." |
|
2644 |
stream next. |
|
2645 |
digit := self nextDigit. |
|
2646 |
digit < 0 ifTrue: [self malformed: 'Bad weekday number']. |
|
2647 |
self dateFromWeek: week andWeekday: digit. |
|
2648 |
^self]. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2649 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2650 |
"Read day number that follows the week. If the number is not given, consider it monday." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2651 |
day := self nextDigit. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2652 |
day <= 0 ifTrue: [day := 1]. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2653 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2654 |
self dateFromWeek: week andWeekday: day |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2655 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2656 |
"Created: / 14-06-2005 / 12:06:47 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2657 |
"Modified: / 15-06-2005 / 15:53:34 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2658 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2659 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2660 |
readYear |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2661 |
"Read YYYY or :Y (broken decade) from the stream. Also handles correctly YY- and YYY-." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2662 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2663 |
| read peek | |
17815 | 2664 |
stream peekOrNil = $: |
2665 |
ifTrue: [ |
|
2666 |
"Broken two digit year > 1999 follows." |
|
2667 |
stream next. |
|
2668 |
year := self nextDigitOrError + 2000. |
|
2669 |
^self]. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2670 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2671 |
"Expecting two-, three- or four-digit year" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2672 |
"Read the first two digits. They must be there." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2673 |
read := self nextDigits: 2. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2674 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2675 |
"Check if there's a dash, this can help us deciding whether the year ends." |
17815 | 2676 |
peek := stream peekOrNil. |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2677 |
peek ifNil: [^self]. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2678 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2679 |
year := peek = $- |
17815 | 2680 |
ifTrue: [ |
2681 |
"OK, got two digits. These are expected to be the year after 1970." |
|
2682 |
read < 70 |
|
2683 |
ifTrue: [read + 2000] |
|
2684 |
ifFalse: [read + 1900]] |
|
2685 |
ifFalse: [ |
|
2686 |
"Read the next digit for the case of three-digit year after 1900 (ie. year > 1999)." |
|
2687 |
read := read * 10 + self nextDigitOrError. |
|
2688 |
peek := stream peekOrNil. |
|
2689 |
(peek isNil or: [peek = $-]) |
|
2690 |
ifTrue: [ |
|
2691 |
"Read three digit year, return it." |
|
2692 |
read + 1900] |
|
2693 |
ifFalse: [ |
|
2694 |
"Read the fourth digit of the year. These can be month digits but the |
|
2695 |
two-digit year format is deprecated anyway." |
|
2696 |
read := read * 10 + self nextDigitOrError] |
|
2697 |
] |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2698 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2699 |
"Created: / 14-06-2005 / 12:01:11 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2700 |
"Modified: / 15-06-2005 / 17:31:56 / masca" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2701 |
! ! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2702 |
|
8246 | 2703 |
!Timestamp class methodsFor:'documentation'! |
699 | 2704 |
|
2705 |
version |
|
17892 | 2706 |
^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.141 2011/09/15 08:42:09 ca Exp $' |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2707 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2708 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
2709 |
version_CVS |
17862 | 2710 |
^ '§Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.141 2011/09/15 08:42:09 ca Exp §' |
17865 | 2711 |
! |
2712 |
||
2713 |
version_SVN |
|
17911 | 2714 |
^ '$Id: Timestamp.st 10761 2012-01-19 11:46:00Z vranyj1 $' |
699 | 2715 |
! ! |
8246 | 2716 |
|
17846 | 2717 |
Timestamp initialize! |
17892 | 2718 |
|
17910 | 2719 |
|
17911 | 2720 |