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