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