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