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