author | Claus Gittinger <cg@exept.de> |
Fri, 28 Jun 2019 08:49:56 +0200 | |
changeset 24385 | dd84e4dfb5cc |
parent 24163 | b50d5ba0d03b |
child 24404 | 0681f4ab2d53 |
permissions | -rw-r--r-- |
23565 | 1 |
"{ Encoding: utf8 }" |
2 |
||
30 | 3 |
" |
4 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
17006 | 5 |
All Rights Reserved |
30 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
5376
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
14 |
"{ Package: 'stx:libbasic' }" |
c2ef7d5e25ca
oops - was not able to reread my own storeString.
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
15 |
|
17422
0a01cd7cf5f2
class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents:
17172
diff
changeset
|
16 |
"{ NameSpace: Smalltalk }" |
0a01cd7cf5f2
class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents:
17172
diff
changeset
|
17 |
|
8246 | 18 |
AbstractTime subclass:#Timestamp |
22834 | 19 |
instanceVariableNames:'osTime additionalPicoseconds' |
19923 | 20 |
classVariableNames:'Epoch MaxOSTime MinOSTime TimeZoneInfo' |
17005 | 21 |
poolDictionaries:'' |
22 |
category:'Magnitude-Time' |
|
30 | 23 |
! |
24 |
||
11993 | 25 |
Object subclass:#TimestampBuilderAbstract |
17005 | 26 |
instanceVariableNames:'year month day hour minute second millisecond isUtcTime |
22873 | 27 |
hasTimezone yearAlreadyRead utcOffset picos' |
17005 | 28 |
classVariableNames:'' |
29 |
poolDictionaries:'' |
|
30 |
privateIn:Timestamp |
|
11993 | 31 |
! |
32 |
||
33 |
Timestamp::TimestampBuilderAbstract subclass:#TimestampISO8601Builder |
|
17005 | 34 |
instanceVariableNames:'stream' |
35 |
classVariableNames:'' |
|
36 |
poolDictionaries:'' |
|
37 |
privateIn:Timestamp |
|
11993 | 38 |
! |
39 |
||
8246 | 40 |
!Timestamp class methodsFor:'documentation'! |
30 | 41 |
|
82 | 42 |
copyright |
43 |
" |
|
44 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
17006 | 45 |
All Rights Reserved |
82 | 46 |
|
47 |
This software is furnished under a license and may be used |
|
48 |
only in accordance with the terms of that license and with the |
|
49 |
inclusion of the above copyright notice. This software may not |
|
50 |
be provided or otherwise made available to, or used by, any |
|
51 |
other person. No title to or ownership of the software is |
|
52 |
hereby transferred. |
|
53 |
" |
|
54 |
! |
|
55 |
||
30 | 56 |
documentation |
57 |
" |
|
22627 | 58 |
This class represents time values in milliseconds, starting some time in the past. |
22834 | 59 |
This base-time is called 'epoch' and always an UTC time. |
60 |
||
16945 | 61 |
When printing and accessing values like #hour, |
22627 | 62 |
the timestamp will be interpreted in the local timezone. |
16955 | 63 |
(as opposed to UtcTimestamp, which presents itself in UTC, |
17131 | 64 |
and as opposed to TZTimestamp, which remembers the timezone in which it was created). |
16939 | 65 |
|
22834 | 66 |
The internal representation, osTime, will typically start with 1970-01-01 00:00 UTC, |
16939 | 67 |
as used in the Unix operating system, but other systems may bias the time differently. |
16945 | 68 |
Actually, the implementation does not depend or even know which time/date |
16939 | 69 |
the OperatingSystem bases its time upon - it is simply keeping the value(s) |
70 |
as returned from the OS. |
|
71 |
For conversion, these values are given back to the OS, which will know |
|
22627 | 72 |
how to convert them. This has the advantage that timestamps on files |
16945 | 73 |
(such as last-access-time or last-modification-time) can be handled transparently - |
16939 | 74 |
especially when performing comparisons. |
75 |
||
16945 | 76 |
You should not interpret the osTime instance variable directly, |
16939 | 77 |
instead (if at all), ask the OS to convert. |
30 | 78 |
|
16945 | 79 |
The implementation of this class is not the same as in ST-80 |
7671 | 80 |
(which represents the time as seconds from Jan 1., 1901). |
30 | 81 |
|
22613 | 82 |
This class should not be confused with Time (which only represents the time within one day). |
22627 | 83 |
Time instances cannot be used to compare times across midnight, whereas instances of Timestamp can. |
84 |
Also, it should not be confused with TimeDuration, which represents a time-difference. |
|
85 |
||
86 |
Notice: |
|
87 |
this class was once called AbsoluteTime. Einstein told us in 1905, that talking |
|
88 |
about an absolute time is not a good idea (at least in our universe). So in 2004 the class |
|
89 |
has been renamed to Timestamp which makes us more compatible to other ST dialects (e.g. VW) |
|
90 |
AbsoluteTime was kept as an alias for backward compatibility and was finally removed in 2017. |
|
3479 | 91 |
|
16922 | 92 |
Also Note: |
21699 | 93 |
On UNIX, osTime can only hold dates between 1970-01-01T00:00:00Z and 2038-01-19T03:14:07Z |
22613 | 94 |
However, timestamp instances can hold negative osTime values (which are timestamps |
95 |
before 1.1.1970 and also osTimes greater than 4294967295 (2^32-1) for timestamps after 2038-01-19. |
|
22627 | 96 |
Thus, ST/X will have no problem when dealing with dates before the epoch or after 2038. |
17131 | 97 |
|
21699 | 98 |
For dates before 1582 (when calendars were changed from Julian to Gregorian), |
17131 | 99 |
the so called 'proleptic gregorian calendar' is used. This assumes leap years to continue in |
100 |
the past as if a gregorian calendar was used. Thus, 0000 is considered a leap year. |
|
16972 | 101 |
|
22834 | 102 |
ALso Note: |
103 |
because all timestamps keep the internal time value in UTC, they can be easily compared |
|
104 |
for being before/same/after another. Only when printing, a difference is made. |
|
105 |
The timezone is compensated out when a timestamp is created and recalculated in when printed. |
|
106 |
||
22627 | 107 |
News: |
108 |
The additional instance variable picoSeconds can be used to add more resolution. |
|
109 |
If non-nil, it holds additional picoseconds to be added to the millisecond osTime |
|
110 |
(i.e. the picoSeconds are an integer between 0 and 1000*1000*1000. |
|
22613 | 111 |
Although, not all OSs give us that detail when asking for the current time, |
22627 | 112 |
the picos can still be used in physical computations. |
113 |
Some OSs will provide microsecond resolution. |
|
22834 | 114 |
Notice: |
115 |
the picos are to be added to the millis, to get picos within the second. |
|
116 |
this is ugly, but makes all the rest backward compatible. |
|
22873 | 117 |
Also, most timestamps only require/have millisecond resolution, |
118 |
so the pico instvar is nil/0 and does not require an aditional largeInteger operation. |
|
22613 | 119 |
|
22867 | 120 |
The typical OS-time resolution is in the milli- or microsecond range. |
121 |
External logging hardware may generate timestamps in the micro- or nanosecond range. |
|
122 |
Picosecond resolution should be good enough for almost any application (at least for the near future). |
|
123 |
||
1306 | 124 |
[author:] |
17131 | 125 |
Claus Gittinger |
1306 | 126 |
|
1282 | 127 |
[See also:] |
17131 | 128 |
UtcTimestamp Time Date |
129 |
Delay ProcessorScheduler |
|
30 | 130 |
" |
131 |
! ! |
|
132 |
||
8246 | 133 |
!Timestamp class methodsFor:'initialization'! |
134 |
||
135 |
initialize |
|
17008 | 136 |
MinOSTime := OperatingSystem epochStartOSTime. |
137 |
MaxOSTime := OperatingSystem epochEndOSTime. |
|
17006 | 138 |
|
139 |
Epoch := UtcTimestamp basicNew setSeconds:0. |
|
21264 | 140 |
|
141 |
"Modified: / 19-01-2017 / 17:01:59 / stefan" |
|
8246 | 142 |
! ! |
143 |
||
144 |
!Timestamp class methodsFor:'instance creation'! |
|
30 | 145 |
|
4378 | 146 |
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
|
147 |
"return an instance of the receiver, given individual components, |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
148 |
interpreted in the UTC timezone." |
1501 | 149 |
|
16945 | 150 |
^ self basicNew |
17006 | 151 |
UTCyear:y month:m day:d hour:h minute:min second:s millisecond:millis |
30 | 152 |
|
241 | 153 |
" |
12819
a28ce068acd8
comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents:
12729
diff
changeset
|
154 |
Timestamp UTCYear:1970 month:1 day:1 hour:0 minute:0 second:0 millisecond:0 |
8246 | 155 |
Timestamp UTCYear:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:0 |
156 |
Timestamp UTCYear:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100 |
|
157 |
Timestamp UTCYear:1999 month:7 day:1 hour:1 minute:0 second:0 millisecond:0 |
|
158 |
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
|
159 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
160 |
UtcTimestamp UTCYear:2000 month:1 day:1 hour:1 minute:0 second:0 millisecond:0 |
241 | 161 |
" |
1228 | 162 |
|
4378 | 163 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
164 |
"Created: / 13.7.1999 / 12:34:37 / stefan" |
|
165 |
"Modified: / 13.7.1999 / 12:42:30 / stefan" |
|
166 |
! |
|
167 |
||
22873 | 168 |
UTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis additionalPicoseconds:picos |
169 |
"return an instance of the receiver, given individual components, |
|
170 |
interpreted in the UTC timezone." |
|
171 |
||
172 |
^ self basicNew |
|
173 |
UTCyear:y month:m day:d hour:h minute:min second:s millisecond:millis |
|
174 |
additionalPicoseconds:picos |
|
175 |
||
176 |
" |
|
177 |
Timestamp UTCYear:1970 month:1 day:1 hour:0 minute:0 second:0 millisecond:0 |
|
178 |
Timestamp UTCYear:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:0 |
|
179 |
Timestamp UTCYear:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100 |
|
180 |
Timestamp UTCYear:1999 month:7 day:1 hour:1 minute:0 second:0 millisecond:0 |
|
181 |
Timestamp UTCYear:2000 month:1 day:1 hour:1 minute:0 second:0 millisecond:0 |
|
182 |
||
183 |
UtcTimestamp UTCYear:2000 month:1 day:1 hour:1 minute:0 second:0 millisecond:0 |
|
184 |
" |
|
185 |
||
186 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
|
187 |
"Created: / 13.7.1999 / 12:34:37 / stefan" |
|
188 |
"Modified: / 13.7.1999 / 12:42:30 / stefan" |
|
189 |
! |
|
190 |
||
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
191 |
decodeFromLiteralArray:anArray |
16986 | 192 |
"decode a Timestamp literalArray. |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
193 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
194 |
anArray may be: |
19897 | 195 |
#(Timestamp '200004182000.123') |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
196 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
197 |
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
|
198 |
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
|
199 |
|
19897 | 200 |
#(Timestamp #osTime: 12345678) |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
201 |
" |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
202 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
203 |
(anArray at:2) == #osTime: ifTrue:[ |
19897 | 204 |
^ self new osTime:(anArray at:3). |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
205 |
]. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
206 |
|
16945 | 207 |
^ self |
19897 | 208 |
readGeneralizedFrom:(anArray at:2) |
209 |
onError:[ self conversionErrorSignal |
|
210 |
raiseWith:anArray errorString:' - Timestamp literal array decoding' ] |
|
8797 | 211 |
|
212 |
" |
|
213 |
Timestamp |
|
19897 | 214 |
decodeFromLiteralArray:#(Timestamp '20050323175226.014') |
16986 | 215 |
Timestamp |
19897 | 216 |
decodeFromLiteralArray:#(Timestamp '20050323175226.014-01') |
16986 | 217 |
Timestamp |
19897 | 218 |
decodeFromLiteralArray:#(Timestamp '20050323175226.014Z') |
8797 | 219 |
" |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
220 |
! |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
221 |
|
16945 | 222 |
epoch |
16986 | 223 |
"the epoch is based to 0 for 1970-01-01 00:00:00. |
224 |
However, we allow negative values to represent timestamps before that" |
|
16945 | 225 |
|
226 |
^ Epoch |
|
16928 | 227 |
! |
228 |
||
16932 | 229 |
fromDate:aDate |
230 |
"return an instance of the receiver, initialized from a time and a date |
|
231 |
object. |
|
232 |
See also `Timestamp now' and other protocol inherited |
|
233 |
from my superclass." |
|
234 |
||
16945 | 235 |
^ self |
17006 | 236 |
year:aDate year |
237 |
month:aDate month |
|
238 |
day:aDate day |
|
239 |
hour:0 |
|
240 |
minute:0 |
|
241 |
second:0 |
|
242 |
millisecond:0 |
|
16932 | 243 |
|
244 |
" |
|
16945 | 245 |
Timestamp fromDate:(Date today) andTime:(Time now) |
246 |
Timestamp fromDate:(Date today plusDays:1) andTime:(Time now) |
|
247 |
Timestamp now |
|
16932 | 248 |
" |
249 |
||
250 |
"Modified: / 8.9.1995 / 15:07:30 / claus" |
|
251 |
"Modified: / 19.4.1996 / 15:25:46 / cg" |
|
252 |
"Modified: / 13.7.1999 / 12:30:47 / stefan" |
|
253 |
! |
|
254 |
||
423 | 255 |
fromDate:aDate andTime:aTime |
256 |
"return an instance of the receiver, initialized from a time and a date |
|
1228 | 257 |
object. |
8246 | 258 |
See also `Timestamp now' and other protocol inherited |
1228 | 259 |
from my superclass." |
423 | 260 |
|
16950 | 261 |
^ self |
17006 | 262 |
year:aDate year |
263 |
month:aDate month |
|
264 |
day:aDate day |
|
265 |
hour:aTime hours |
|
266 |
minute:aTime minutes |
|
267 |
second:aTime seconds |
|
268 |
millisecond:aTime milliseconds |
|
16946 | 269 |
|
423 | 270 |
" |
16950 | 271 |
Timestamp fromDate:(Date today) andTime:(Time now) |
16946 | 272 |
Timestamp fromDate:(Date today) andTime:(Time nowWithMilliseconds) |
273 |
||
16950 | 274 |
Timestamp fromDate:(Date today plusDays:1) andTime:(Time now) |
275 |
Timestamp now |
|
423 | 276 |
" |
277 |
||
4378 | 278 |
"Modified: / 8.9.1995 / 15:07:30 / claus" |
279 |
"Modified: / 19.4.1996 / 15:25:46 / cg" |
|
280 |
"Modified: / 13.7.1999 / 12:30:47 / stefan" |
|
423 | 281 |
! |
282 |
||
22873 | 283 |
fromDate:aDate hour:hour minute:minute second:second |
284 |
"return an instance of the receiver, initialized from a time and a date object. |
|
285 |
See also `Timestamp now' and other protocol inherited from my superclass." |
|
286 |
||
287 |
^ self fromDate:aDate hour:hour minute:minute second:second millisecond:0 |
|
288 |
||
289 |
" |
|
290 |
Timestamp fromDate:(Date today) andTime:(Time now) |
|
291 |
Timestamp fromDate:(Date today) hour:10 minute:5 second:30 |
|
292 |
" |
|
293 |
! |
|
294 |
||
295 |
fromDate:aDate hour:hour minute:minute second:second microsecond:micros |
|
296 |
"return an instance of the receiver, initialized from a time and a date object. |
|
297 |
See also `Timestamp now' and other protocol inherited from my superclass." |
|
298 |
||
299 |
^ (self |
|
300 |
year:aDate year |
|
301 |
month:aDate month |
|
302 |
day:aDate day |
|
303 |
hour:hour |
|
304 |
minute:minute |
|
305 |
second:second |
|
306 |
millisecond:0 |
|
307 |
) setMicrosecond:micros |
|
308 |
||
309 |
" |
|
310 |
Timestamp fromDate:(Date today) hour:10 minute:5 second:30 microsecond:123456 |
|
311 |
Timestamp fromDate:(Date today) hour:10 minute:5 second:30 microsecond:140 |
|
312 |
" |
|
313 |
! |
|
314 |
||
315 |
fromDate:aDate hour:hour minute:minute second:second millisecond:millis |
|
316 |
"return an instance of the receiver, initialized from a time and a date object. |
|
317 |
See also `Timestamp now' and other protocol inherited from my superclass." |
|
318 |
||
319 |
^ self |
|
320 |
year:aDate year |
|
321 |
month:aDate month |
|
322 |
day:aDate day |
|
323 |
hour:hour |
|
324 |
minute:minute |
|
325 |
second:second |
|
326 |
millisecond:millis |
|
327 |
||
328 |
" |
|
329 |
Timestamp fromDate:(Date today) andTime:(Time now) |
|
330 |
Timestamp fromDate:(Date today) andTime:(Time nowWithMilliseconds) |
|
331 |
Timestamp fromDate:(Date today) hour:10 minute:5 second:30 millisecond:140 |
|
332 |
" |
|
333 |
! |
|
334 |
||
335 |
fromDate:aDate hour:hour minute:minute second:second nanosecond:nanos |
|
336 |
"return an instance of the receiver, initialized from a time and a date object. |
|
337 |
See also `Timestamp now' and other protocol inherited from my superclass." |
|
338 |
||
339 |
^ (self |
|
340 |
year:aDate year |
|
341 |
month:aDate month |
|
342 |
day:aDate day |
|
343 |
hour:hour |
|
344 |
minute:minute |
|
345 |
second:second |
|
346 |
millisecond:0 |
|
347 |
) setNanosecond:nanos |
|
348 |
||
349 |
" |
|
350 |
Timestamp fromDate:(Date today) hour:10 minute:5 second:30 microsecond:123456 |
|
351 |
Timestamp fromDate:(Date today) hour:10 minute:5 second:30 microsecond:140 |
|
352 |
" |
|
353 |
! |
|
354 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
355 |
newDay:dayInYear year:year |
8246 | 356 |
"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
|
357 |
Date protocol compatibility" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
358 |
|
16932 | 359 |
^ self fromDate:(Date newDay:dayInYear year:year) |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
360 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
361 |
" |
8246 | 362 |
Timestamp newDay:183 year:1996 |
16945 | 363 |
Timestamp newDay:1 year:1996 |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
364 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
365 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
366 |
"Modified: 2.7.1996 / 09:39:30 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
367 |
! |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
368 |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
369 |
secondsSince1970:secs |
22834 | 370 |
"set time from elapsed seconds since 1-1-1970, 00:00:00 (UTC). |
371 |
This is the format used in the UNIX world. |
|
372 |
Notice that the internal storage is always UTC based." |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
373 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
374 |
^ self basicNew setSeconds:secs. |
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 |
" |
22834 | 377 |
UtcTimestamp secondsSince1970:0 -> 1970-01-01 00:00:00Z |
378 |
Timestamp secondsSince1970:0 -> 1970-01-01 01:00:00 (local germany, ST) |
|
379 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
380 |
Timestamp secondsSince1970:3600 |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
381 |
Timestamp secondsSince1970:3600*24 |
22834 | 382 |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
383 |
(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
|
384 |
= |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
385 |
(Timestamp secondsSince1970:1277935200) |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
386 |
" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
387 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
388 |
"Created: / 21-10-1996 / 17:48:30 / stefan" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
389 |
"Modified: / 13-07-1999 / 12:31:22 / stefan" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
390 |
"Modified: / 08-01-2011 / 16:06:28 / cg" |
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 |
|
23565 | 393 |
utcMillisecondsSince1970:millis |
16986 | 394 |
"set time from elapsed milliseconds since the epoch 1-1-1970, 00:00:00." |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
395 |
|
23565 | 396 |
^ self basicNew setMilliseconds:millis |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
397 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
398 |
"Created: / 08-01-2011 / 16:09:32 / cg" |
23565 | 399 |
"Modified (format): / 14-12-2018 / 19:45:12 / Claus Gittinger" |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
400 |
! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
401 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
402 |
utcNow |
16986 | 403 |
"return now as utc timestamp" |
404 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
405 |
^ UtcTimestamp now |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
406 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
407 |
" |
16986 | 408 |
Timestamp now |
409 |
Timestamp utcNow |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
410 |
" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
411 |
! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
412 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
413 |
utcSecondsSince1970:secs |
22834 | 414 |
"set time from the elapsed seconds since 1-1-1970, 00:00:00 UTC. |
415 |
This is the format used in the UNIX world. |
|
416 |
Notice that the internal storage is always UTC based." |
|
417 |
||
418 |
^ UtcTimestamp secondsSince1970:secs |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
419 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
420 |
" |
22834 | 421 |
UtcTimestamp secondsSince1970:0 -> 1970-01-01 00:00:00Z |
422 |
Timestamp secondsSince1970:0 -> 1970-01-01 01:00:00 (local germany, ST) |
|
423 |
||
424 |
UtcTimestamp secondsSince1970:3600 -> 1970-01-01 01:00:00Z |
|
425 |
Timestamp secondsSince1970:3600 -> 1970-01-01 02:00:00 (local) |
|
426 |
||
16945 | 427 |
Timestamp secondsSince1970:3600*24 |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
428 |
" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
429 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
430 |
"Modified: / 13-07-1999 / 12:31:22 / stefan" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
431 |
"Created: / 08-01-2011 / 16:05:09 / cg" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
432 |
! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
433 |
|
19713 | 434 |
year:year month:month day:day |
435 |
"return a new Timestamp, given the year, month and day (starting at 1). |
|
436 |
Date protocol compatibility" |
|
437 |
||
438 |
^ self |
|
439 |
year:year |
|
440 |
month:month |
|
441 |
day:day |
|
442 |
hour:0 |
|
443 |
minute:0 |
|
444 |
second:0 |
|
445 |
millisecond:0 |
|
446 |
||
447 |
" |
|
448 |
Timestamp year:1996 month:1 day:1 |
|
449 |
" |
|
450 |
! |
|
451 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
452 |
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
|
453 |
"return an instance of the receiver, given individual components. |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
454 |
See also `Timestamp now' and other protocol inherited |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
455 |
from my superclass." |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
456 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
457 |
^ 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
|
458 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
459 |
" |
16945 | 460 |
Timestamp year:1970 month:1 day:1 hour:1 minute:0 second:0 |
461 |
Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
462 |
Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100 |
16945 | 463 |
Timestamp year:2000 month:7 day:1 hour:1 minute:0 second:0 |
19771 | 464 |
Timestamp year:2080 month:7 day:1 hour:1 minute:0 second:0 |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
465 |
" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
466 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
467 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
468 |
"Created: / 13.7.1999 / 12:06:39 / stefan" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
469 |
"Modified: / 13.7.1999 / 12:27:47 / stefan" |
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 |
|
22873 | 472 |
year:y month:m day:d hour:h minute:min second:s microsecond:micros |
473 |
"return an instance of the receiver, given individual components. |
|
474 |
See also `Timestamp now' and other protocol inherited |
|
475 |
from my superclass." |
|
476 |
||
477 |
^ (self year:y month:m day:d hour:h minute:min second:s) setMicrosecond:micros |
|
478 |
||
479 |
" |
|
480 |
Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 microsecond:100 |
|
481 |
" |
|
482 |
! |
|
483 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
484 |
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
|
485 |
"return an instance of the receiver, given individual components. |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
486 |
See also `Timestamp now' and other protocol inherited |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
487 |
from my superclass." |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
488 |
|
16945 | 489 |
^ self basicNew |
17006 | 490 |
year: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
|
491 |
" |
16945 | 492 |
Timestamp year:1970 month:1 day:1 hour:0 minute:0 second:0 |
493 |
Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
494 |
Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100 |
16945 | 495 |
Timestamp year:2000 month:7 day:1 hour:1 minute:0 second:0 |
496 |
UtcTimestamp year:2000 month:7 day:1 hour:1 minute:0 second:0 |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
497 |
" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
498 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
499 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
500 |
"Created: / 13.7.1999 / 12:28:44 / stefan" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
501 |
"Modified: / 13.7.1999 / 12:37:57 / stefan" |
22873 | 502 |
! |
503 |
||
504 |
year:y month:m day:d hour:h minute:min second:s millisecond:millis additionalPicoseconds:picos |
|
505 |
"return an instance of the receiver, given individual components. |
|
506 |
See also `Timestamp now' and other protocol inherited |
|
507 |
from my superclass." |
|
508 |
||
509 |
^ self basicNew |
|
510 |
year:y month:m day:d hour:h minute:min second:s |
|
511 |
millisecond:millis additionalPicoseconds:picos |
|
512 |
||
513 |
" |
|
514 |
Timestamp year:1970 month:1 day:1 hour:0 minute:0 second:0 |
|
515 |
Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 |
|
516 |
Timestamp year:1991 month:1 day:2 hour:12 minute:30 second:0 millisecond:100 |
|
517 |
Timestamp year:2000 month:7 day:1 hour:1 minute:0 second:0 |
|
518 |
UtcTimestamp year:2000 month:7 day:1 hour:1 minute:0 second:0 |
|
519 |
" |
|
520 |
||
521 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
|
522 |
"Created: / 13.7.1999 / 12:28:44 / stefan" |
|
523 |
"Modified: / 13.7.1999 / 12:37:57 / stefan" |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
524 |
! ! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
525 |
|
24160 | 526 |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
527 |
!Timestamp class methodsFor:'Compatibility-Squeak'! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
528 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
529 |
current |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
530 |
^ self now |
13604 | 531 |
! |
532 |
||
533 |
readFrom:aStringOrStream |
|
534 |
"Answer a new instance for the value given by aStringOrStream" |
|
535 |
||
16945 | 536 |
^ self |
19713 | 537 |
readFrom:aStringOrStream |
23564 | 538 |
onError:[ |
539 |
TimeConversionError raiseRequestWith:aStringOrStream errorString:' - timestamp' |
|
540 |
] |
|
13604 | 541 |
|
542 |
" |
|
543 |
self readFrom:'23-jun-2000 15:00' |
|
14969 | 544 |
self fromString:'23-jun-2000 15:00' |
13604 | 545 |
self readFrom:'23-jun-2000 ' |
546 |
" |
|
547 |
||
548 |
"Modified (comment): / 20-08-2011 / 16:52:10 / cg" |
|
23564 | 549 |
"Modified (format): / 14-12-2018 / 19:14:16 / Claus Gittinger" |
18886 | 550 |
! |
551 |
||
24160 | 552 |
year:year day:dayInYear |
553 |
"return a new Timestamp, given the year and the day-in-year (starting at 1). |
|
554 |
See also: Date today / Time now / Timestamp now. |
|
555 |
Squeak compatibility" |
|
556 |
||
557 |
^ self newDay:dayInYear year:year |
|
558 |
||
559 |
" |
|
560 |
self year:1970 day:1 |
|
561 |
self year:2000 day:1 |
|
562 |
" |
|
563 |
||
564 |
"Created: / 26-05-2019 / 11:59:20 / Claus Gittinger" |
|
565 |
! |
|
566 |
||
18886 | 567 |
year: year month: month day: day hour: hour minute: minute second: second millisecond: millisecond offset:timeDuration |
568 |
^ (UtcTimestamp year: year month: month day: day hour: hour minute: minute second: second millisecond: millisecond) |
|
569 |
utcOffset:timeDuration |
|
570 |
||
571 |
" |
|
572 |
Timestamp year:2015 month:11 day:9 hour:12 minute:0 second:0 millisecond:0 offset:(2 hours) |
|
573 |
" |
|
574 |
! |
|
575 |
||
576 |
year: year month: month day: day hour: hour minute: minute second: second offset:timeDuration |
|
577 |
^ (UtcTimestamp year: year month: month day: day hour: hour minute: minute second: second) |
|
578 |
utcOffset:timeDuration |
|
579 |
||
580 |
" |
|
581 |
Timestamp year:2015 month:11 day:9 hour:12 minute:0 second:0 offset:(2 hours) |
|
24163 | 582 |
Timestamp year:2015 month:11 day:9 hour:12 minute:0 second:0 offset:0 |
583 |
" |
|
584 |
||
585 |
"Modified (comment): / 26-05-2019 / 12:10:28 / Claus Gittinger" |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
586 |
! ! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
587 |
|
22837 | 588 |
!Timestamp class methodsFor:'class access'! |
589 |
||
590 |
timestampISO8601Builder |
|
591 |
"I hate private class overuse... |
|
592 |
... I need such ugly hacks whenever someone thinks that he/she must keep a secret... |
|
593 |
See Time for such its use" |
|
594 |
||
595 |
^ TimestampISO8601Builder |
|
596 |
! ! |
|
597 |
||
13700 | 598 |
!Timestamp class methodsFor:'format strings'! |
599 |
||
600 |
defaultFormatString |
|
16986 | 601 |
"a format string to present times in user interfaces. |
602 |
Do not use this to store/retrieve times (use ISO8601 for that). |
|
603 |
Although the string below looks like ISO8601, it does not include TZ information, |
|
604 |
so when read back, it will always be interpreted as a local timestamp." |
|
605 |
||
13700 | 606 |
^ '%(year)-%(month)-%(day) %h:%m:%s.%i' |
607 |
||
608 |
"Created: / 16-01-2011 / 11:23:36 / cg" |
|
609 |
! ! |
|
610 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
611 |
!Timestamp class methodsFor:'obsolete'! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
612 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
613 |
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
|
614 |
<resource: #obsolete> |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
615 |
"This is obsolete. User #year:month:day:hour:minute:second:" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
616 |
|
16945 | 617 |
^ self |
17006 | 618 |
year:y month:m day:d hour:h |
619 |
minute:min second:s millisecond:0 |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
620 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
621 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
622 |
"Modified: / 1.7.1996 / 15:22:26 / cg" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
623 |
"Modified: / 13.7.1999 / 12:29:56 / stefan" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
624 |
! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
625 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
626 |
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
|
627 |
<resource: #obsolete> |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
628 |
"This is obsolete. User #year:month:day:hour:minute:second:millisecond:" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
629 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
630 |
^ 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
|
631 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
632 |
" |
16945 | 633 |
Timestamp day:1 month:1 year:1970 hour:1 minute:0 second:0 |
634 |
Timestamp day:2 month:1 year:1991 hour:12 minute:30 second:0 |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
635 |
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
|
636 |
" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
637 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
638 |
"Created: / 1.7.1996 / 14:46:09 / cg" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
639 |
"Modified: / 1.7.1996 / 15:22:07 / cg" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
640 |
"Modified: / 13.7.1999 / 12:30:26 / stefan" |
19713 | 641 |
! |
642 |
||
643 |
newDay:day month:month year:year |
|
644 |
<resource: #obsolete> |
|
22873 | 645 |
|
19713 | 646 |
"return a new Timestamp, given the year, month and day (starting at 1). |
22873 | 647 |
Date protocol compatibility. |
648 |
Obsolete: use year:month:day:." |
|
19713 | 649 |
|
650 |
^ self |
|
22873 | 651 |
year:year |
652 |
month:month |
|
653 |
day:day |
|
654 |
hour:0 |
|
655 |
minute:0 |
|
656 |
second:0 |
|
657 |
millisecond:0 |
|
19713 | 658 |
|
659 |
" |
|
660 |
Timestamp newDay:1 month:1 year:1996 |
|
661 |
" |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
662 |
! ! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
663 |
|
22914 | 664 |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
665 |
!Timestamp class methodsFor:'private'! |
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 |
basicReadFrom:aStream |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
668 |
"return a new Timestamp, reading a printed representation from aStream. |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
669 |
The string is interpreted as 24 hour format, as printed. |
16914 | 670 |
|
16945 | 671 |
Notice, that this is NOT the storeString format, which is iso8601 |
16914 | 672 |
This is more or less a heuristic attempt to read any reasonable format. |
16945 | 673 |
If the input starts with an integer > 31, |
16935 | 674 |
it is assumed to be a year and the rest is read in iso8601 format. |
16914 | 675 |
|
16945 | 676 |
KLUDGE: |
17071 | 677 |
us and non-us format have different ordering of day and month; |
678 |
The format read here is (non-us) dd-mm-yyyy hh:mm:ss.iii |
|
679 |
or (us-format, for Travis) mm/dd/yyyy hh:mm:ss.iii. |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
680 |
On error, raise an exception" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
681 |
|
22873 | 682 |
|monthOrYear firstNumber secondNumber day month year hour min sec |
23564 | 683 |
millis usFormat possibeMonthName ch utcOffsetOrNil |
684 |
count mantissa fraction picos ts |
|
685 |
monthName| |
|
686 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
687 |
aStream skipSeparators. |
23564 | 688 |
aStream peek isLetter ifTrue:[ |
689 |
"/ US format, like 'July 21, 1983 01:15:00' ? |
|
690 |
monthName := aStream throughAnyForWhich:[:ch | ch isLetter]. |
|
691 |
month := Date indexOfMonth:monthName asLowercase. |
|
692 |
aStream skipSeparators. |
|
693 |
day := Integer readFrom:aStream onError:-1. |
|
694 |
aStream skipSeparators. |
|
695 |
aStream peek == $, ifTrue:[ |
|
696 |
aStream next |
|
697 |
]. |
|
698 |
] ifFalse:[ |
|
699 |
count := 0. |
|
700 |
monthOrYear := aStream throughAnyForWhich:[:ch | count := count+1. ch isDigit and:[count <= 4]]. |
|
701 |
firstNumber := Integer readFrom:monthOrYear onError:[TimeConversionError raiseErrorString:' - integer expected']. |
|
702 |
firstNumber > 31 ifTrue:[ |
|
703 |
"/ assume iso8601 format; |
|
704 |
^ self readIso8601FormatFrom:aStream yearAlreadyRead:firstNumber. |
|
705 |
]. |
|
706 |
aStream skipSeparators. |
|
707 |
||
708 |
"/ consider this a kludge |
|
709 |
usFormat := (aStream peek == $/ ). |
|
710 |
||
711 |
[(ch := aStream peekOrNil) notNil and:[ch isLetterOrDigit not]] whileTrue:[aStream next]. |
|
712 |
(ch notNil and:[ch isDigit]) ifTrue:[ |
|
713 |
secondNumber := Integer readFrom:aStream onError:-1. |
|
714 |
||
715 |
usFormat ifTrue:[ |
|
716 |
month := firstNumber. |
|
717 |
day := secondNumber. |
|
718 |
] ifFalse:[ |
|
719 |
month := secondNumber. |
|
720 |
day := firstNumber. |
|
721 |
]. |
|
17071 | 722 |
] ifFalse:[ |
23564 | 723 |
possibeMonthName := aStream throughAnyForWhich:[:ch | ch isLetter]. |
724 |
month := Date indexOfMonth:possibeMonthName asLowercase. |
|
17071 | 725 |
day := firstNumber. |
726 |
]. |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
727 |
]. |
23564 | 728 |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
729 |
(day between:1 and:31) ifFalse:[ TimeConversionError raiseErrorString:' - bad day' ]. |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
730 |
(month between:1 and:12) ifFalse:[ TimeConversionError raiseErrorString:' - bad month' ]. |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
731 |
|
16967 | 732 |
[(ch := aStream peekOrNil) notNil and:[ch isDigit not]] whileTrue:[aStream next]. |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
733 |
year := Integer readFrom:aStream onError:[ TimeConversionError raiseErrorString:' - bad year' ]. |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
734 |
|
22873 | 735 |
picos := 0. |
736 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
737 |
aStream atEnd ifTrue:[ |
17071 | 738 |
hour := min := sec := millis := 0. |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
739 |
] ifFalse:[ |
17071 | 740 |
[(ch := aStream peekOrNil) notNil and:[ch isDigit not]] whileTrue:[aStream next]. |
741 |
hour := Integer readFrom:aStream onError:-1. |
|
742 |
(hour between:0 and:24) ifFalse:[ TimeConversionError raiseErrorString:' - bad hour' ]. |
|
743 |
||
744 |
[(ch := aStream peekOrNil) notNil and:[ch isDigit not]] whileTrue:[aStream next]. |
|
745 |
min := Integer readFrom:aStream onError:-1. |
|
746 |
(min between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad minute' ]. |
|
747 |
||
748 |
aStream atEnd ifTrue:[ |
|
749 |
sec := millis := 0. |
|
750 |
] ifFalse:[ |
|
751 |
[(ch := aStream peekOrNil) notNil and:[ch isDigit not]] whileTrue:[aStream next]. |
|
752 |
sec := Integer readFrom:aStream onError:-1. |
|
753 |
(sec between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad second' ]. |
|
754 |
||
22873 | 755 |
(aStream peek == $. or:[aStream peek == $,]) ifTrue:[ |
17071 | 756 |
aStream next. |
22873 | 757 |
mantissa := Number readMantissaAndScaleFrom:aStream radix:10. |
758 |
fraction := (mantissa at:2) / (10 raisedTo:(mantissa at:3)). |
|
759 |
(mantissa at:3) > 3 ifTrue:[ |
|
760 |
picos := fraction * (1000 * 1000 * 1000 * 1000). |
|
761 |
millis := picos // (1000 * 1000 * 1000). |
|
762 |
picos := picos \\ (1000 * 1000 * 1000). |
|
763 |
] ifFalse:[ |
|
764 |
millis := fraction * 1000. |
|
765 |
]. |
|
766 |
"/ millis := Integer readFrom:aStream onError:0. |
|
767 |
"/ millis >= 1000 ifTrue:[ TimeConversionError raiseErrorString:' - bad millisecond' ]. |
|
17071 | 768 |
] ifFalse:[ |
769 |
millis := 0. |
|
770 |
]. |
|
771 |
aStream atEnd ifFalse:[ |
|
772 |
utcOffsetOrNil := self utcOffsetFrom:aStream |
|
773 |
]. |
|
774 |
]. |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
775 |
]. |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
776 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
777 |
"special check - only 24:00:00 is allowed; |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
778 |
every time after that must wrap" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
779 |
hour == 24 ifTrue:[ |
17071 | 780 |
(min ~~ 0 or:[sec ~~ 0 or:[millis ~~ 0]]) ifTrue:[ TimeConversionError raiseErrorString:' - bad hour' ]. |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
781 |
]. |
22894 | 782 |
|
16967 | 783 |
utcOffsetOrNil notNil ifTrue:[ |
17071 | 784 |
utcOffsetOrNil = 0 ifTrue:[ |
785 |
"/ utc timestamp |
|
22894 | 786 |
ts := UtcTimestamp year:year month:month day:day hour:hour minute:min second:sec millisecond:millis |
787 |
] ifFalse:[ |
|
788 |
"/ tz timestamp |
|
789 |
ts := ((TZTimestamp basicNew |
|
790 |
setOSTimeFromUTCYear:year month:month day:day |
|
791 |
hour:hour minute:min second:sec millisecond:millis |
|
792 |
) utcOffset:utcOffsetOrNil |
|
793 |
) addSeconds:utcOffsetOrNil. |
|
17071 | 794 |
]. |
22894 | 795 |
] ifFalse:[ |
796 |
"/ a local timestamp |
|
797 |
ts := self year:year month:month day:day hour:hour minute:min second:sec millisecond:millis. |
|
16967 | 798 |
]. |
22873 | 799 |
picos ~~ 0 ifTrue:[ ts additionalPicoseconds:picos ]. |
800 |
^ ts |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
801 |
|
17081 | 802 |
"some ad hoc formats: |
16914 | 803 |
|
16945 | 804 |
Timestamp basicReadFrom:'20-2-1995 13:11:06' readStream |
805 |
Timestamp basicReadFrom:'20-2-1995 13:11:06.' readStream |
|
17081 | 806 |
Timestamp basicReadFrom:'20-feb-1995 13:11:06' readStream |
807 |
Timestamp basicReadFrom:'20-foo-1995 13:11:06' readStream |
|
16945 | 808 |
(Timestamp basicReadFrom:'10-9-1995 13:11:06' readStream) month - european |
16935 | 809 |
(Timestamp basicReadFrom:'10/9/1995 13:11:06' readStream) month - us |
16945 | 810 |
Timestamp basicReadFrom:'20-2-1995 13:11' readStream |
811 |
Timestamp basicReadFrom:'20-2-1995 13:11:06.100' readStream |
|
17081 | 812 |
Timestamp basicReadFrom:'20-2-1995 13:11:06.100 MESZ' readStream |
813 |
Timestamp basicReadFrom:'20-2-1995 13:11:06.100+0200' readStream |
|
16945 | 814 |
Timestamp basicReadFrom:'32-2-1995 13:11:06.100' readStream |
815 |
Timestamp basicReadFrom:'32-foo-1995 13:11:06.100' readStream |
|
816 |
Timestamp basicReadFrom:'20-13-1995 13:11:06.100' readStream |
|
817 |
Timestamp basicReadFrom:'20-12-1995 25:11:06.100' readStream |
|
818 |
Timestamp basicReadFrom:'20-12-1995 23:61:06.100' readStream |
|
819 |
Timestamp basicReadFrom:'20-12-1995 23:10:66.100' readStream |
|
820 |
Timestamp basicReadFrom:'20-12-1995 23:10:00.1000' readStream |
|
821 |
Timestamp basicReadFrom:'20-2-1995 24:01:00.100' readStream |
|
822 |
Timestamp basicReadFrom:'20-2-1995 24:00:01.100' readStream |
|
823 |
Timestamp basicReadFrom:'foo' readStream |
|
16914 | 824 |
|
825 |
any iso8601 format:. |
|
16945 | 826 |
Timestamp basicReadFrom:(Timestamp now printString readStream) |
827 |
Timestamp basicReadFrom:'1995-10-20 24:00:00.000' readStream |
|
828 |
Timestamp basicReadFrom:'1995-10-20 12:10:00.000' readStream |
|
17081 | 829 |
Timestamp basicReadFrom:'1995-10-20 12:10:00.000-0200' readStream |
16945 | 830 |
|
831 |
UtcTimestamp basicReadFrom:'1995-10-20 12:10:00.000' readStream |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
832 |
" |
22337 | 833 |
|
834 |
"Modified: / 09-11-2017 / 10:10:07 / cg" |
|
23564 | 835 |
"Modified: / 14-12-2018 / 19:22:17 / Claus Gittinger" |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
836 |
! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
837 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
838 |
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
839 |
"common helper for read methods. |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
840 |
Return a new Timestamp, reading an iso8601 representation from aStream. |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
841 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
842 |
If the time ends with a 'Z' it is the UTC (or zulu) time, |
16292 | 843 |
otherwise it is local time. |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
844 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
845 |
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
|
846 |
is the same as 1999-01-01T24:00:00. |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
847 |
Missing minute, second and ms values are replaced with 0; |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
848 |
i.e. 1999T12 is the same as 1999-01-01T12:00:00.000. |
16292 | 849 |
Partial hours, minutes, seconds are allowed at the end, |
16914 | 850 |
decimal separators are both $. and $, . |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
851 |
Of course, a 24 hour clock is used. |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
852 |
On error, raise an exception. |
16914 | 853 |
Please use this format for all external representations - it's the standard." |
854 |
||
855 |
"/ changed to use the new reader |
|
16945 | 856 |
^ TimestampISO8601Builder |
17006 | 857 |
read:aStringOrStream withClass:self |
858 |
yearAlreadyReadAs:yearOrNil |
|
16914 | 859 |
|
860 |
"/ |str day month dayInWeek week year hour min sec tmpDay millis fraction isUtcTime peekChar ch| |
|
861 |
"/ |
|
862 |
"/ str := aStringOrStream readStream. |
|
863 |
"/ |
|
864 |
"/ month := day := 1. |
|
865 |
"/ hour := millis := 0. |
|
866 |
"/ isUtcTime := false. |
|
867 |
"/ |
|
868 |
"/ yearOrNil notNil ifTrue:[ |
|
869 |
"/ year := yearOrNil |
|
870 |
"/ ] ifFalse:[ |
|
871 |
"/ year := Integer readFrom:str onError:nil. |
|
872 |
"/ year isNil ifTrue:[ TimeConversionError raiseErrorString:' - bad year' ] |
|
873 |
"/ ]. |
|
874 |
"/ |
|
875 |
"/ str skipSeparators. |
|
876 |
"/ (((ch := str peek) == $-) or:[ch == $W]) ifTrue:[ |
|
877 |
"/ (ch == $-) ifTrue:[ str next ]. |
|
878 |
"/ str peek == $W ifTrue:[ |
|
879 |
"/ str next. |
|
880 |
"/ |
|
881 |
"/ "/ week follows |
|
882 |
"/ week := Integer readFrom:str onError:-1. |
|
883 |
"/ (week between:1 and:53) ifFalse:[ TimeConversionError raiseErrorString:' - bad week' ]. |
|
884 |
"/ |
|
885 |
"/ str skipSeparators. |
|
886 |
"/ str peek == $- ifTrue:[ |
|
887 |
"/ str next. |
|
888 |
"/ "/ day follows. |
|
889 |
"/ dayInWeek := Integer readFrom:str onError:-1. |
|
890 |
"/ (dayInWeek between:1 and:7) ifFalse:[ TimeConversionError raiseErrorString:' - bad day in week' ]. |
|
891 |
"/ ] ifFalse:[ |
|
892 |
"/ dayInWeek := 1. |
|
893 |
"/ ]. |
|
894 |
"/ tmpDay := Date newDayInWeek:dayInWeek week:week year:year. |
|
895 |
"/ day := tmpDay day. |
|
896 |
"/ month := tmpDay month. |
|
897 |
"/ year := tmpDay year. |
|
898 |
"/ ] ifFalse:[ |
|
899 |
"/ "/ month follows. |
|
900 |
"/ month := Integer readFrom:str onError:-1. |
|
901 |
"/ (month between:1 and:12) ifFalse:[ TimeConversionError raiseErrorString:' - bad month' ]. |
|
902 |
"/ |
|
903 |
"/ str skipSeparators. |
|
904 |
"/ str peek == $- ifTrue:[ |
|
905 |
"/ str next. |
|
906 |
"/ "/ day follows. |
|
907 |
"/ day := Integer readFrom:str onError:-1. |
|
908 |
"/ (day between:1 and:31) ifFalse:[ TimeConversionError raiseErrorString:' - bad day' ]. |
|
909 |
"/ ]. |
|
910 |
"/ ]. |
|
911 |
"/ ]. |
|
912 |
"/ |
|
913 |
"/ str skipSeparators. |
|
914 |
"/ str atEnd ifFalse:[ |
|
915 |
"/ "time follows" |
|
916 |
"/ |
|
917 |
"/ str peek == $T ifTrue:[ |
|
918 |
"/ "we treat the T as optional here" |
|
919 |
"/ str next. |
|
920 |
"/ str skipSeparators. |
|
921 |
"/ ]. |
|
922 |
"/ hour := Integer readFrom:str onError:-1. |
|
923 |
"/ (hour between:0 and:24) ifFalse:[ TimeConversionError raiseErrorString:' - bad hour' ]. |
|
924 |
"/ str skipSeparators. |
|
925 |
"/ str peekOrNil == $: ifTrue:[ |
|
926 |
"/ str next. |
|
927 |
"/ "/ minutes follow. |
|
928 |
"/ min := Integer readFrom:str onError:-1. |
|
929 |
"/ (min between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad minute' ]. |
|
930 |
"/ str skipSeparators. |
|
931 |
"/ str peekOrNil == $: ifTrue:[ |
|
932 |
"/ str next. |
|
933 |
"/ "/ seconds follow. |
|
934 |
"/ sec := Integer readFrom:str onError:-1. |
|
935 |
"/ (sec between:0 and:59) ifFalse:[ TimeConversionError raiseErrorString:' - bad seconds' ]. |
|
936 |
"/ str skipSeparators. |
|
937 |
"/ ]. |
|
938 |
"/ ]. |
|
939 |
"/ |
|
940 |
"/ peekChar := str peekOrNil. |
|
941 |
"/ (peekChar == $. or:[peekChar == $,]) ifTrue:[ |
|
942 |
"/ str next. |
|
943 |
"/ "/ decimals follow. |
|
944 |
"/ fraction := Number readMantissaFrom:str radix:10. |
|
945 |
"/ min isNil ifTrue:[ |
|
946 |
"/ min := 60 * fraction. |
|
947 |
"/ fraction := min fractionPart. |
|
948 |
"/ min := min truncated. |
|
949 |
"/ ]. |
|
950 |
"/ (sec isNil and:[fraction ~= 0])ifTrue:[ |
|
951 |
"/ sec := 60 * fraction. |
|
952 |
"/ fraction := sec fractionPart. |
|
953 |
"/ sec := sec truncated. |
|
954 |
"/ ]. |
|
955 |
"/ fraction ~= 0 ifTrue:[ |
|
956 |
"/ millis := (1000 * fraction) rounded. "/ mhmh - should it be truncated ? |
|
957 |
"/ ]. |
|
958 |
"/ ]. |
|
16945 | 959 |
"/ |
16914 | 960 |
"/ peekChar := str peekOrNil. |
961 |
"/ peekChar notNil ifTrue:[ |
|
962 |
"/ peekChar == $Z ifTrue:[ |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
963 |
"/ str next. |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
964 |
"/ isUtcTime := true. |
16914 | 965 |
"/ ] ifFalse:[ |
966 |
"/ ((peekChar == $+) or:[peekChar == $- ]) ifTrue:[ |
|
967 |
"/ str next. |
|
968 |
"/ self halt. |
|
969 |
"/ isUtcTime := true. |
|
970 |
"/ ] |
|
971 |
"/ ] |
|
972 |
"/ ]. |
|
973 |
"/ ]. |
|
974 |
"/ |
|
975 |
"/ min isNil ifTrue:[min := 0]. |
|
976 |
"/ sec isNil ifTrue:[sec := 0]. |
|
977 |
"/ |
|
978 |
"/ "special check - only 24:00:00 is allowed; |
|
979 |
"/ every time after that must wrap" |
|
980 |
"/ hour == 24 ifTrue:[ |
|
981 |
"/ (min ~~ 0 or:[sec ~~ 0 or:[millis ~~ 0]]) ifTrue:[ TimeConversionError raiseErrorString:' - bad hour' ]. |
|
982 |
"/ ]. |
|
983 |
"/ |
|
984 |
"/ isUtcTime ifTrue:[ |
|
16945 | 985 |
"/ ^ self |
986 |
"/ UTCYear:year month:month day:day |
|
16914 | 987 |
"/ hour:hour minute:min second:sec millisecond:millis. |
988 |
"/ ] ifFalse:[ |
|
16945 | 989 |
"/ ^ self |
990 |
"/ year:year month:month day:day |
|
16914 | 991 |
"/ hour:hour minute:min second:sec millisecond:millis. |
992 |
"/ ] |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
993 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
994 |
" |
16945 | 995 |
Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06.123' |
996 |
Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06' |
|
997 |
Timestamp readIso8601FormatFrom:'1995-02T13:11:06' |
|
998 |
Timestamp readIso8601FormatFrom:'1995T13:11:06' |
|
999 |
Timestamp readIso8601FormatFrom:'1995T13:11' |
|
1000 |
Timestamp readIso8601FormatFrom:'1995T13:11.5' |
|
1001 |
Timestamp readIso8601FormatFrom:'1995T13:11,5' |
|
1002 |
Timestamp readIso8601FormatFrom:'1995T13' |
|
1003 |
Timestamp readIso8601FormatFrom:'1995T13.25' |
|
1004 |
Timestamp readIso8601FormatFrom:'1995T13.333333' |
|
1005 |
Timestamp readIso8601FormatFrom:'1995' |
|
1006 |
||
1007 |
Timestamp readIso8601FormatFrom:'2014W40' -> 29.sep.2014 |
|
1008 |
Timestamp readIso8601FormatFrom:'2014W44-4' -> 30.oct.2014 |
|
1009 |
Timestamp readIso8601FormatFrom:'2014W1' -> 30.dec.2013 !!!!!! (this week starts in the previous year) |
|
1010 |
Timestamp readIso8601FormatFrom:'2014W1-1' -> same 30.dec.2013 !!!!!! (this week starts in the previous year) |
|
1011 |
Timestamp readIso8601FormatFrom:'2014W1-2' -> 31.dec.2013 !!!!!! (this week starts in the previous year) |
|
1012 |
Timestamp readIso8601FormatFrom:'2014W1-3' -> 1.jan.2014 !!!!!! (this week starts in the previous year) |
|
1013 |
||
1014 |
Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06' |
|
1015 |
Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06Z' |
|
1016 |
||
1017 |
Timestamp readIso8601FormatFrom:'1995-02-20 13:11' |
|
1018 |
Timestamp readIso8601FormatFrom:'1995-02-20 13' |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
1019 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
1020 |
24 is allowed with ISO, and is 00:00 of the next day: |
16945 | 1021 |
Timestamp readIso8601FormatFrom:'1995-02-20 24:00:00' |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
1022 |
" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
1023 |
! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
1024 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
1025 |
readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil onError:exceptionValue |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
1026 |
"common helper for read methods." |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
1027 |
|
21388 | 1028 |
^ [ |
1029 |
self readIso8601FormatFrom:aStringOrStream yearAlreadyRead:yearOrNil |
|
1030 |
] on:ConversionError do:exceptionValue. |
|
1031 |
||
1032 |
"Modified: / 09-02-2017 / 10:01:27 / stefan" |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
1033 |
! ! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
1034 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
1035 |
!Timestamp class methodsFor:'reading'! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
1036 |
|
14713 | 1037 |
readFrom:aStringOrStream format:formatString language:languageOrNil onError:exceptionalValue |
1038 |
"return a new Timestamp, reading a printed representation from aStream using a formatString. |
|
1039 |
The formatString is similar to the one used when printing. |
|
16945 | 1040 |
On error, exceptionalValue is returned. |
16914 | 1041 |
If exceptionalValue is a one-arg block, an error message is passed as argument. |
1042 |
Format: |
|
18441 | 1043 |
%h hours, 00..23 (i.e. european) 0-padded to length 2 |
1044 |
%u hours, 00..12 (i.e. us) 0-padded to length 2 |
|
1045 |
%m minutes, 00..59 0-padded to length 2 |
|
1046 |
%s seconds, 00..59 0-padded to length 2 |
|
1047 |
%i milliseconds, 000..999 0-padded to length 3 |
|
19923 | 1048 |
%f fractional seconds any length, but only milliseconds kept |
22894 | 1049 |
%F fractional seconds any length, up to picoseconds kept |
18441 | 1050 |
%a am/pm |
22885 | 1051 |
%tz timezone |
18441 | 1052 |
|
1053 |
%d - day |
|
1054 |
%D - day |
|
1055 |
%(day) - day |
|
18447 | 1056 |
%(dayOfYear) - 1..365/366 |
18441 | 1057 |
|
1058 |
%(month) - month |
|
1059 |
||
1060 |
%(monthName) - monthName |
|
1061 |
||
1062 |
%(year) - year, full 4 digits |
|
1063 |
%Y - year, last 2 digits only, |
|
1064 |
0..71 map to 2000..2071; |
|
1065 |
72..99 map to 1972..1999; |
|
1066 |
%Y1900 - year, last 2 digits only, map to 1900..1999 |
|
1067 |
%Y2000 - year, last 2 digits only, map to 2000..2099 |
|
18445 | 1068 |
%Y1950 - year, last 2 digits only, map to 1950..2049 |
1069 |
%Y1980 - year, last 2 digits only, map to 1980..2079 |
|
22873 | 1070 |
%Y1970 - year, last 2 digits only, map to 1970..2069 |
14713 | 1071 |
|
16914 | 1072 |
an optional length after the % gives a field length; |
18441 | 1073 |
i.e. %2h%2m%2s parses '123557' as 12:35:37 |
1074 |
and '%4(year)%2(month)%2(day)' parses '20060620' as 2006-06-20 00:00:00 |
|
16914 | 1075 |
|
1076 |
Please consider using a standard format, such as iso8601. |
|
1077 |
" |
|
14713 | 1078 |
|
18447 | 1079 |
|day month year dayOfYear monthAndDay |
14713 | 1080 |
hour minute second millisecond |
16945 | 1081 |
utcOffset inStream formatStream error fChar format itemHandler |
23239 | 1082 |
len s fractionString fraction picos ts| |
14713 | 1083 |
|
16945 | 1084 |
error := [:msg | |
18441 | 1085 |
exceptionalValue isBlock ifTrue:[ |
18445 | 1086 |
^ exceptionalValue valueWithOptionalArgument:'format error' |
18441 | 1087 |
] ifFalse:[ |
1088 |
^ exceptionalValue value |
|
1089 |
]. |
|
1090 |
]. |
|
14713 | 1091 |
|
1092 |
itemHandler := [:format | |
|
18441 | 1093 |
|input| |
18445 | 1094 |
|
18441 | 1095 |
input := len isNil ifTrue:[ inStream ] ifFalse:[ inStream next: len ]. |
1096 |
||
1097 |
( #('d' 'D' 'day' ) includes:format ) ifTrue:[ |
|
1098 |
day := Integer readFrom:input onError:[ error value:'invalid day' ]. |
|
1099 |
||
1100 |
] ifFalse:[ ( format = 'month' ) ifTrue:[ |
|
1101 |
month := Integer readFrom:input onError:[ error value:'invalid month' ]. |
|
1102 |
||
1103 |
] ifFalse:[ ( format = 'year' or:[ format = 'y' ]) ifTrue:[ |
|
1104 |
year := Integer readFrom:input onError:[ error value:'invalid year' ]. |
|
1105 |
||
1106 |
] ifFalse:[ ( format = 'Y' ) ifTrue:[ |
|
1107 |
year := Integer readFrom:input onError:[ error value:'invalid year' ]. |
|
1108 |
(year between:0 and: 99) ifFalse:[ error value:'invalid year' ]. |
|
18449 | 1109 |
(year < 70) ifTrue:[ |
1110 |
year := year + 2000 |
|
1111 |
] ifFalse:[ |
|
18441 | 1112 |
year := year + 1900 |
1113 |
] |
|
1114 |
||
1115 |
] ifFalse:[ (format = 'monthName') ifTrue:[ |
|
1116 |
s := input nextMatching:[:c | c isLetter] thenMatching:[:c | c isLetter]. |
|
1117 |
month := Date indexOfMonth:s asLowercase language:languageOrNil |
|
1118 |
||
18447 | 1119 |
] ifFalse:[ (format = 'dayOfYear') ifTrue:[ |
1120 |
dayOfYear := Integer readFrom:input onError:[ error value:'invalid day of year' ]. |
|
1121 |
||
18445 | 1122 |
] ifFalse:[ ( format sameAs: 'Y1900' ) ifTrue:[ |
18441 | 1123 |
year := Integer readFrom:input onError:[ error value:'invalid year' ]. |
1124 |
(year between:0 and: 99) ifFalse:[ error value:'invalid year' ]. |
|
1125 |
year := year + 1900 |
|
1126 |
||
18445 | 1127 |
] ifFalse:[ ( format sameAs: 'Y1950' ) ifTrue:[ |
1128 |
year := Integer readFrom:input onError:[ error value:'invalid year' ]. |
|
1129 |
(year between:0 and: 99) ifFalse:[ error value:'invalid year' ]. |
|
1130 |
(year between:0 and: 49) ifTrue:[ |
|
1131 |
year := year + 2000 |
|
1132 |
] ifFalse:[ |
|
1133 |
year := year + 1900 |
|
1134 |
] |
|
1135 |
||
1136 |
] ifFalse:[ ( format sameAs: 'Y1980' ) ifTrue:[ |
|
1137 |
year := Integer readFrom:input onError:[ error value:'invalid year' ]. |
|
1138 |
(year between:0 and: 99) ifFalse:[ error value:'invalid year' ]. |
|
1139 |
(year between:0 and: 79) ifTrue:[ |
|
1140 |
year := year + 2000 |
|
1141 |
] ifFalse:[ |
|
1142 |
year := year + 1900 |
|
1143 |
] |
|
1144 |
||
22873 | 1145 |
] ifFalse:[ ( format sameAs: 'Y1970' ) ifTrue:[ |
1146 |
year := Integer readFrom:input onError:[ error value:'invalid year' ]. |
|
1147 |
(year between:0 and: 99) ifFalse:[ error value:'invalid year' ]. |
|
1148 |
(year between:0 and: 69) ifTrue:[ |
|
1149 |
year := year + 2000 |
|
1150 |
] ifFalse:[ |
|
1151 |
year := year + 1900 |
|
1152 |
] |
|
1153 |
||
18445 | 1154 |
] ifFalse:[ ( format sameAs: 'Y2000' ) ifTrue:[ |
18441 | 1155 |
year := Integer readFrom:input onError:[ error value:'invalid year' ]. |
1156 |
(year between:0 and: 99) ifFalse:[ error value:'invalid year' ]. |
|
1157 |
year := year + 2000 |
|
1158 |
||
1159 |
] ifFalse:[ ( format = 'h' or:[ format = 'H' ]) ifTrue:[ |
|
1160 |
hour := Integer readFrom:input onError:[ error value:'invalid hour' ]. |
|
1161 |
||
1162 |
] ifFalse:[ ( format = 'u' or:[ format = 'U']) ifTrue:[ |
|
1163 |
hour := Integer readFrom:input onError:[ error value:'invalid hour' ]. |
|
1164 |
||
1165 |
] ifFalse:[ ( format = 'm' or:[ format = 'M' ]) ifTrue:[ |
|
1166 |
minute := Integer readFrom:input onError:[ error value:'invalid minute' ]. |
|
1167 |
||
1168 |
] ifFalse:[ ( format = 's' or:[ format = 'S' ]) ifTrue:[ |
|
1169 |
second := Integer readFrom:input onError:[ error value:'invalid second' ]. |
|
1170 |
||
1171 |
] ifFalse:[ ( format = 'i' or:[ format = 'I' ]) ifTrue:[ |
|
1172 |
millisecond := Integer readFrom:input onError:[ error value:'invalid month' ]. |
|
1173 |
||
19923 | 1174 |
] ifFalse:[ ( format = 'f' or:[ format = 'F' ]) ifTrue:[ |
1175 |
fractionString := input upToMatching:[:ch | ch isDigit not]. |
|
1176 |
fraction := FixedPoint readFrom:'0.',fractionString. |
|
22894 | 1177 |
format = 'f' ifTrue:[ |
1178 |
millisecond := (fraction * 1000) truncated. |
|
1179 |
] ifFalse:[ |
|
1180 |
picos := (fraction * 1000*1000*1000*1000) truncated. |
|
1181 |
millisecond := picos // (1000*1000*1000). |
|
1182 |
picos := picos \\ (1000*1000*1000). |
|
1183 |
]. |
|
18441 | 1184 |
] ifFalse:[ ( format = 'tz' ) ifTrue:[ |
1185 |
utcOffset := self utcOffsetFrom:input. |
|
1186 |
utcOffset isNil ifTrue:[ error value:'invalid timezone' ] |
|
1187 |
] ifFalse:[ ( format = 'a' ) ifTrue:[ |
|
1188 |
s := (input next:2) asLowercase. |
|
1189 |
s = 'am' ifTrue:[ |
|
1190 |
(hour between:0 and:12) ifFalse:[ error value:'invalid hour' ] |
|
1191 |
] ifFalse:[ |
|
1192 |
s = 'pm' ifTrue:[ |
|
1193 |
(hour between:1 and:12) ifFalse:[ error value:'invalid hour' ]. |
|
1194 |
hour := hour + 12. |
|
1195 |
] ifFalse:[ |
|
1196 |
error value:'invalid am/pm' |
|
1197 |
] |
|
1198 |
] |
|
1199 |
||
1200 |
] ifFalse:[ |
|
1201 |
error value:'unhandled format:',format |
|
22873 | 1202 |
]]]]]]]]]]]]]]]]]]] |
18445 | 1203 |
]. |
14713 | 1204 |
|
1205 |
hour := 0. |
|
1206 |
minute := 0. |
|
1207 |
second := 0. |
|
1208 |
millisecond := 0. |
|
1209 |
||
1210 |
inStream := aStringOrStream readStream. |
|
1211 |
formatStream := formatString readStream. |
|
1212 |
||
1213 |
[formatStream atEnd] whileFalse:[ |
|
18441 | 1214 |
fChar := formatStream next. |
1215 |
fChar = Character space ifTrue:[ |
|
1216 |
inStream peek isSeparator ifFalse:[ error value: 'format error; space expcected' ]. |
|
1217 |
inStream skipSeparators. |
|
1218 |
] ifFalse:[ |
|
1219 |
fChar == $% ifTrue:[ |
|
1220 |
len := nil. |
|
1221 |
(formatStream peek isDigit) ifTrue:[ |
|
1222 |
len := Integer readFrom:formatStream onError:[ error value: 'format error; invalid length' ] |
|
1223 |
]. |
|
1224 |
(formatStream peek == $() ifTrue:[ |
|
1225 |
formatStream next. |
|
1226 |
format := formatStream upTo:$). |
|
1227 |
] ifFalse:[ |
|
1228 |
(formatStream peek == ${) ifTrue:[ |
|
1229 |
formatStream next. |
|
1230 |
format := formatStream upTo:$}. |
|
1231 |
] ifFalse:[ |
|
1232 |
(formatStream peek isLetter) ifTrue:[ |
|
1233 |
format := formatStream nextAlphaNumericWord. |
|
1234 |
] ifFalse:[ |
|
1235 |
error value:'unhandled format:',formatStream peek |
|
1236 |
] |
|
1237 |
] |
|
1238 |
]. |
|
1239 |
itemHandler value:format. |
|
1240 |
] ifFalse:[ |
|
1241 |
inStream peek = fChar ifFalse:[^ error value: 'format error; ',fChar,' expcected']. |
|
1242 |
inStream next. |
|
1243 |
] |
|
1244 |
]. |
|
14713 | 1245 |
]. |
1246 |
||
1247 |
year isNil ifTrue:[ |
|
23239 | 1248 |
year := Timestamp now year |
14713 | 1249 |
]. |
18447 | 1250 |
|
1251 |
dayOfYear notNil ifTrue:[ |
|
1252 |
monthAndDay := Date monthAndDayFromDayInYear:dayOfYear forYear:year. |
|
1253 |
month := (monthAndDay at:1). |
|
1254 |
day := (monthAndDay at:2). |
|
1255 |
]. |
|
22885 | 1256 |
|
1257 |
utcOffset notNil ifTrue:[ |
|
1258 |
utcOffset == 0 ifTrue:[ |
|
22894 | 1259 |
ts := (UtcTimestamp |
22885 | 1260 |
year:year month:month day:day |
1261 |
hour:(hour ? 0) minute:(minute ? 0) second:(second ? 0) millisecond:millisecond) |
|
22894 | 1262 |
] ifFalse:[ |
1263 |
ts := ((TZTimestamp basicNew |
|
1264 |
setOSTimeFromUTCYear:year month:month day:day |
|
1265 |
hour:(hour ? 0) minute:(minute ? 0) second:(second ? 0) millisecond:millisecond |
|
1266 |
) utcOffset:utcOffset |
|
1267 |
) addSeconds:utcOffset. |
|
1268 |
] |
|
1269 |
] ifFalse:[ |
|
1270 |
ts := (self |
|
22885 | 1271 |
year:year month:month day:day |
22894 | 1272 |
hour:(hour ? 0) minute:(minute ? 0) second:(second ? 0) millisecond:millisecond) |
22885 | 1273 |
]. |
22894 | 1274 |
picos notNil ifTrue:[ |
1275 |
ts additionalPicoseconds:picos |
|
1276 |
]. |
|
1277 |
^ ts. |
|
14713 | 1278 |
|
1279 |
" |
|
16945 | 1280 |
Timestamp readFrom:'20-2-1995 13:11:06' format:'%day-%month-%year %h:%m:%s' language:nil onError:[self halt] |
1281 |
Timestamp readFrom:'20021995131106' format:'%2d%2month%4y%2h%2m%2s' language:nil onError:[self halt] |
|
18445 | 1282 |
Timestamp readFrom:'200295131106' format:'%2d%2month%2y%2h%2m%2s' language:nil onError:[self halt] |
1283 |
Timestamp readFrom:'200260131106' format:'%2d%2month%2(y1900)%2h%2m%2s' language:nil onError:[self halt] |
|
1284 |
Timestamp readFrom:'200260131106' format:'%2d%2month%2(y2000)%2h%2m%2s' language:nil onError:[self halt] |
|
1285 |
Timestamp readFrom:'200260131106' format:'%2d%2month%2(y1950)%2h%2m%2s' language:nil onError:[self halt] |
|
1286 |
Timestamp readFrom:'200260131106' format:'%2d%2month%2(y1980)%2h%2m%2s' language:nil onError:[self halt] |
|
14713 | 1287 |
Timestamp readFrom:'March 7 2009 7:30pm EST' format:'%monthName %day %year %u:%m%a %tz' language:#en onError:[self halt] |
16945 | 1288 |
Timestamp readFrom:'March 7 2009 7:30pm UTC' format:'%monthName %day %year %u:%m%a %tz' language:#en onError:[self halt] |
18447 | 1289 |
Timestamp readFrom:'2015103' format:'%4y%3dayOfYear' onError:[self halt] |
19923 | 1290 |
|
1291 |
Timestamp readFrom:'20-2-1995 13:11:06.999' format:'%day-%month-%year %h:%m:%s.%i' language:nil onError:[self halt] |
|
1292 |
Timestamp readFrom:'20-2-1995 13:11:06.100' format:'%day-%month-%year %h:%m:%s.%i' language:nil onError:[self halt] |
|
1293 |
Timestamp readFrom:'20-2-1995 13:11:06.010' format:'%day-%month-%year %h:%m:%s.%i' language:nil onError:[self halt] |
|
1294 |
||
1295 |
Timestamp readFrom:'20-2-1995 13:11:06.1' format:'%day-%month-%year %h:%m:%s.%f' language:nil onError:[self halt] |
|
1296 |
Timestamp readFrom:'20-2-1995 13:11:06.01' format:'%day-%month-%year %h:%m:%s.%f' language:nil onError:[self halt] |
|
1297 |
Timestamp readFrom:'20-2-1995 13:11:06.001' format:'%day-%month-%year %h:%m:%s.%f' language:nil onError:[self halt] |
|
1298 |
Timestamp readFrom:'20-2-1995 13:11:06.12345' format:'%day-%month-%year %h:%m:%s.%f' language:nil onError:[self halt] |
|
14713 | 1299 |
" |
23239 | 1300 |
|
1301 |
"Modified: / 27-07-2018 / 11:57:59 / Stefan Vogel" |
|
14713 | 1302 |
! |
1303 |
||
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
1304 |
readFrom:aStringOrStream onError:exceptionBlock |
8246 | 1305 |
"return a new Timestamp, reading a printed representation from aStream. |
275 | 1306 |
The string is interpreted as 24 hour format, as printed. |
16945 | 1307 |
Notice, that this is not the storeString format and |
4898 | 1308 |
is different from the format expected by readFrom:. |
16914 | 1309 |
The format read here is either dd-mm-yyyy hh:mm:ss.iii |
1310 |
or iso8601 (if the first integer is >31). |
|
1311 |
||
1312 |
Please consider using a standard format, such as iso8601." |
|
275 | 1313 |
|
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1314 |
|stream newTime| |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1315 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1316 |
stream := aStringOrStream readStream. |
275 | 1317 |
|
7092
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7058
diff
changeset
|
1318 |
Error handle:[:ex | |
17006 | 1319 |
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
|
1320 |
] do:[ |
17006 | 1321 |
newTime := self basicReadFrom:stream. |
275 | 1322 |
]. |
3995
777470826394
no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
3510
diff
changeset
|
1323 |
^ newTime |
275 | 1324 |
|
1325 |
" |
|
16945 | 1326 |
Timestamp readFrom:'20-2-1995 13:11:06' |
1327 |
Timestamp readFrom:'20-2-1995 13:11' |
|
1328 |
Timestamp readFrom:'20-2-2001 13:11' |
|
1329 |
Timestamp readFrom:'20-2-1995 13:11:06.100' |
|
1330 |
Timestamp readFrom:'32-2-1995 13:11:06.100' onError:'wrong' |
|
1331 |
Timestamp readFrom:'32-foo-1995 13:11:06.100' onError:'wrong' |
|
1332 |
Timestamp readFrom:'20-2-1995 24:01:00.100' onError:'wrong' |
|
1333 |
Timestamp readFrom:'20-2-1995 24:00:01.100' onError:'wrong' |
|
1334 |
Timestamp readFrom:'2002-08-02 24:00:01.100' onError:'wrong' |
|
1335 |
Timestamp readFrom:'foo' onError:'wrong' |
|
1336 |
Timestamp readFrom:(Timestamp now storeString) onError:'wrong' |
|
275 | 1337 |
" |
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
1338 |
|
4378 | 1339 |
"Modified: / 8.10.1996 / 19:25:59 / cg" |
1340 |
"Modified: / 13.7.1999 / 12:31:14 / stefan" |
|
2311 | 1341 |
! |
1342 |
||
16945 | 1343 |
readGeneralizedFrom:aStringOrStream |
9620 | 1344 |
"return a new Timestamp, reading a printed representation from aStream. |
1345 |
The format read here is either |
|
19897 | 1346 |
yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format. |
9620 | 1347 |
or: |
19897 | 1348 |
yyyy-mm-dd HH:MM:SS.iii +uuuu. |
12166 | 1349 |
The string is interpreted as 24 hour format, as printed. |
1350 |
||
1351 |
This format is used for BER specification of the ASN.1 GeneralizedTime as defined in X.208 Sec. 33, |
|
1352 |
so read this before changing anything here. |
|
1353 |
||
16914 | 1354 |
New applications should consider using a standard format, such as iso8601. |
1355 |
||
16945 | 1356 |
Notice, that this is not the storeString format and |
12166 | 1357 |
is different from the format expected by readFrom:. |
9620 | 1358 |
" |
16914 | 1359 |
|
16945 | 1360 |
^ self |
19897 | 1361 |
readGeneralizedFrom:aStringOrStream |
1362 |
short:false |
|
1363 |
onError:[ |
|
1364 |
self conversionErrorSignal raiseWith:aStringOrStream errorString:' - Timestamp GeneralizedTime format error' |
|
1365 |
]. |
|
9620 | 1366 |
|
1367 |
"Created: / 22-08-2006 / 16:05:55 / cg" |
|
1368 |
! |
|
1369 |
||
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
1370 |
readGeneralizedFrom:aStringOrStream onError:exceptionBlock |
8246 | 1371 |
"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
|
1372 |
The format read here is either |
17006 | 1373 |
yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format. |
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
1374 |
or: |
17006 | 1375 |
yyyy-mm-dd HH:MM:SS.iii +uuuu. |
12166 | 1376 |
The string is interpreted as 24 hour format, as printed. |
1377 |
||
1378 |
This format is used for BER specification of the ASN.1 GeneralizedTime as defined in X.208 Sec. 33, |
|
1379 |
so read this before changing anything here. |
|
1380 |
||
16914 | 1381 |
New applications should consider using a standard format, such as iso8601. |
1382 |
||
16945 | 1383 |
Notice, that this is not the storeString format and |
12166 | 1384 |
is different from the format expected by readFrom:. |
1385 |
" |
|
1386 |
||
1387 |
^ self readGeneralizedFrom:aStringOrStream short:false onError:exceptionBlock |
|
1388 |
||
1389 |
" |
|
1390 |
|s| |
|
1391 |
s := '' writeStream. |
|
1392 |
Timestamp now printGeneralizedOn:s. |
|
1393 |
Timestamp readGeneralizedFrom:s contents onError:[] |
|
1394 |
||
1395 |
Daylight saving time: |
|
1396 |
||
1397 |
Timestamp readGeneralizedFrom:'20000718120000Z' onError:[] |
|
1398 |
Timestamp readGeneralizedFrom:'20000718120000+0200' onError:[] |
|
1399 |
Timestamp readGeneralizedFrom:'20000718120000+0300' onError:[] |
|
1400 |
||
1401 |
No daylight saving time: |
|
1402 |
||
1403 |
Timestamp readGeneralizedFrom:'20000202120000Z' onError:[] |
|
1404 |
Timestamp readGeneralizedFrom:'20000202120000+0100' onError:[] |
|
1405 |
Timestamp readGeneralizedFrom:'20000202120000+0200' onError:[] |
|
1406 |
||
16945 | 1407 |
Timestamp readGeneralizedFrom:'19950220131106' onError:[] |
1408 |
Timestamp readGeneralizedFrom:'199502201311' onError:[] |
|
1409 |
Timestamp readGeneralizedFrom:'19950220131106.100' onError:[] |
|
1410 |
Timestamp readGeneralizedFrom:'19950232131106.100' onError:'wrong' |
|
1411 |
Timestamp readGeneralizedFrom:'19950fo2131106.100' onError:'wrong' |
|
1412 |
Timestamp readGeneralizedFrom:'foo' onError:'wrong' |
|
1413 |
||
1414 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00' onError:[] |
|
12166 | 1415 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100' onError:[] |
16945 | 1416 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100 +0100' onError:[] |
12166 | 1417 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 -0100' onError:[] |
16945 | 1418 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 +0000' onError:[] |
12166 | 1419 |
" |
1420 |
||
1421 |
"Modified: / 13-07-1999 / 12:31:14 / stefan" |
|
1422 |
"Modified: / 22-08-2006 / 12:30:11 / cg" |
|
1423 |
! |
|
1424 |
||
1425 |
readGeneralizedFrom:aStringOrStream short:shortFormat onError:exceptionBlock |
|
1426 |
"return a new Timestamp, reading a printed representation from aStream. |
|
1427 |
The long format read here is either |
|
18761 | 1428 |
yyyymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format. |
1429 |
or: |
|
1430 |
yyyy-mm-dd HH:MM:SS.iii +uuuu. |
|
12166 | 1431 |
The (not recommended) short forms are: |
18761 | 1432 |
yymmddHHMMSS.iii+uuuu, which is the ASN1 GeneralizedTime format. |
1433 |
or: |
|
1434 |
yy-mm-dd HH:MM:SS.iii +uuuu. |
|
12166 | 1435 |
The string is interpreted as 24 hour format, as printed. |
1436 |
||
1437 |
This format is used for BER specification of the ASN.1 GeneralizedTime and |
|
1438 |
UTCTime as defined in X.208 Sec. 33, so read this before changing anything here. |
|
1439 |
The short form is no longer recommended. |
|
1440 |
||
16914 | 1441 |
New applications should consider using a standard format, such as iso8601. |
1442 |
||
16945 | 1443 |
Notice, that this is not the storeString format and |
12166 | 1444 |
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
|
1445 |
" |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
1446 |
|
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
1447 |
|
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6047
diff
changeset
|
1448 |
^ [ |
22653 | 1449 |
|newTime str day month year hour min sec millis c fraction| |
18761 | 1450 |
|
1451 |
sec := millis := 0. |
|
1452 |
str := aStringOrStream readStream. |
|
1453 |
||
1454 |
shortFormat ifTrue:[ |
|
1455 |
year := Integer readFrom:(str next:2). |
|
1456 |
year < 50 ifTrue:[ |
|
1457 |
year := year + 2000. |
|
1458 |
] ifFalse:[ |
|
1459 |
year := year + 1900. |
|
1460 |
]. |
|
1461 |
] ifFalse:[ |
|
1462 |
year := Integer readFrom:(str next:4). |
|
1463 |
]. |
|
1464 |
str peek == $- ifTrue:[ str next]. |
|
1465 |
month := Integer readFrom:(str next:2). |
|
1466 |
(month between:1 and:12) ifFalse:[^ exceptionBlock value]. |
|
1467 |
str peek == $- ifTrue:[ str next]. |
|
1468 |
day := Integer readFrom:(str next:2). |
|
1469 |
(day between:1 and:31) ifFalse:[^ exceptionBlock value]. |
|
1470 |
||
1471 |
str skipSeparators. |
|
1472 |
hour:= Integer readFrom:(str next:2). |
|
1473 |
(hour between:0 and:24) ifFalse:[^ exceptionBlock value]. |
|
1474 |
str peek == $: ifTrue:[ str next]. |
|
1475 |
min:= Integer readFrom:(str next:2). |
|
1476 |
(min between:0 and:59) ifFalse:[^ exceptionBlock value]. |
|
1477 |
str atEnd ifFalse:[ |
|
1478 |
str peek == $: ifTrue:[ str next]. |
|
1479 |
sec := Integer readFrom:(str next:2). |
|
1480 |
(sec between:0 and:59) ifFalse:[^ exceptionBlock value]. |
|
1481 |
str atEnd ifFalse:[ |
|
1482 |
str peek == $. ifTrue:[ |
|
1483 |
str next. |
|
22653 | 1484 |
"/ the old code here was wrong in assuming that exactly 3 digits |
1485 |
"/ are coming; thus hh:mm:ss.1 was interpreted as 1ms (instead of 100) |
|
1486 |
"/ thus: count the zeros... |
|
1487 |
str peek isDigit ifTrue:[ |
|
1488 |
fraction := Number readMantissaFrom:str radix:10. |
|
1489 |
fraction isNil ifTrue:[^ exceptionBlock value]. |
|
1490 |
millis := (fraction * 1000) rounded. |
|
1491 |
] ifFalse:[ |
|
1492 |
millis := 0 |
|
1493 |
]. |
|
18761 | 1494 |
]. |
1495 |
str skipSeparators. |
|
1496 |
]. |
|
1497 |
]. |
|
1498 |
||
1499 |
str atEnd ifTrue:[ |
|
1500 |
"/ this is local time |
|
1501 |
newTime := self year:year month:month day:day |
|
1502 |
hour:hour minute:min second:sec millisecond:millis. |
|
1503 |
] ifFalse:[ |
|
1504 |
c := str next. |
|
1505 |
c ~~ $Z ifTrue:[ |
|
1506 |
|tzh tzmin| |
|
1507 |
tzh := Integer readFrom:(str next:2). |
|
1508 |
tzmin := Integer readFrom:(str next:2). |
|
1509 |
c == $+ ifTrue:[ |
|
1510 |
"the timezone is ahead of UTC or EAST from Greenwich: subtract hours and minutes" |
|
1511 |
hour := hour - tzh. |
|
1512 |
min := min - tzmin. |
|
1513 |
] ifFalse:[ |
|
1514 |
c == $- ifTrue:[ |
|
1515 |
"the timezone is behind of UTC or WEST from Greenwich: add hours and minutes" |
|
1516 |
hour := hour + tzh. |
|
1517 |
min := min + tzmin. |
|
1518 |
] ifFalse:exceptionBlock |
|
1519 |
]. |
|
1520 |
]. |
|
1521 |
"this is UTC time" |
|
1522 |
newTime := self UTCYear:year month:month day:day |
|
1523 |
hour:hour minute:min second:sec millisecond:millis. |
|
1524 |
]. |
|
1525 |
newTime |
|
6624
886265eff14c
#readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents:
6047
diff
changeset
|
1526 |
] on:Error do:exceptionBlock. |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
1527 |
|
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
1528 |
" |
5656
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
1529 |
|s| |
dbc52ea02716
Fix UTC Time w.r.t. Daylight saving time.
Stefan Vogel <sv@exept.de>
parents:
5572
diff
changeset
|
1530 |
s := '' writeStream. |
8246 | 1531 |
Timestamp now printGeneralizedOn:s. |
1532 |
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
|
1533 |
|
16945 | 1534 |
Timestamp readGeneralizedFrom:'20080718120000+0300' short:false onError:[] |
1535 |
Timestamp readGeneralizedFrom:'080718120000+0300' short:true onError:[] |
|
1536 |
Timestamp readGeneralizedFrom:'990718120000+0300' short:true onError:[] |
|
12166 | 1537 |
|
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1538 |
Daylight saving time: |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1539 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1540 |
Timestamp readGeneralizedFrom:'20000718120000Z' onError:[] |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1541 |
Timestamp readGeneralizedFrom:'20000718120000+0200' onError:[] |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1542 |
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
|
1543 |
|
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1544 |
No daylight saving time: |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1545 |
|
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1546 |
Timestamp readGeneralizedFrom:'20000202120000Z' onError:[] |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1547 |
Timestamp readGeneralizedFrom:'20000202120000+0100' onError:[] |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
1548 |
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
|
1549 |
|
16945 | 1550 |
Timestamp readGeneralizedFrom:'19950220131106' onError:[] |
1551 |
Timestamp readGeneralizedFrom:'199502201311' onError:[] |
|
1552 |
Timestamp readGeneralizedFrom:'19950220131106.100' onError:[] |
|
1553 |
Timestamp readGeneralizedFrom:'19950232131106.100' onError:'wrong' |
|
1554 |
Timestamp readGeneralizedFrom:'19950fo2131106.100' onError:'wrong' |
|
1555 |
Timestamp readGeneralizedFrom:'foo' onError:'wrong' |
|
1556 |
||
1557 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00' onError:[] |
|
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
1558 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100' onError:[] |
16945 | 1559 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00.100 +0100' onError:[] |
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
1560 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 -0100' onError:[] |
16945 | 1561 |
Timestamp readGeneralizedFrom:'2000-02-02 12:00:00 +0000' onError:[] |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
1562 |
" |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
1563 |
|
9619
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
1564 |
"Modified: / 13-07-1999 / 12:31:14 / stefan" |
6f1fc553757f
skip dashes and colons in readGeneralizedFrom
Claus Gittinger <cg@exept.de>
parents:
9449
diff
changeset
|
1565 |
"Modified: / 22-08-2006 / 12:30:11 / cg" |
5292
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
1566 |
! |
a3936f79327b
Fix #readGeneralizedFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5291
diff
changeset
|
1567 |
|
16914 | 1568 |
readISO8601From:aStringOrStream |
22840 | 1569 |
"obsoleted due to uc/lc confusion" |
1570 |
||
21388 | 1571 |
<resource: #obsolete> |
1572 |
||
1573 |
^ self readIso8601FormatFrom:aStringOrStream |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
1574 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
1575 |
"Created: / 16-06-2005 / 16:13:36 / masca" |
21388 | 1576 |
"Modified: / 09-02-2017 / 10:04:53 / stefan" |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
1577 |
! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
1578 |
|
16914 | 1579 |
readISO8601From:aStringOrStream onError:exceptionValue |
22840 | 1580 |
"obsoleted due to uc/lc confusion" |
1581 |
||
21388 | 1582 |
<resource: #obsolete> |
1583 |
||
1584 |
^ self readIso8601FormatFrom:aStringOrStream onError:exceptionValue |
|
1585 |
||
1586 |
"Modified: / 09-02-2017 / 10:05:56 / stefan" |
|
16914 | 1587 |
! |
1588 |
||
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
1589 |
readIso8601FormatFrom:aStringOrStream |
8246 | 1590 |
"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
|
1591 |
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
|
1592 |
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
|
1593 |
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
|
1594 |
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
|
1595 |
Of course, a 24 hour clock is used. |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
1596 |
On error, raise an exception. |
16914 | 1597 |
|
1598 |
Please use this format for all external representations - it's the standard." |
|
1599 |
||
1600 |
"changed to use the new reader" |
|
1601 |
||
16945 | 1602 |
^ TimestampISO8601Builder read:aStringOrStream withClass:self |
16914 | 1603 |
"/ ^ self |
1604 |
"/ readIso8601FormatFrom:aStringOrStream yearAlreadyRead:nil |
|
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
1605 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
1606 |
" |
16921 | 1607 |
Timestamp readIso8601FormatFrom:'20141106T123843.299Z' |
1608 |
Timestamp readIso8601FormatFrom:'20141106T123843.299' |
|
1609 |
||
16945 | 1610 |
Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06' |
1611 |
Timestamp readIso8601FormatFrom:'1995-02T13:11:06' |
|
1612 |
Timestamp readIso8601FormatFrom:'1995T13:11:06' |
|
1613 |
Timestamp readIso8601FormatFrom:'1995T13:11' |
|
1614 |
Timestamp readIso8601FormatFrom:'1995T13' |
|
1615 |
Timestamp readIso8601FormatFrom:'1995' |
|
1616 |
||
1617 |
Timestamp readIso8601FormatFrom:'1995-02-20 13:11:06' |
|
1618 |
Timestamp readIso8601FormatFrom:'1995-02-20 13:11' |
|
1619 |
Timestamp readIso8601FormatFrom:'1995-02-20 13' |
|
1620 |
||
1621 |
Timestamp readIso8601FormatFrom:'20141106T122831.894Z' |
|
16921 | 1622 |
|
6684
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
1623 |
24 is allowed with ISO, and is 00:00 of the next day: |
16945 | 1624 |
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
|
1625 |
|
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
1626 |
" |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
1627 |
! |
1f4d15ab7c4c
default printString is now iso format.
Claus Gittinger <cg@exept.de>
parents:
6634
diff
changeset
|
1628 |
|
8432 | 1629 |
readIso8601FormatFrom:aStringOrStream onError:exceptionValue |
1630 |
"return a new Timestamp, reading an iso8601 UTC representation from aStream. |
|
1631 |
Missing month/day values are replaced with 1; i.e. 1999T24:00 |
|
1632 |
is the same as 1999-01-01T24:00:00. |
|
1633 |
Missing minute, second and ms values are replaced with 0; |
|
1634 |
i.e. 1999T12 is the same as 1999-01-01T12:00:00.000. |
|
1635 |
Of course, a 24 hour clock is used. |
|
1636 |
On error, raise an exception. |
|
16914 | 1637 |
|
1638 |
Please use this format for all external representations - it's the standard." |
|
1639 |
||
1640 |
"/ changed to use the new reader |
|
21388 | 1641 |
^ [ |
1642 |
TimestampISO8601Builder read:aStringOrStream withClass:self |
|
1643 |
] on:ConversionError do:exceptionValue. |
|
16914 | 1644 |
|
1645 |
"/ ^ self |
|
16945 | 1646 |
"/ readIso8601FormatFrom:aStringOrStream |
1647 |
"/ yearAlreadyRead:nil |
|
16914 | 1648 |
"/ onError:exceptionValue |
21388 | 1649 |
|
1650 |
"Modified: / 09-02-2017 / 10:02:03 / stefan" |
|
8432 | 1651 |
! |
1652 |
||
11847 | 1653 |
readRFC1123FormatFrom:rfc1123String onError:exceptionBlock |
16914 | 1654 |
"please use this only for http-requests. |
1655 |
All other programs should use iso8601, which is the standard for times and dates. |
|
1656 |
||
16945 | 1657 |
All HTTP/1.0 date/time stamps must be represented in Universal Time (UT), |
1658 |
also known as Greenwich Mean Time (GMT), without exception. |
|
1659 |
This is indicated in the first two formats by the inclusion of |
|
1660 |
'GMT' as the three-letter abbreviation for time zone, |
|
16914 | 1661 |
and should be assumed when reading the asctime format. |
1662 |
||
1663 |
HTTP-date = rfc1123-date | rfc850-date | asctime-date |
|
1664 |
||
1665 |
rfc1123-date = wkday ',' SP date1 SP time SP 'GMT' |
|
1666 |
rfc850-date = weekday ',' SP date2 SP time SP 'GMT' |
|
1667 |
asctime-date = wkday SP date3 SP time SP 4DIGIT |
|
1668 |
||
1669 |
date1 = 2DIGIT SP month SP 4DIGIT |
|
17081 | 1670 |
; day month year (e.g., 02 Jun 1982) |
16914 | 1671 |
date2 = 2DIGIT '-' month '-' 2DIGIT |
17081 | 1672 |
; day-month-year (e.g., 02-Jun-82) |
16914 | 1673 |
date3 = month SP ( 2DIGIT | ( SP 1DIGIT )) |
17081 | 1674 |
; month day (e.g., Jun 2) |
16914 | 1675 |
|
1676 |
time = 2DIGIT ':' 2DIGIT ':' 2DIGIT |
|
17081 | 1677 |
; 00:00:00 - 23:59:59 |
16914 | 1678 |
|
1679 |
wkday = 'Mon' | 'Tue' | 'Wed' |
|
17081 | 1680 |
| 'Thu' | 'Fri' | 'Sat' | 'Sun' |
16914 | 1681 |
|
1682 |
weekday = 'Monday' | 'Tuesday' | 'Wednesday' |
|
17081 | 1683 |
| 'Thursday' | 'Friday' | 'Saturday' | 'Sunday' |
16914 | 1684 |
|
1685 |
month = 'Jan' | 'Feb' | 'Mar' | 'Apr' |
|
17081 | 1686 |
| 'May' | 'Jun' | 'Jul' | 'Aug' |
1687 |
| 'Sep' | 'Oct' | 'Nov' | 'Dec' |
|
16914 | 1688 |
|
1689 |
Mon, 17 Aug 2009 11:11:15 GMT |
|
1690 |
||
1691 |
however, occasionally, someone presents us with non-UTC strings which include a timezone; |
|
1692 |
thus, this also supports: |
|
17081 | 1693 |
Mon, 17 Aug 2009 11:11:15 +xxxx |
1694 |
Mon, 17 Aug 2009 11:11:15 -xxxx |
|
16914 | 1695 |
and: |
17081 | 1696 |
Mon, 17 Aug 2009 11:11:15 PST |
16914 | 1697 |
" |
14713 | 1698 |
|
1699 |
|parts indexModifier utcOffsetString utcOffset day year time monthName month| |
|
11847 | 1700 |
|
1701 |
rfc1123String isEmptyOrNil ifTrue:[^ exceptionBlock value]. |
|
1702 |
||
17081 | 1703 |
parts := rfc1123String asCollectionOfSubstringsSeparatedBy:Character space. |
11862 | 1704 |
parts size == 6 ifTrue:[ |
17081 | 1705 |
indexModifier := 0. |
11862 | 1706 |
] ifFalse:[ |
17081 | 1707 |
parts size == 5 ifTrue:[ |
1708 |
indexModifier := -1. |
|
1709 |
] ifFalse:[ |
|
1710 |
^ exceptionBlock value |
|
1711 |
]. |
|
11862 | 1712 |
]. |
11847 | 1713 |
|
11862 | 1714 |
day := Integer readFrom:(parts at:2 + indexModifier) onError:[^ exceptionBlock]. |
1715 |
year := Integer readFrom:(parts at:4 + indexModifier) onError:[^ exceptionBlock]. |
|
1716 |
time := Time readFrom:(parts at:5 + indexModifier) onError:[^ exceptionBlock]. |
|
1717 |
monthName := parts at:3 + indexModifier. |
|
11847 | 1718 |
|
17081 | 1719 |
month := Date indexOfMonth:monthName language:#en. |
1720 |
month = 0 ifTrue:[^ exceptionBlock value]. |
|
1721 |
||
1722 |
utcOffsetString := parts at:6 + indexModifier ifAbsent:nil. |
|
1723 |
utcOffset := self utcOffsetFrom:utcOffsetString. |
|
1724 |
||
1725 |
(utcOffset isNil or:[utcOffset = 0]) ifTrue:[ |
|
1726 |
^ UtcTimestamp year:year month:month day:day hour:time hour minute:time minute second:time second millisecond:0. |
|
1727 |
]. |
|
22894 | 1728 |
^ ((TZTimestamp new |
1729 |
setOSTimeFromUTCYear:year month:month day:day |
|
1730 |
hour:time hour minute:time minute second:time second millisecond:0 |
|
1731 |
) utcOffset:utcOffset |
|
1732 |
) addSeconds:utcOffset. |
|
14713 | 1733 |
|
1734 |
" |
|
17081 | 1735 |
self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 GMT' onError:nil |
1736 |
self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 UTC' onError:nil |
|
16945 | 1737 |
self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 PST' onError:nil |
1738 |
self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 PDT' onError:nil |
|
1739 |
self readRFC1123FormatFrom:'Mon, 17 Aug 2009 11:11:15 +0100' onError:nil |
|
17081 | 1740 |
self readRFC1123FormatFrom:'17 Aug 2009 11:11:15 +0100' onError:nil |
14713 | 1741 |
" |
13085
ee5674e04bd6
changed: #readRFC1123FormatFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
12939
diff
changeset
|
1742 |
|
ee5674e04bd6
changed: #readRFC1123FormatFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
12939
diff
changeset
|
1743 |
"Modified: / 05-10-2010 / 16:05:32 / cg" |
14713 | 1744 |
! |
1745 |
||
16986 | 1746 |
timezoneInfo |
1747 |
"return a table containing timezone information. |
|
17006 | 1748 |
This may or may not be correct by the time you read this. |
16986 | 1749 |
It is recommended to add explicit information in the form of +hh:mm to a printed |
16990 | 1750 |
representation, instead of using names. |
1751 |
||
19624 | 1752 |
As this is searched for when reverse converting from utcOffset to TZName" |
1753 |
||
1754 |
"/ the table below can be customized via a setter, |
|
1755 |
"/ if an application knows better |
|
1756 |
"/ (reading a system timeZone table, or limiting the table to military/non-military names only, for example) |
|
1757 |
||
1758 |
TimeZoneInfo notNil ifTrue:[^ TimeZoneInfo]. |
|
1759 |
||
1760 |
"/ table is name, utcOffset(minutes), DST-flag, startDay, endDay |
|
16986 | 1761 |
^ #( |
19624 | 1762 |
'Z' 0 false "/ zulu |
1763 |
'UTC' 0 false |
|
1764 |
'GMT' 0 false |
|
17081 | 1765 |
|
1766 |
"/ US |
|
19624 | 1767 |
'HAST' -600 false "/ hawai standard |
1768 |
'AKST' -540 false "/ alaska standard |
|
1769 |
'YST' -540 false "/ yukon standard |
|
1770 |
'PST' -480 false "/ pacific standard |
|
1771 |
'PT' -480 false "/ pacific standard |
|
1772 |
'MST' -420 false "/ mountain standard |
|
1773 |
'CST' -360 false "/ central standard |
|
1774 |
'EST' -300 false "/ eastern standard |
|
1775 |
'AST' -240 false "/ atlantic standard |
|
1776 |
||
1777 |
'NST' -210 false "/ new foundland standard |
|
1778 |
'PMST' -180 false "/ pierre & miquelon |
|
1779 |
'WGT' -180 false "/ west greenland |
|
1780 |
'EGT' -60 false "/ east greenland |
|
17081 | 1781 |
|
1782 |
"/ europe |
|
19624 | 1783 |
'CET' 60 false "/ central european |
1784 |
'EET' 120 false "/ east european |
|
1785 |
'WET' 0 false "/ west european |
|
17081 | 1786 |
"/ conflict with india!! |
1787 |
"/ 'IST' 1 "/ irish standard time |
|
1788 |
"/ 'IST' 1 "/ israel standard time |
|
19624 | 1789 |
'AZOT' -60 false "/ azores standard |
1790 |
||
1791 |
'MSK' 240 false "/ moscow european |
|
1792 |
'MSD' 240 false |
|
1793 |
'BT' 240 false "/ baghdad |
|
17081 | 1794 |
|
1795 |
"/ pacific |
|
19624 | 1796 |
'NZST' 720 false "/ new zealand standard |
1797 |
'FJT' 720 false "/ fiji |
|
17081 | 1798 |
|
1799 |
"/ south america |
|
19624 | 1800 |
'ART' -180 false "/ argentina |
1801 |
'BOT' -240 false "/ bolivia |
|
1802 |
'BRT' -180 false "/ brasilia |
|
1803 |
'CLT' -240 false "/ chile |
|
1804 |
'ECT' -300 false "/ equador |
|
1805 |
'PET' -300 false "/ peru |
|
1806 |
'PYT' -240 false "/ paraguay |
|
1807 |
'UYT' -180 false "/ uruguay |
|
1808 |
'VET' -270 false "/ venezuela standard |
|
1809 |
'VST' -270 false "/ venezuela standard |
|
17081 | 1810 |
|
1811 |
"/ africa |
|
19624 | 1812 |
'CAT' 120 false "/ central africa |
1813 |
'EAT' 180 false "/ east africa |
|
1814 |
'SAST' 120 false "/ south africa standard |
|
1815 |
'WAT' 60 false "/ west africa |
|
1816 |
'WT' 0 false "/ west sahara standard |
|
1817 |
||
1818 |
'AST' 180 false "/ arabia |
|
1819 |
'IRT' 210 false "/ iran time |
|
1820 |
'AFT' 270 false "/ afghanistan time |
|
1821 |
||
1822 |
'HKT' 480 false "/ hongkong |
|
1823 |
'IST' 330 false "/ india standard |
|
1824 |
'ICT' 420 false "/ indochina |
|
1825 |
'CNST' 480 false "/ china standard |
|
1826 |
'JST' 540 false "/ japan standard |
|
1827 |
'KST' 540 false "/ korea standard |
|
1828 |
'SGT' 480 false "/ singapore |
|
1829 |
'MYT' 480 false "/ malaysia |
|
1830 |
'AWST' 480 false "/ australian west standard |
|
1831 |
'ACWST' 525 false "/ australian central western standard |
|
1832 |
'ACST' 570 false "/ australian central standard |
|
1833 |
'AEST' 600 false "/ australian east standard |
|
1834 |
'NFT' 690 false "/ norfolk island, australia |
|
1835 |
||
1836 |
'CHAST' 765 false "/ chatham island standard |
|
20429 | 1837 |
'WST' 780 false "/ west samoa - yes that's 13!! |
1838 |
'TOT' 780 false "/ tonga - yes that's 13!! |
|
1839 |
'TKT' 780 false "/ tokelau - yes that's 13!! |
|
1840 |
'LINT' 840 false "/ line islands - yes that's 14!! |
|
17081 | 1841 |
|
1842 |
"/ misc |
|
19624 | 1843 |
'IDLW' -720 false "/ international date line west |
1844 |
'IDLE' 720 false "/ international date line east |
|
1845 |
||
23565 | 1846 |
'MEZ' 60 false "/ mittel europäische Zeit / central european (german) |
19624 | 1847 |
'MESZ' 120 true "/ central european summer (german) |
1848 |
'WESZ' 60 true "/ west european summer (german) |
|
1849 |
||
1850 |
'WEZ' 0 false "/ west european (german) |
|
1851 |
||
1852 |
'HADT' -540 true "/ hawaii summer |
|
1853 |
'ADT' -180 true |
|
1854 |
'AKDT' -540 true "/ alaska summer |
|
1855 |
'YDT' -480 true "/ yukon summer |
|
1856 |
'PDT' -420 true "/ pacific daylight saving |
|
1857 |
'MDT' -360 true "/ mountain daylight saving |
|
1858 |
'CDT' -300 true "/ central daylight saving |
|
1859 |
'EDT' -240 true "/ eastern daylight saving |
|
1860 |
'CLST' -180 true "/ chile summer |
|
1861 |
'NDT' -150 true |
|
1862 |
'PMDT' -120 true |
|
1863 |
'BRST' -120 true "/ brasilia summer |
|
1864 |
'WGST' -120 true "/ west greenland summer |
|
1865 |
'EGST' 0 true "/ east greenland summer |
|
1866 |
'AZOST' 0 true "/ azores summer |
|
1867 |
'EEST' 180 true |
|
1868 |
'CEST' 120 true |
|
1869 |
'WAST' 120 true "/ west africa summer |
|
1870 |
"/ 'WST' 60 true "/ west sahara summer - conflict with west samoa |
|
1871 |
'WEST' 60 true |
|
1872 |
'BST' 60 true "/ british summer time |
|
1873 |
'IRST' 270 true "/ iran summer time |
|
1874 |
'AWDT' 540 true "/ australian west daylight saving |
|
1875 |
'ACDT' 630 true "/ australian central daylight saving |
|
1876 |
'AEDT' 660 true "/ australian east daylight saving |
|
1877 |
'CHADT' 825 true "/ chatham island daylight saving |
|
1878 |
'FJST' 780 true "/ fiji summer |
|
1879 |
'NZDT' 780 true "/ new zealand summer |
|
17081 | 1880 |
|
1881 |
"/ military |
|
19624 | 1882 |
'A' 60 false "/ alpha |
1883 |
'B' 120 false "/ bravo |
|
1884 |
'C' 180 false "/ charlie |
|
1885 |
'D' 240 false "/ delta |
|
1886 |
'E' 300 false "/ echo |
|
1887 |
'F' 360 false "/ foxtrot |
|
1888 |
'G' 420 false "/ golf |
|
1889 |
'H' 480 false "/ hotel |
|
1890 |
'I' 540 false "/ also called india - how misleading |
|
1891 |
'K' 600 false "/ kilo |
|
1892 |
'L' 660 false "/ lima - but not there |
|
1893 |
'M' 720 false "/ mike |
|
1894 |
'N' -60 false "/ november (but also in other months) |
|
1895 |
'O' -120 false "/ oscar |
|
1896 |
'P' -180 false "/ papa (not mama) |
|
1897 |
'Q' -240 false "/ quebec - really? |
|
1898 |
'R' -300 false "/ romeo and juliet |
|
1899 |
'S' -360 false "/ sierra |
|
1900 |
'T' -420 false "/ tango (& not rumba) |
|
1901 |
'U' -480 false "/ uniform |
|
1902 |
'V' -540 false "/ victor |
|
1903 |
'W' -600 false "/ whiskey (scotch?) |
|
1904 |
'X' -660 false "/ xray |
|
1905 |
'Y' -720 false "/ yankee |
|
1906 |
||
17081 | 1907 |
). |
16986 | 1908 |
! |
1909 |
||
1910 |
utcOffsetFrom:aStringOrStream |
|
1911 |
"return the utcOffset (in seconds) for a given time-zone name. |
|
17172 | 1912 |
Returns nil for invalid formats, 0 if no timezone offset is present. |
16986 | 1913 |
|
1914 |
Notice: this returns the negated value of what is read from a printed representation, |
|
1915 |
which means that the sign is the same as what the utcOffset instance variable |
|
17081 | 1916 |
in timeStamp and OperatingSystem-timeInfo will be. |
16986 | 1917 |
|
1918 |
If utcOffset is negative, the local timezone is east of Greenwich. |
|
1919 |
If utcOffset is positive, the local timezone is west of Greenwich. |
|
1920 |
||
1921 |
UtcOffset is what you have to ADD to correct the printed time to GMT. |
|
1922 |
I.e. for Germany, you'll get -3600 (+01h), for NewYork, you'll get +18000 (-05h)" |
|
1923 |
||
17081 | 1924 |
|ch offset stream| |
14713 | 1925 |
|
1926 |
stream := aStringOrStream readStream. |
|
1927 |
stream skipSeparators. |
|
1928 |
||
17079 | 1929 |
ch := stream peekOrNil. |
1930 |
ch isNil ifTrue:[^ 0]. |
|
17081 | 1931 |
|
17071 | 1932 |
ch isLetter ifTrue:[ |
19624 | 1933 |
|table tzName i minuteOffset| |
1934 |
||
17081 | 1935 |
table := self timezoneInfo. |
17071 | 1936 |
tzName := stream upToElementForWhich:[:ch | ch isLetter not]. |
1937 |
||
1938 |
i := table indexOf:tzName. |
|
1939 |
i == 0 ifTrue:[ |
|
1940 |
^ nil |
|
1941 |
]. |
|
19624 | 1942 |
minuteOffset := (table at:i+1). |
1943 |
offset := minuteOffset * 60 |
|
14713 | 1944 |
] ifFalse:[ |
17081 | 1945 |
|sign| |
1946 |
||
17071 | 1947 |
sign := 1. |
1948 |
ch == $- ifTrue:[ |
|
1949 |
sign := -1. |
|
1950 |
stream next. |
|
17081 | 1951 |
] ifFalse:[ch == $+ ifTrue:[ |
1952 |
stream next. |
|
17071 | 1953 |
] ifFalse:[ |
17081 | 1954 |
stream skipSeparators |
1955 |
]]. |
|
17172 | 1956 |
stream peekOrNil isDigit ifFalse:[^ nil]. |
17081 | 1957 |
|
17071 | 1958 |
offset := ((stream next:2) asNumber * 60 * 60). |
17081 | 1959 |
ch := stream peekOrNil. |
1960 |
ch notNil ifTrue:[ |
|
1961 |
ch == $: ifTrue:[ stream next ]. |
|
17071 | 1962 |
offset := offset + ((stream next:2) asNumber * 60). |
1963 |
]. |
|
1964 |
offset := offset * sign |
|
14713 | 1965 |
]. |
1966 |
||
16975 | 1967 |
"/ return what would be an utcOffset (not what is at the end of an iso string) |
1968 |
^ offset negated |
|
14713 | 1969 |
|
1970 |
" |
|
16945 | 1971 |
self utcOffsetFrom:'UTC' |
1972 |
self utcOffsetFrom:'PST' |
|
17006 | 1973 |
self utcOffsetFrom:'EST' |
1974 |
self utcOffsetFrom:'CET' |
|
16945 | 1975 |
self utcOffsetFrom:'+0130' |
16955 | 1976 |
self utcOffsetFrom:'+01:30' |
17081 | 1977 |
self utcOffsetFrom:'+1:30' |
16955 | 1978 |
self utcOffsetFrom:'+01' |
14713 | 1979 |
" |
1980 |
! |
|
1981 |
||
1982 |
utcOffsetFromString:aString |
|
16955 | 1983 |
<resource: #obsolete> |
14713 | 1984 |
"return the utcOffset (in seconds) for a given time-zone name. |
1985 |
Returns nil for invalid formats" |
|
1986 |
||
16955 | 1987 |
^ self utcOffsetFrom:aString |
14713 | 1988 |
|
1989 |
" |
|
17006 | 1990 |
self utcOffsetFromString:'UTC' |
1991 |
self utcOffsetFromString:'+01' |
|
14713 | 1992 |
" |
11993 | 1993 |
! ! |
1994 |
||
22914 | 1995 |
|
22834 | 1996 |
|
24160 | 1997 |
|
1998 |
||
8246 | 1999 |
!Timestamp methodsFor:'accessing'! |
30 | 2000 |
|
2001 |
day |
|
92 | 2002 |
"return the day-in-month of the receiver (1..31). |
275 | 2003 |
For compatibility, use instances of Date for this." |
30 | 2004 |
|
16928 | 2005 |
^ self asDate day. |
54 | 2006 |
|
92 | 2007 |
" |
16945 | 2008 |
Timestamp now day |
92 | 2009 |
" |
1501 | 2010 |
|
2011 |
"Modified: 1.7.1996 / 15:23:02 / cg" |
|
2012 |
! |
|
2013 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2014 |
dayInWeek |
16986 | 2015 |
"return the week-day of the receiver - 1 for monday, 7 for sunday. |
2016 |
for pre-gregorian dates, it simply goes on assuming the current leapYear rules |
|
2017 |
WARNING: different from ANSIs dayOfWeek (which returns 1 for sunday, ... 7 for saturday)." |
|
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2018 |
|
16928 | 2019 |
^ self asDate dayInWeek |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2020 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2021 |
" |
16945 | 2022 |
Timestamp now dayInWeek |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2023 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2024 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2025 |
"Modified: 2.7.1996 / 09:20:32 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2026 |
"Created: 2.7.1996 / 09:35:48 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2027 |
! |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2028 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2029 |
dayInYear |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2030 |
"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
|
2031 |
|
16928 | 2032 |
^ self asDate dayInYear |
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2033 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2034 |
" |
16945 | 2035 |
Timestamp now dayInYear |
2036 |
(Timestamp newDay:184 year:1996) dayInYear |
|
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2037 |
" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2038 |
|
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2039 |
"Modified: 2.7.1996 / 10:21:02 / cg" |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2040 |
! |
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2041 |
|
13225 | 2042 |
dayOfMonth |
2043 |
"Answer the day of the month represented by me. |
|
2044 |
Same as day; for ST-80 compatibility." |
|
2045 |
||
2046 |
^ self asDate dayOfMonth |
|
2047 |
||
2048 |
" |
|
16945 | 2049 |
Timestamp now dayOfMonth |
2050 |
(Timestamp newDay:184 year:1996) dayOfMonth |
|
13225 | 2051 |
" |
2052 |
||
2053 |
"Created: / 20-01-2011 / 12:26:54 / cg" |
|
2054 |
! |
|
2055 |
||
16993 | 2056 |
dayOfWeek |
2057 |
"return the week-day of the receiver - 1 is sunday, 7 for saturday. |
|
17006 | 2058 |
WARNING: different from dayInWeek (which returns 1 for monday, ... 7 for sunday). |
16993 | 2059 |
" |
2060 |
||
2061 |
^ self asDate dayOfWeek |
|
2062 |
||
2063 |
" |
|
2064 |
Timestamp now dayOfWeek |
|
2065 |
" |
|
2066 |
! |
|
2067 |
||
13225 | 2068 |
dayOfWeekName |
2069 |
"return the week-day of the receiver as a string. |
|
2070 |
The returned string depends on the language setting. |
|
2071 |
Expect things like 'monday', 'tuesday' ..." |
|
2072 |
||
2073 |
^ self asDate dayOfWeekName |
|
2074 |
||
2075 |
" |
|
16945 | 2076 |
Timestamp now dayOfWeekName |
2077 |
(Timestamp newDay:184 year:1996) dayOfWeekName |
|
13225 | 2078 |
" |
2079 |
||
2080 |
"Created: / 20-01-2011 / 12:28:46 / cg" |
|
2081 |
! |
|
2082 |
||
22873 | 2083 |
exactMicroseconds |
2084 |
"return the exact microseconds within the stamp's second (0 .. 999.999...) as a fixedPoint number. |
|
2085 |
notice: |
|
2086 |
that is NOT the total number of microseconds, |
|
2087 |
but the fractional part (within the second) only. |
|
2088 |
A fixedPoint number holds the exact value, but prints itself rounded!!" |
|
2089 |
||
2090 |
|millis microsFromMillis| |
|
2091 |
||
2092 |
millis := (osTime \\ 1000). |
|
2093 |
microsFromMillis := millis * 1000. |
|
2094 |
additionalPicoseconds notNil ifTrue:[ |
|
2095 |
^ microsFromMillis + (FixedPoint numerator:additionalPicoseconds denominator:(1000*1000) scale:3) |
|
2096 |
]. |
|
2097 |
^ microsFromMillis. |
|
2098 |
||
2099 |
" |
|
2100 |
|ts| |
|
2101 |
||
2102 |
ts := Timestamp nowWithMicroseconds. |
|
2103 |
Transcript showCR:ts. |
|
2104 |
Transcript showCR:ts microseconds. |
|
2105 |
Transcript showCR:ts exactMicroseconds. |
|
2106 |
Transcript showCR:ts nanoseconds. |
|
2107 |
Transcript showCR:ts picoseconds. |
|
2108 |
" |
|
2109 |
! |
|
2110 |
||
2111 |
exactMilliseconds |
|
2112 |
"return the exact milliseconds within the stamp's second (0 .. 999.999...) as a fixedPoint number. |
|
2113 |
notice: |
|
2114 |
that is NOT the total number of microseconds, |
|
2115 |
but the fractional part (within the second) only. |
|
2116 |
A fixedPoint number holds the exact value, but prints itself rounded!!" |
|
2117 |
||
2118 |
|millis| |
|
2119 |
||
2120 |
millis := (osTime \\ 1000). |
|
2121 |
additionalPicoseconds notNil ifTrue:[ |
|
2122 |
^ millis + (FixedPoint numerator:additionalPicoseconds denominator:(1000*1000*1000) scale:3) |
|
2123 |
]. |
|
2124 |
^ millis. |
|
2125 |
||
2126 |
" |
|
2127 |
|ts| |
|
2128 |
||
2129 |
ts := Timestamp nowWithMicroseconds. |
|
2130 |
Transcript showCR:ts. |
|
2131 |
Transcript showCR:ts milliseconds. |
|
2132 |
Transcript showCR:ts exactMilliseconds. |
|
2133 |
Transcript showCR:ts microseconds. |
|
2134 |
Transcript showCR:ts nanoseconds. |
|
2135 |
Transcript showCR:ts picoseconds. |
|
2136 |
" |
|
2137 |
! |
|
2138 |
||
2139 |
exactMinutes |
|
2140 |
"return the exact minutes within the stamp's hour (00 .. 59.999...) as a fixedPoint number. |
|
2141 |
Notice: |
|
2142 |
that is NOT the total number of minutes, |
|
2143 |
but the fractional part (within the hour) only. |
|
2144 |
A fixedPoint number holds the exact value, but prints itself rounded!!" |
|
2145 |
||
2146 |
|minutes additionalSeconds| |
|
2147 |
||
2148 |
minutes := FixedPoint numerator:(osTime \\ (60*60*1000)) / 60 denominator:1000 scale:3. |
|
2149 |
additionalPicoseconds notNil ifTrue:[ |
|
2150 |
additionalSeconds := (FixedPoint numerator:additionalPicoseconds denominator:(1000*1000*1000*1000) scale:3). |
|
2151 |
minutes := minutes + (additionalSeconds / 60). |
|
2152 |
]. |
|
2153 |
^ minutes. |
|
2154 |
||
2155 |
" |
|
2156 |
|ts| |
|
2157 |
||
2158 |
ts := Timestamp nowWithMicroseconds. |
|
2159 |
Transcript showCR:ts. |
|
2160 |
Transcript showCR:ts minutes. |
|
2161 |
Transcript showCR:ts exactMinutes. |
|
2162 |
" |
|
2163 |
! |
|
2164 |
||
2165 |
exactNanoseconds |
|
2166 |
"return the exact nanoseconds within the stamp's second (0 .. 999.999...). |
|
2167 |
notice: |
|
2168 |
that is NOT the total number of nanoseconds, |
|
2169 |
but the fractional part (within the second) only. |
|
2170 |
A fixedPoint number holds the exact value, but prints itself rounded!!" |
|
2171 |
||
2172 |
|millis nanosFromMillis| |
|
2173 |
||
2174 |
millis := (osTime \\ 1000). |
|
2175 |
nanosFromMillis := millis * 1000 * 1000. |
|
2176 |
additionalPicoseconds notNil ifTrue:[ |
|
2177 |
^ nanosFromMillis + (FixedPoint numerator:additionalPicoseconds denominator:(1000) scale:3) |
|
2178 |
]. |
|
2179 |
^ nanosFromMillis. |
|
2180 |
||
2181 |
" |
|
2182 |
|ts| |
|
2183 |
||
2184 |
ts := Timestamp now + 100.3 nanoseconds. |
|
2185 |
Transcript showCR:ts. |
|
2186 |
Transcript showCR:ts milliseconds. |
|
2187 |
Transcript showCR:ts exactMilliseconds. |
|
2188 |
Transcript showCR:ts microseconds. |
|
2189 |
Transcript showCR:ts exactMicroseconds. |
|
2190 |
Transcript showCR:ts nanoseconds. |
|
2191 |
Transcript showCR:ts exactNanoseconds. |
|
2192 |
Transcript showCR:ts picoseconds. |
|
2193 |
" |
|
2194 |
! |
|
2195 |
||
2196 |
exactSeconds |
|
2197 |
"return the exact seconds within the stamp's minute (00 .. 59.999...) as a fixedPoint number. |
|
2198 |
Notice: |
|
2199 |
that is NOT the total number of seconds, |
|
2200 |
but the fractional part (within the minute) only. |
|
2201 |
A fixedPoint number holds the exact value, but prints itself rounded!!" |
|
2202 |
||
2203 |
|seconds additionalSeconds| |
|
2204 |
||
2205 |
seconds := FixedPoint numerator:(osTime \\ (60*1000)) denominator:1000 scale:3. |
|
2206 |
additionalPicoseconds notNil ifTrue:[ |
|
2207 |
additionalSeconds := (FixedPoint numerator:additionalPicoseconds denominator:(1000*1000*1000*1000) scale:3). |
|
2208 |
seconds := seconds + additionalSeconds |
|
2209 |
]. |
|
2210 |
^ seconds. |
|
2211 |
||
2212 |
" |
|
2213 |
|ts| |
|
2214 |
||
2215 |
ts := Timestamp fromDate:(Date today) hour:10 minute:30 second:20 millisecond:300. |
|
2216 |
Transcript showCR:ts. |
|
2217 |
Transcript showCR:ts seconds. |
|
2218 |
Transcript showCR:ts exactSeconds. |
|
2219 |
" |
|
2220 |
! |
|
2221 |
||
241 | 2222 |
hours |
2223 |
"return the hours (0..23)" |
|
2224 |
||
17006 | 2225 |
(osTime between:MinOSTime and:MaxOSTime) ifFalse:[ |
2226 |
^ self asTime hours. |
|
16928 | 2227 |
]. |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2228 |
^ self timeInfo hours |
54 | 2229 |
|
92 | 2230 |
" |
16945 | 2231 |
Timestamp now hours |
241 | 2232 |
" |
2233 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2234 |
"Modified: 2.7.1996 / 09:20:32 / cg" |
1501 | 2235 |
! |
2236 |
||
22834 | 2237 |
microseconds |
22873 | 2238 |
"return the truncated microseconds within the stamp's second (0..999999). |
22834 | 2239 |
notice: that is NOT the total number of microseconds, |
2240 |
but the fractional part (within the second) only. |
|
2241 |
Use this only for printing." |
|
2242 |
||
22873 | 2243 |
|millis microsFromMillis| |
2244 |
||
2245 |
millis := (osTime \\ 1000). |
|
2246 |
microsFromMillis := millis * 1000. |
|
22834 | 2247 |
additionalPicoseconds notNil ifTrue:[ |
2248 |
^ microsFromMillis + (additionalPicoseconds // (1000*1000)) |
|
2249 |
]. |
|
2250 |
^ microsFromMillis. |
|
2251 |
||
2252 |
" |
|
22873 | 2253 |
-- (definitely millisecond resolution here) |
2254 |
Timestamp now |
|
2255 |
Timestamp now microseconds |
|
2256 |
||
2257 |
-- (but some OS's only deliver millisecond resolution also here) |
|
22834 | 2258 |
Timestamp nowWithMicroseconds microseconds |
2259 |
||
22873 | 2260 |
|
22834 | 2261 |
|t1 t2| |
2262 |
t1 := Timestamp nowWithMicroseconds microseconds. |
|
2263 |
t2 := Timestamp nowWithMicroseconds microseconds. |
|
2264 |
t2-t1 |
|
2265 |
||
2266 |
|t1 t2| |
|
2267 |
t1 := Timestamp now microseconds. |
|
2268 |
t2 := Timestamp nowWithMicroseconds microseconds. |
|
2269 |
t2-t1 |
|
2270 |
" |
|
2271 |
||
2272 |
"Created: 1.7.1996 / 15:15:02 / cg" |
|
2273 |
"Modified: 2.7.1996 / 09:21:41 / cg" |
|
2274 |
! |
|
2275 |
||
1501 | 2276 |
millisecond |
22873 | 2277 |
"return the truncated millisecond within the stamp's second (0..999). |
1501 | 2278 |
ST-80 Timestamp compatibility (I'd prefer the name #milliseconds)." |
2279 |
||
2280 |
^ self milliseconds |
|
2281 |
||
2282 |
"Created: 1.7.1996 / 15:14:50 / cg" |
|
2283 |
"Modified: 1.7.1996 / 15:15:24 / cg" |
|
2284 |
! |
|
2285 |
||
2286 |
milliseconds |
|
22873 | 2287 |
"return the truncated milliseconds within the stamp's second (0..999)" |
1501 | 2288 |
|
16928 | 2289 |
^ osTime \\ 1000. |
1501 | 2290 |
|
2291 |
" |
|
16945 | 2292 |
Timestamp now milliseconds |
1501 | 2293 |
" |
2294 |
||
2295 |
"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
|
2296 |
"Modified: 2.7.1996 / 09:21:41 / cg" |
1501 | 2297 |
! |
2298 |
||
241 | 2299 |
minutes |
2300 |
"return the minutes (0..59)" |
|
2301 |
||
17006 | 2302 |
(osTime between:MinOSTime and:MaxOSTime) ifFalse:[ |
2303 |
^ self asTime minutes. |
|
16928 | 2304 |
]. |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2305 |
^ self timeInfo minutes |
241 | 2306 |
|
2307 |
" |
|
16945 | 2308 |
Timestamp now minutes |
92 | 2309 |
" |
241 | 2310 |
|
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2311 |
"Modified: 2.7.1996 / 09:20:49 / cg" |
241 | 2312 |
! |
2313 |
||
699 | 2314 |
month |
2315 |
"return the month of the receiver (1..12). |
|
2316 |
For compatibility, use instances of Date for this." |
|
2317 |
||
17006 | 2318 |
(osTime between:MinOSTime and:MaxOSTime) ifFalse:[ |
2319 |
^ self asDate month. |
|
16928 | 2320 |
]. |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2321 |
^ self timeInfo month |
699 | 2322 |
|
2323 |
" |
|
8246 | 2324 |
Timestamp now month |
699 | 2325 |
" |
1501 | 2326 |
|
2327 |
"Modified: 1.7.1996 / 15:23:05 / cg" |
|
2328 |
! |
|
2329 |
||
18886 | 2330 |
monthIndex |
2331 |
"return the month of the receiver (1..12). |
|
2332 |
For compatibility" |
|
2333 |
||
2334 |
^ self asDate monthIndex. |
|
2335 |
||
2336 |
" |
|
2337 |
Timestamp now monthIndex |
|
2338 |
" |
|
2339 |
! |
|
2340 |
||
22834 | 2341 |
nanoseconds |
22873 | 2342 |
"return the truncated nanoseconds within the stamp's second (0..999999999). |
22834 | 2343 |
notice: that is NOT the total number of nanoseconds, |
2344 |
but the fractional part (within the second) only. |
|
2345 |
Use this only for printing." |
|
2346 |
||
2347 |
|nanosFromMillis| |
|
2348 |
||
2349 |
nanosFromMillis := (osTime \\ 1000) * (1000 * 1000). |
|
2350 |
additionalPicoseconds notNil ifTrue:[ |
|
2351 |
^ nanosFromMillis + (additionalPicoseconds // 1000) |
|
2352 |
]. |
|
2353 |
^ nanosFromMillis. |
|
2354 |
||
2355 |
" |
|
2356 |
Timestamp now nanoseconds |
|
2357 |
Timestamp nowWithMicroseconds nanoseconds |
|
2358 |
||
2359 |
|t1 t2| |
|
2360 |
t1 := Timestamp nowWithMicroseconds nanoseconds. |
|
2361 |
t2 := Timestamp nowWithMicroseconds nanoseconds. |
|
2362 |
t2-t1 |
|
2363 |
||
2364 |
|t1 t2| |
|
2365 |
t1 := Timestamp now nanoseconds. |
|
2366 |
t2 := Timestamp nowWithMicroseconds nanoseconds. |
|
2367 |
t2-t1 |
|
2368 |
" |
|
2369 |
||
2370 |
"Created: 1.7.1996 / 15:15:02 / cg" |
|
2371 |
"Modified: 2.7.1996 / 09:21:41 / cg" |
|
2372 |
! |
|
2373 |
||
8286 | 2374 |
osTime |
2375 |
"get the internal representation of the time. |
|
2376 |
Warning: do not depend on the value (unix vs. win32 - differences)" |
|
2377 |
||
2378 |
^ osTime |
|
2379 |
! |
|
2380 |
||
22613 | 2381 |
picoseconds |
22834 | 2382 |
"return the picoseconds within the stamp's second (0..999999999999). |
2383 |
notice: that is NOT the total number of picoseconds, |
|
2384 |
but the fractional part (within the second) only. |
|
2385 |
Use this only for printing." |
|
2386 |
||
2387 |
|picosFromMillis| |
|
2388 |
||
2389 |
picosFromMillis := (osTime \\ 1000) * (1000 * 1000 * 1000). |
|
2390 |
^ picosFromMillis + (additionalPicoseconds ? 0) |
|
22613 | 2391 |
|
2392 |
" |
|
2393 |
Timestamp now picoseconds |
|
22834 | 2394 |
Timestamp nowWithMicroseconds picoseconds |
22614 | 2395 |
" |
2396 |
! |
|
2397 |
||
241 | 2398 |
seconds |
22873 | 2399 |
"return the truncated seconds (0..59)" |
241 | 2400 |
|
17006 | 2401 |
(osTime between:MinOSTime and:MaxOSTime) ifFalse:[ |
22873 | 2402 |
^ self asTime seconds. |
16928 | 2403 |
]. |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2404 |
^ self timeInfo seconds |
241 | 2405 |
|
2406 |
" |
|
16945 | 2407 |
Timestamp now seconds |
241 | 2408 |
" |
2409 |
||
1513
a4b4c4ce039c
added dayInYear & dayInWeek for Date compatibility
Claus Gittinger <cg@exept.de>
parents:
1501
diff
changeset
|
2410 |
"Modified: 2.7.1996 / 09:20:54 / cg" |
92 | 2411 |
! |
2412 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2413 |
timeZoneDeltaInMinutes |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2414 |
"answer the number of minutes between local time and utc time. |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2415 |
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
|
2416 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2417 |
^ self utcOffset negated // 60 |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2418 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2419 |
" |
16945 | 2420 |
Timestamp now timeZoneDeltaInMinutes |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2421 |
(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
|
2422 |
" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2423 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2424 |
"Modified: 20.12.1995 / 17:28:49 / stefan" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2425 |
"Modified: 1.7.1996 / 15:21:29 / cg" |
7734 | 2426 |
! |
2427 |
||
16986 | 2428 |
timeZoneName |
16990 | 2429 |
"find the first zone which is in this range. |
2430 |
This is a bit naive, but should be sufficient in most cases |
|
2431 |
(for a correct result, we'd have to care for start-end dates of summer time |
|
2432 |
of that particular year...)" |
|
16986 | 2433 |
|
19624 | 2434 |
|myUtcOffset iAmDST bestNonDST| |
16986 | 2435 |
|
2436 |
myUtcOffset := self utcOffset negated. |
|
19624 | 2437 |
iAmDST := self timeInfo dst ? false. |
2438 |
||
2439 |
bestNonDST := nil. |
|
2440 |
self class timezoneInfo inGroupsOf:3 do:[:name :offsetInMinutes :isDST| |
|
2441 |
|thisUtcOffset| |
|
2442 |
||
2443 |
thisUtcOffset := offsetInMinutes * 60. |
|
2444 |
thisUtcOffset = myUtcOffset ifTrue:[ |
|
2445 |
isDST == iAmDST ifTrue:[^ name ]. |
|
2446 |
]. |
|
2447 |
bestNonDST := name. |
|
16986 | 2448 |
]. |
19624 | 2449 |
bestNonDST notNil ifTrue:[^ bestNonDST]. |
2450 |
||
2451 |
"/ nothing found - construct a standard offset string |
|
16986 | 2452 |
^ ((self utcOffset > 0) ifTrue:['+'] ifFalse:['-']) |
2453 |
, ((myUtcOffset abs // 60) printStringLeftPaddedTo:2 with:$0) |
|
2454 |
, ((myUtcOffset abs \\ 60) printStringLeftPaddedTo:2 with:$0) |
|
2455 |
||
2456 |
" |
|
17006 | 2457 |
Timestamp now timeZoneName |
2458 |
UtcTimestamp now timeZoneName |
|
2459 |
||
19624 | 2460 |
(Timestamp now asTZTimestampInZone:'MEZ') timeZoneName - will find international name |
17006 | 2461 |
(Timestamp now asTZTimestampInZone:'EST') timeZoneName |
19624 | 2462 |
(Timestamp now asTZTimestampInZone:'IDLE') timeZoneName - sorry - will find 'NZST' |
2463 |
(Timestamp now asTZTimestampInZone:'BRST') timeZoneName - sorry: will find military 'O' |
|
2464 |
(Timestamp now asTZTimestampInZone:'MYT') timeZoneName - will find hongkong; same timezone |
|
16986 | 2465 |
" |
2466 |
! |
|
2467 |
||
799 | 2468 |
utcOffset |
8886 | 2469 |
"return the difference between UTC (Greenwich Mean Time) and the local time in seconds. |
2470 |
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
|
2471 |
|
8886 | 2472 |
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
|
2473 |
Subtract utcOffset to convert from UTC time to local time. |
8886 | 2474 |
|
22890 | 2475 |
If utcOffset is negative, the local timezone is east of Greenwich (Russia, Asia). |
2476 |
If utcOffset is positive, the local timezone is west of Greenwich (USA)." |
|
799 | 2477 |
|
17026 | 2478 |
(osTime between:MinOSTime and:MaxOSTime) ifFalse:[ |
22890 | 2479 |
"/ fake an info which the OS cannot give me |
2480 |
"/ we do not know about DST in the far future and in the long gone past. |
|
2481 |
"/ Take the utcOffset without DST |
|
2482 |
^ self utcOffsetWithoutDst. |
|
17026 | 2483 |
]. |
2484 |
||
17003 | 2485 |
^ (OperatingSystem computeTimeAndDateFrom:osTime) utcOffset |
799 | 2486 |
|
2487 |
" |
|
16945 | 2488 |
Timestamp now utcOffset |
17031 | 2489 |
(Timestamp year:1995 month:7 day:1 hour:12 minute:0 second:0) utcOffset |
2490 |
(Timestamp year:1995 month:1 day:1 hour:12 minute:0 second:0) utcOffset |
|
2491 |
(Timestamp year:1689 month:7 day:1 hour:12 minute:0 second:0) utcOffset |
|
2492 |
(Timestamp year:4096 month:7 day:1 hour:12 minute:0 second:0) utcOffset |
|
799 | 2493 |
" |
2494 |
||
2495 |
"Modified: 20.12.1995 / 17:28:49 / stefan" |
|
1501 | 2496 |
"Modified: 1.7.1996 / 15:21:29 / cg" |
799 | 2497 |
! |
2498 |
||
17031 | 2499 |
utcOffsetWithoutDst |
2500 |
"return the difference between UTC (Greenwich Mean Time) and the local time in seconds. |
|
2501 |
If daylight saving time applies to ourself, do not take that into account. |
|
2502 |
||
2503 |
Add utcOffset to convert from local time to UTC time. |
|
2504 |
Subtract utcOffset to convert from UTC time to local time. |
|
2505 |
||
2506 |
If utcOffset is negative, the local timezone is east of Greenwich. |
|
2507 |
If utcOffset is positive, the local timezone is west of Greenwich." |
|
2508 |
||
2509 |
|offset epochInfo| |
|
2510 |
||
2511 |
offset := 0. |
|
2512 |
[ |
|
17067 | 2513 |
"DST may be in winter in the southern hemisphere. If we are in DST, add some days" |
2514 |
epochInfo := OperatingSystem timeInfoFromSeconds:offset milliseconds:0 localTime:true. |
|
2515 |
offset := offset + (3600 * 24 * 90). "Add about 3 months" |
|
17031 | 2516 |
] doWhile:[epochInfo dst and:[offset < (3600 * 24 * 365) "avoid endless loop"]]. |
2517 |
||
2518 |
^ epochInfo utcOffset |
|
2519 |
||
2520 |
" |
|
2521 |
Timestamp now utcOffsetWithoutDst |
|
2522 |
" |
|
2523 |
! |
|
2524 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2525 |
weekInYear |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2526 |
"return the week number of the receiver - 1 for Jan, 1st." |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2527 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2528 |
^ Date weekInYearOf:self |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2529 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2530 |
" |
16945 | 2531 |
(Timestamp newDay:1 year:2000) weekInYear |
2532 |
(Timestamp newDay:2 year:2000) weekInYear |
|
2533 |
(Timestamp newDay:3 year:2000) weekInYear |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2534 |
" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2535 |
! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2536 |
|
16993 | 2537 |
weekday |
2538 |
"return the week-day of the receiver as a string. |
|
2539 |
The returned string depends on the current language setting. |
|
2540 |
Expect things like 'monday', 'tuesday' ... |
|
2541 |
For ST-80 compatibility" |
|
2542 |
||
2543 |
^ self asDate weekday |
|
2544 |
||
2545 |
" |
|
17006 | 2546 |
Timestamp now weekday |
16993 | 2547 |
|
2548 |
but maybe a different day there, in the south pacific: |
|
17006 | 2549 |
(Timestamp now asTZTimestampInZone:'LINT') weekday |
16993 | 2550 |
|
2551 |
but maybe a different day there, in alaska: |
|
17006 | 2552 |
(Timestamp now asTZTimestampInZone:'AKST') weekday |
16993 | 2553 |
" |
2554 |
! |
|
2555 |
||
699 | 2556 |
year |
2557 |
"return the year of the receiver i.e. 1992. |
|
2558 |
For compatibility, use instances of Date for this." |
|
241 | 2559 |
|
17006 | 2560 |
(osTime between:MinOSTime and:MaxOSTime) ifFalse:[ |
2561 |
^ self asDate year. |
|
16928 | 2562 |
]. |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2563 |
^ self timeInfo year |
241 | 2564 |
|
2565 |
" |
|
8246 | 2566 |
Timestamp now year |
241 | 2567 |
" |
1501 | 2568 |
|
2569 |
"Modified: 1.7.1996 / 15:23:08 / cg" |
|
241 | 2570 |
! ! |
2571 |
||
8246 | 2572 |
!Timestamp methodsFor:'arithmetic'! |
30 | 2573 |
|
13199 | 2574 |
ceilingSecond |
2575 |
"return a timestamp which represents the next full second" |
|
2576 |
||
2577 |
|offs| |
|
2578 |
||
2579 |
offs := (self milliseconds / 1000) ceiling. |
|
2580 |
^ self class basicNew setSeconds:(self getSeconds + offs). |
|
2581 |
||
2582 |
" |
|
2583 |
|t1 t2| |
|
2584 |
||
2585 |
t1 := Timestamp now. |
|
2586 |
t2 := t1 ceilingSecond. |
|
2587 |
self halt |
|
2588 |
" |
|
2589 |
||
2590 |
"Created: / 08-01-2011 / 16:23:03 / cg" |
|
2591 |
! |
|
2592 |
||
2593 |
floorSecond |
|
2594 |
"return a timestamp truncated to the last full second" |
|
2595 |
||
2596 |
^ self class basicNew setSeconds:(self getSeconds). |
|
2597 |
||
2598 |
" |
|
2599 |
|t1 t2| |
|
2600 |
||
2601 |
t1 := Timestamp now. |
|
2602 |
t2 := t1 floorSecond. |
|
2603 |
self halt |
|
2604 |
" |
|
2605 |
||
2606 |
"Created: / 08-01-2011 / 16:20:55 / cg" |
|
2607 |
! |
|
2608 |
||
22940 | 2609 |
microsecondDeltaFrom:aTimestamp |
23776 | 2610 |
"return the delta in (truncated) microseconds between 2 timestamps. |
22940 | 2611 |
The argument is supposed to be BEFORE the receiver, |
2612 |
computes self - aTimestamp" |
|
2613 |
||
2614 |
^ self getMicroseconds - (aTimestamp getMicroseconds) |
|
2615 |
||
2616 |
" |
|
2617 |
|t1 t2| |
|
2618 |
||
2619 |
t1 := Timestamp now. |
|
2620 |
Delay waitForSeconds:0.5. |
|
2621 |
t2 := Timestamp now. |
|
2622 |
t2 microsecondDeltaFrom:t1 |
|
2623 |
" |
|
2624 |
||
2625 |
"Modified: / 10-07-2010 / 09:37:18 / cg" |
|
23776 | 2626 |
"Modified (comment): / 26-02-2019 / 14:02:16 / Claus Gittinger" |
22940 | 2627 |
! |
2628 |
||
8246 | 2629 |
millisecondDeltaFrom:aTimestamp |
23776 | 2630 |
"return the delta in (truncated) milliseconds between 2 timestamps. |
12939 | 2631 |
The argument is supposed to be BEFORE the receiver, |
23239 | 2632 |
computes self - aTimestamp" |
2633 |
||
2634 |
^ osTime - (aTimestamp getMilliseconds) |
|
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
2635 |
|
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
2636 |
" |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
2637 |
|t1 t2| |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
2638 |
|
8246 | 2639 |
t1 := Timestamp now. |
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
2640 |
Delay waitForSeconds:0.5. |
8246 | 2641 |
t2 := Timestamp now. |
16945 | 2642 |
t2 millisecondDeltaFrom:t1 |
2623
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
2643 |
" |
593ab389efd1
added #millisecondDeltaFrom:
Claus Gittinger <cg@exept.de>
parents:
2311
diff
changeset
|
2644 |
|
12939 | 2645 |
"Modified: / 10-07-2010 / 09:37:18 / cg" |
23239 | 2646 |
"Modified: / 27-07-2018 / 10:34:11 / Stefan Vogel" |
23776 | 2647 |
"Modified (comment): / 26-02-2019 / 14:02:13 / Claus Gittinger" |
9056 | 2648 |
! |
2649 |
||
13200 | 2650 |
roundedToSecond |
2651 |
"return a timestamp which represents the time rounded to the nearest full second" |
|
2652 |
||
2653 |
|offs| |
|
2654 |
||
2655 |
offs := (self milliseconds / 1000) rounded. |
|
2656 |
^ self class basicNew setSeconds:(self getSeconds + offs). |
|
2657 |
||
2658 |
" |
|
2659 |
|t1 t2| |
|
2660 |
||
2661 |
t1 := Timestamp now. |
|
2662 |
t2 := t1 roundedToSecond. |
|
2663 |
self halt |
|
2664 |
" |
|
2665 |
||
2666 |
"Created: / 08-01-2011 / 16:24:12 / cg" |
|
2667 |
! |
|
2668 |
||
9056 | 2669 |
secondDeltaFrom:aTimestamp |
23776 | 2670 |
"return the delta in (truncated) seconds between 2 timestamps. |
12939 | 2671 |
The argument is supposed to be BEFORE the receiver, |
23776 | 2672 |
computes self - aTimestamp" |
9056 | 2673 |
|
2674 |
^ self getSeconds - (aTimestamp getSeconds) |
|
2675 |
||
2676 |
" |
|
2677 |
|t1 t2| |
|
2678 |
||
2679 |
t1 := Timestamp now. |
|
2680 |
Delay waitForSeconds:5. |
|
2681 |
t2 := Timestamp now. |
|
16945 | 2682 |
t2 secondDeltaFrom:t1 |
9056 | 2683 |
" |
2684 |
||
12939 | 2685 |
"Modified: / 10-07-2010 / 09:37:24 / cg" |
23776 | 2686 |
"Modified (comment): / 26-02-2019 / 14:02:09 / Claus Gittinger" |
30 | 2687 |
! ! |
2688 |
||
8246 | 2689 |
!Timestamp methodsFor:'comparing'! |
699 | 2690 |
|
2691 |
hash |
|
22885 | 2692 |
"return an integer useful for hashing on time stamps" |
2693 |
||
2694 |
^ osTime "// 1000" - why ignore the millis? |
|
1520
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
2695 |
|
da08f8e49e87
fixed comparing absoluteTimes
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
2696 |
"Modified: 3.7.1996 / 13:10:52 / cg" |
699 | 2697 |
! ! |
2698 |
||
8246 | 2699 |
!Timestamp methodsFor:'converting'! |
699 | 2700 |
|
2701 |
asDate |
|
2702 |
"return a Date object from the receiver. |
|
16932 | 2703 |
The returned date will only represent the day - not the timeOfDay. |
2704 |
Notice: if you convert a local timestamp, you will get the local date; |
|
2705 |
otherwise if you convert an utcTimestamp, you'll get the utc date." |
|
699 | 2706 |
|
17006 | 2707 |
(osTime between:MinOSTime and:MaxOSTime) ifFalse:[ |
17067 | 2708 |
|milliDelta dayDelta| |
2709 |
||
2710 |
"/ we do not know about DST in the far future and in the long gone past. |
|
2711 |
"/ Take the utcOffset without DST |
|
2712 |
milliDelta := osTime - (1000 * self utcOffsetWithoutDst). |
|
2713 |
dayDelta := milliDelta // (24 * 3600 * 1000). |
|
2714 |
^ Epoch asDate addDays:dayDelta. |
|
16928 | 2715 |
]. |
16945 | 2716 |
^ self timeInfo asDate |
699 | 2717 |
|
2718 |
" |
|
16945 | 2719 |
Timestamp now |
8246 | 2720 |
Timestamp now asDate |
16945 | 2721 |
(Timestamp now addTime:3600) asDate |
2722 |
(Timestamp now addTime:3600) asTime |
|
2723 |
Timestamp fromSeconds:(Timestamp now asSeconds + 3600) |
|
2724 |
(Timestamp fromSeconds:(Timestamp now asSeconds + 3600)) asDate |
|
699 | 2725 |
" |
2726 |
! |
|
2727 |
||
11003 | 2728 |
asLocalTimestamp |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2729 |
"represent myself as a timestamp in the local timezone" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2730 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2731 |
^ self |
11003 | 2732 |
|
2733 |
" |
|
2734 |
Timestamp now asUtcTimestamp |
|
2735 |
Timestamp now asUtcTimestamp asLocalTimestamp |
|
2736 |
" |
|
2737 |
! |
|
2738 |
||
16996 | 2739 |
asTZTimestamp |
2740 |
"return a timestamp which represents the very same time, |
|
2741 |
but will represent itself as a timestamp with the local utcOffset. |
|
2742 |
Use this to make sure that a local timestamp can be read back in another timezone" |
|
2743 |
||
2744 |
^ self asTZTimestamp:self utcOffset |
|
2745 |
||
2746 |
"see the different printStrings of: |
|
23003 | 2747 |
Timestamp now |
2748 |
and |
|
2749 |
Timestamp now asTZTimestamp |
|
16996 | 2750 |
and |
23003 | 2751 |
Timestamp now asUtcTimestamp |
2752 |
" |
|
2753 |
||
2754 |
"Modified (comment): / 24-05-2018 / 17:31:26 / Claus Gittinger" |
|
16996 | 2755 |
! |
2756 |
||
16967 | 2757 |
asTZTimestamp:utcOffset |
2758 |
"return a timestamp which represents the very same time, |
|
16986 | 2759 |
but will represent itself as a timestamp with the given utcOffset" |
16967 | 2760 |
|
2761 |
^ (TZTimestamp fromOSTime:osTime) utcOffset:utcOffset |
|
2762 |
||
2763 |
"what is the time now in NewYork? |
|
17006 | 2764 |
Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'EST') |
2765 |
Timestamp now asTZTimestampInZone:'EST' |
|
16975 | 2766 |
|
2767 |
what is the time now in Stuttgart? |
|
17006 | 2768 |
Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'MEZ') |
2769 |
Timestamp now asTZTimestampInZone:'MEZ' |
|
16986 | 2770 |
" |
2771 |
! |
|
2772 |
||
2773 |
asTZTimestampInZone:timeZoneName |
|
2774 |
"return a timestamp which represents the very same time, |
|
2775 |
but will represent itself as a timestamp in the given timezone. |
|
2776 |
timeZoneName must be one of the standard names as listed in Timestamp >> timezoneInfo" |
|
2777 |
||
17081 | 2778 |
|utcOffset| |
2779 |
||
2780 |
utcOffset := self class utcOffsetFrom:timeZoneName. |
|
2781 |
utcOffset isNil ifTrue:[ |
|
17132 | 2782 |
^ TimeConversionError raiseRequestWith:self errorString:(' - Invalid/unknown timzone: %1' bindWith:timeZoneName) |
17081 | 2783 |
]. |
2784 |
||
2785 |
^ self asTZTimestamp:utcOffset |
|
16986 | 2786 |
|
2787 |
"what is the time now in NewYork? |
|
17133 | 2788 |
Timestamp now asTZTimestampInZone:'EST' |
16986 | 2789 |
|
2790 |
what is the time now in Stuttgart? |
|
17133 | 2791 |
Timestamp now asTZTimestampInZone:'MEZ' |
2792 |
||
2793 |
an error os raised for any unknown/invalid timezone: |
|
2794 |
Timestamp now asTZTimestampInZone:'BlaBla' |
|
16967 | 2795 |
" |
2796 |
! |
|
2797 |
||
699 | 2798 |
asTime |
2799 |
"return a Time object from the receiver. |
|
16936 | 2800 |
The returned time will only represent the timeOfDay - not the day, |
17003 | 2801 |
and does not include the milliseconds." |
699 | 2802 |
|
16932 | 2803 |
|secondDelta| |
2804 |
||
17006 | 2805 |
(osTime between:MinOSTime and:MaxOSTime) ifFalse:[ |
17067 | 2806 |
secondDelta := osTime // 1000. |
2807 |
"/ we do not know about DST in the far future and in the long gone past. |
|
2808 |
"/ Take the utcOffset without DST |
|
2809 |
secondDelta := (secondDelta - self utcOffsetWithoutDst) \\ (24*3600). |
|
2810 |
^ Epoch asTime addSeconds:secondDelta. |
|
16928 | 2811 |
]. |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2812 |
^ self timeInfo asTime |
699 | 2813 |
|
2814 |
" |
|
16945 | 2815 |
Timestamp now |
8246 | 2816 |
Timestamp now asTime |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2817 |
UtcTimestamp now asTime |
16945 | 2818 |
(Timestamp now addTime:3600) asTime |
17003 | 2819 |
(Timestamp year:2014 month:7 day:1 hour:12 minute:0 second:0) asTime |
2820 |
(UtcTimestamp year:2014 month:7 day:1 hour:12 minute:0 second:0) asTime |
|
699 | 2821 |
" |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
2822 |
! |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
2823 |
|
17006 | 2824 |
asTimeWithMilliseconds |
2825 |
"return a Time object from the receiver. |
|
2826 |
The returned time will only represent the timeOfDay - not the day, |
|
2827 |
it will include the milliseconds." |
|
2828 |
||
2829 |
|milliSecondDelta| |
|
2830 |
||
2831 |
(osTime between:MinOSTime and:MaxOSTime) ifFalse:[ |
|
2832 |
milliSecondDelta := osTime - (self utcOffset * 1000). |
|
2833 |
^ self class epoch asTime addMilliseconds:milliSecondDelta. |
|
2834 |
]. |
|
2835 |
^ self timeInfo asTime |
|
2836 |
||
2837 |
" |
|
2838 |
Timestamp now |
|
2839 |
Timestamp now asTime |
|
2840 |
UtcTimestamp now asTime |
|
2841 |
(Timestamp now addTime:3600) asTime |
|
2842 |
(Timestamp year:2014 month:7 day:1 hour:12 minute:0 second:0) asTime |
|
2843 |
(UtcTimestamp year:2014 month:7 day:1 hour:12 minute:0 second:0) asTime |
|
2844 |
" |
|
2845 |
! |
|
2846 |
||
8246 | 2847 |
asTimestamp |
16928 | 2848 |
"return an Timestamp object from the receiver - that's the receiver." |
8246 | 2849 |
|
16945 | 2850 |
^ self |
8246 | 2851 |
! |
2852 |
||
18886 | 2853 |
asUTC |
2854 |
^ self asUtcTimestamp |
|
2855 |
||
2856 |
" |
|
2857 |
Timestamp now |
|
2858 |
Timestamp now asUTC |
|
2859 |
" |
|
2860 |
! |
|
2861 |
||
9402 | 2862 |
asUtcTimestamp |
16967 | 2863 |
"return a timestamp which represents the very same timestamp, |
2864 |
but will represent itself as a timestamp in the UTC timezone" |
|
16945 | 2865 |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2866 |
^ UtcTimestamp fromOSTime:osTime |
9402 | 2867 |
|
2868 |
" |
|
11003 | 2869 |
Timestamp now asUtcTimestamp |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2870 |
Timestamp now asUtcTimestamp asLocalTimestamp |
9402 | 2871 |
" |
2872 |
! |
|
2873 |
||
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
2874 |
literalArrayEncoding |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
2875 |
"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
|
2876 |
can be reconstructed with #decodeAsLiteralArray. |
16945 | 2877 |
The encoding is: |
18761 | 2878 |
(#Timestamp YYYYMMDDhhmmss.iiiZ) |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
2879 |
" |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
2880 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
2881 |
|s| |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
2882 |
|
8223
56da5d8f8bc1
replaced '' writeStream by String writeStream
Claus Gittinger <cg@exept.de>
parents:
8111
diff
changeset
|
2883 |
s := WriteStream on:(String new:18). |
16986 | 2884 |
self printGeneralizedOn:s isLocal:false. |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
2885 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
2886 |
^ Array |
18761 | 2887 |
with:self class name |
2888 |
with:s contents |
|
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
2889 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
2890 |
" |
9416 | 2891 |
Timestamp now literalArrayEncoding |
18761 | 2892 |
decodeAsLiteralArray |
16986 | 2893 |
UtcTimestamp now literalArrayEncoding |
18761 | 2894 |
decodeAsLiteralArray |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
2895 |
" |
7006 | 2896 |
! |
2897 |
||
24163 | 2898 |
utcOffset:secondsOrTimeDuration |
22890 | 2899 |
"answer a DateTime equivalent to the receiver but offset from UTC by offset. |
2900 |
If utcOffset is negative, the local timezone is east of Greenwich (Russia, Asia). |
|
24163 | 2901 |
If utcOffset is positive, the local timezone is west of Greenwich (USA). |
2902 |
If utcOffset is zero, you effectively get UTC time." |
|
18886 | 2903 |
|
2904 |
^ TZTimestamp new |
|
2905 |
osTime:osTime; |
|
24163 | 2906 |
utcOffset:(secondsOrTimeDuration asTimeDuration); |
23239 | 2907 |
yourself. |
18886 | 2908 |
|
2909 |
" |
|
2910 |
Timestamp now -- now as local time |
|
2911 |
Timestamp now asTZTimestamp -- now in your local timezone |
|
2912 |
Timestamp now asUtcTimestamp -- now in greenwich |
|
2913 |
UtcTimestamp now -- now in greenwich |
|
22894 | 2914 |
Timestamp now utcOffset:(-2 hours) -- now in East Europe |
18886 | 2915 |
Timestamp now utcOffset:(5 hours) -- now in Eastern time |
2916 |
Timestamp now asTZTimestampInZone:'EST' -- now in Eastern time |
|
2917 |
" |
|
23239 | 2918 |
|
2919 |
"Modified: / 27-07-2018 / 11:54:45 / Stefan Vogel" |
|
24163 | 2920 |
"Modified: / 26-05-2019 / 12:54:56 / Claus Gittinger" |
18886 | 2921 |
! |
2922 |
||
7006 | 2923 |
utcSecondsSince1901 |
2924 |
"return the number of seconds elapsed since Jan, 1st 1901" |
|
2925 |
||
16945 | 2926 |
" |
2927 |
secondsBetween1901and1970 := |
|
23559 | 2928 |
((Date year:1970 month:1 day:1) subtractDate:(Date year:1901 month:1 day:1)) |
2929 |
* (24 * 60 * 60) |
|
9430
919e0cb2257c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
9416
diff
changeset
|
2930 |
" |
7006 | 2931 |
|
16945 | 2932 |
^ self utcSecondsSince1970 + 2177452800. |
2933 |
||
2934 |
" |
|
2935 |
Timestamp now utcSecondsSince1901 |
|
7006 | 2936 |
" |
23559 | 2937 |
|
2938 |
"Modified (comment): / 10-12-2018 / 20:37:38 / Stefan Vogel" |
|
699 | 2939 |
! ! |
2940 |
||
23239 | 2941 |
!Timestamp methodsFor:'double dispatching'! |
2942 |
||
2943 |
differenceFromTimestamp:aTimestamp |
|
2944 |
|newMillis newPicos| |
|
2945 |
||
2946 |
newMillis := aTimestamp getMilliseconds - osTime. |
|
2947 |
newPicos := (aTimestamp additionalPicoseconds) - (additionalPicoseconds ? 0). |
|
2948 |
||
2949 |
^ TimeDuration basicNew |
|
2950 |
setMilliseconds:newMillis additionalPicoseconds:newPicos. |
|
2951 |
||
2952 |
"Created: / 27-07-2018 / 08:45:22 / Stefan Vogel" |
|
2953 |
"Modified (format): / 27-07-2018 / 10:50:05 / Stefan Vogel" |
|
2954 |
! ! |
|
2955 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2956 |
!Timestamp methodsFor:'initialization'! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
2957 |
|
16996 | 2958 |
UTCyear:y month:m day:d hour:h minute:min second:s millisecond:millis |
2959 |
"private: ask the operating system to compute the internal osTime (based on the epoch), |
|
22885 | 2960 |
given y,m,d and h,m,s in my time. |
2961 |
All arguments MUST be integral (for now)" |
|
16996 | 2962 |
|
2963 |
self setOSTimeFromUTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis |
|
2964 |
! |
|
2965 |
||
22873 | 2966 |
UTCyear:y month:m day:d hour:h minute:min second:s millisecond:millis additionalPicoseconds:picos |
2967 |
"private: ask the operating system to compute the internal osTime (based on the epoch), |
|
22885 | 2968 |
given y,m,d and h,m,s in my time. |
2969 |
All arguments MUST be integral (for now)" |
|
22873 | 2970 |
|
2971 |
self setOSTimeFromUTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis. |
|
2972 |
additionalPicoseconds := picos. |
|
2973 |
! |
|
2974 |
||
16996 | 2975 |
setOSTimeFromUTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis |
2976 |
"private: ask the operating system to compute the internal osTime (based on the epoch), |
|
2977 |
given y,m,d and h,m,s in local time" |
|
2978 |
||
2979 |
Error handle:[:ex | |
|
19713 | 2980 |
"handler for timestamps before the epoch or after the OS representable time (2038 on current Unices). |
2981 |
Then, an out-of-os-range osTime is generated here manually." |
|
2982 |
||
2983 |
|deltaDays| |
|
2984 |
||
2985 |
deltaDays := self class epoch asDate subtractDate:(Date year:y month:m day:d). |
|
2986 |
"/ deltadays will be negative for dates before the epoch and positive if after. |
|
2987 |
||
2988 |
osTime := (h * 3600) + (min * 60) + s. |
|
2989 |
osTime := osTime - (deltaDays * 24 * 3600). |
|
2990 |
osTime := osTime * 1000. |
|
2991 |
osTime := osTime + millis. |
|
16996 | 2992 |
] do:[ |
19713 | 2993 |
osTime := OperatingSystem |
2994 |
computeOSTimeFromUTCYear:y month:m day:d |
|
2995 |
hour:h minute:min second:s |
|
2996 |
millisecond:millis |
|
16996 | 2997 |
] |
2998 |
! |
|
2999 |
||
16945 | 3000 |
setOSTimeFromYear:y month:m day:d hour:h minute:min second:s millisecond:millis |
16986 | 3001 |
"private: ask the operating system to compute the internal osTime (based on the epoch), |
17006 | 3002 |
given y,m,d and h,m,s in local time. If the OS cannot do it, do it here." |
16986 | 3003 |
|
17026 | 3004 |
TimeConversionError handle:[:ex | |
19713 | 3005 |
"handler for timestamps before the epoch or after the OS representable time (2038 on current Unices). |
3006 |
Then, an out-of-os-range osTime is generated here manually." |
|
3007 |
||
3008 |
|deltaDays| |
|
3009 |
||
3010 |
deltaDays := self class epoch asDate subtractDate:(Date year:y month:m day:d). |
|
3011 |
"/ deltadays will be negative for dates before the epoch and positive if after. |
|
3012 |
||
3013 |
osTime := (h * 3600) + (min * 60) + s. |
|
3014 |
osTime := osTime + self utcOffset. |
|
3015 |
osTime := osTime - (deltaDays * 24 * 3600). |
|
3016 |
osTime := osTime * 1000. |
|
3017 |
osTime := osTime + millis. |
|
16928 | 3018 |
] do:[ |
19713 | 3019 |
osTime := OperatingSystem |
3020 |
computeOSTimeFromYear:y month:m day:d |
|
3021 |
hour:h minute:min second:s |
|
3022 |
millisecond:millis |
|
16996 | 3023 |
] |
3024 |
! |
|
3025 |
||
3026 |
year:y month:m day:d hour:h minute:min second:s millisecond:millis |
|
3027 |
"private: ask the operating system to compute the internal osTime (based on the epoch), |
|
22885 | 3028 |
given y,m,d and h,m,s in my time. |
3029 |
All arguments MUST be integral (for now)" |
|
16996 | 3030 |
|
3031 |
self setOSTimeFromYear:y month:m day:d hour:h minute:min second:s millisecond:millis |
|
19652 | 3032 |
|
3033 |
" |
|
3034 |
self basicNew |
|
3035 |
year:2016 month:4 day:16 hour:17 minute:21 second:13 millisecond:726 |
|
3036 |
" |
|
22873 | 3037 |
! |
3038 |
||
3039 |
year:y month:m day:d hour:h minute:min second:s millisecond:millis additionalPicoseconds:picos |
|
3040 |
"private: ask the operating system to compute the internal osTime (based on the epoch), |
|
22885 | 3041 |
given y,m,d and h,m,s in my time. |
3042 |
All arguments MUST be integral (for now)" |
|
22873 | 3043 |
|
3044 |
self setOSTimeFromYear:y month:m day:d hour:h minute:min second:s millisecond:millis. |
|
3045 |
additionalPicoseconds := picos |
|
3046 |
||
3047 |
" |
|
3048 |
self basicNew |
|
3049 |
year:2016 month:4 day:16 hour:17 minute:21 second:13 millisecond:726 |
|
3050 |
" |
|
11993 | 3051 |
! ! |
3052 |
||
13541
91828a57f378
added: #differenceFromTimestamp:
Claus Gittinger <cg@exept.de>
parents:
13236
diff
changeset
|
3053 |
|
8246 | 3054 |
!Timestamp methodsFor:'printing & storing'! |
30 | 3055 |
|
8111
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7817
diff
changeset
|
3056 |
addPrintBindingsTo:dict language:languageOrNil |
67347b7e3e69
print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents:
7817
diff
changeset
|
3057 |
"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
|
3058 |
languageOrNil can only be #en or nil for the current language." |
5726 | 3059 |
|
16928 | 3060 |
|date| |
3061 |
||
3062 |
date := self asDate. |
|
3063 |
date addPrintBindingsTo:dict language:languageOrNil. |
|
17003 | 3064 |
super addPrintBindingsTo:dict language:languageOrNil. |
16928 | 3065 |
|
3066 |
date year == Date today year ifTrue:[ |
|
18447 | 3067 |
dict at:#yearOrTime put:('%h:%m' expandPlaceholdersWith:dict). |
6795
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6686
diff
changeset
|
3068 |
]. |
519894240d97
more printFormats: yearOrDate (as in unix); dayPadded and monthPadded
penk
parents:
6686
diff
changeset
|
3069 |
|
17003 | 3070 |
" |
18447 | 3071 |
|d| |
3072 |
d := Dictionary new. |
|
3073 |
Timestamp now addPrintBindingsTo:d language:nil. |
|
3074 |
d inspect. |
|
3075 |
" |
|
3076 |
||
3077 |
"used by: |
|
22331 | 3078 |
Timestamp now printStringFormat:'%y-%(mon)-%d' |
18447 | 3079 |
Timestamp now printStringFormat:'%(dayOfYear)' |
17003 | 3080 |
" |
22331 | 3081 |
|
3082 |
"Modified (comment): / 03-11-2017 / 10:54:30 / cg" |
|
4843 | 3083 |
! |
3084 |
||
16945 | 3085 |
printGeneralizedOn:aStream |
5290 | 3086 |
"append a representation of the receiver to aStream in a general format, |
18761 | 3087 |
top-down, without separators: 'yyyymmddHHMMSS.mmmZ' |
12166 | 3088 |
|
5290 | 3089 |
This format is used for the ASN.1 GeneralizedTime as defined in X.208 Sec. 33, |
3090 |
so read this before changing the output format." |
|
3091 |
||
12166 | 3092 |
^ self printGeneralizedOn:aStream isLocal:false short:false. |
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
3093 |
! |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
3094 |
|
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
3095 |
printGeneralizedOn:aStream isLocal:isLocal |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
3096 |
"append a representation of the receiver to aStream in a general format, |
11177 | 3097 |
top-down, without separators: 'yyyymmddHHMMSS.mmm+0100' |
12166 | 3098 |
|
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
3099 |
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
|
3100 |
so read this before changing the output format. |
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
3101 |
|
18761 | 3102 |
If isLocal is true, represent as local time (Local 'yyyymmddHHMMSS.mmm+0100'), |
3103 |
otherwise as UTC time (UTC 'yyyymmddHHMMSS.mmmZ')." |
|
5379
2cf681402817
Make literal array encoding architecture independent.
Stefan Vogel <sv@exept.de>
parents:
5376
diff
changeset
|
3104 |
|
12166 | 3105 |
self printGeneralizedOn:aStream isLocal:isLocal short:false |
3106 |
||
3107 |
||
3108 |
"Modified: / 1.7.1996 / 15:20:59 / cg" |
|
3109 |
"Modified: / 17.1.2000 / 15:53:02 / stefan" |
|
3110 |
! |
|
3111 |
||
3112 |
printGeneralizedOn:aStream isLocal:isLocal short:shortFormat |
|
3113 |
"append a representation of the receiver to aStream in a general format, |
|
3114 |
top-down, without separators; |
|
18761 | 3115 |
long format: 'yyyymmddHHMMSS.mmm+0100' |
3116 |
short format: 'yymmddHHMMSS.mmm+0100' |
|
3117 |
Using the short format is strictly discouraged!! |
|
12166 | 3118 |
|
3119 |
This format is used for the ASN.1 GeneralizedTime and UTCTime |
|
3120 |
as defined in X.208 Sec. 33, so read this before changing the output format. |
|
18761 | 3121 |
|
3122 |
If isLocal is true, represent as local time (Local 'yyyymmddHHMMSS.mmm+0100'), |
|
3123 |
otherwise as UTC time (UTC 'yyyymmddHHMMSS.mmmZ')." |
|
12166 | 3124 |
|
5290 | 3125 |
|t off| |
3126 |
||
12819
a28ce068acd8
comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents:
12729
diff
changeset
|
3127 |
isLocal ifTrue:[ |
18761 | 3128 |
t := self timeInfo. |
3129 |
off := t utcOffset. |
|
12819
a28ce068acd8
comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents:
12729
diff
changeset
|
3130 |
] ifFalse:[ |
18761 | 3131 |
t := self asUtcTimestamp timeInfo. |
3132 |
off := 0. |
|
12819
a28ce068acd8
comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents:
12729
diff
changeset
|
3133 |
]. |
a28ce068acd8
comment/format in: #UTCYear:month:day:hour:minute:second:millisecond:
Stefan Vogel <sv@exept.de>
parents:
12729
diff
changeset
|
3134 |
|
12166 | 3135 |
shortFormat ifTrue:[ |
18761 | 3136 |
self assert:(t year between:1951 and:2049). |
3137 |
(t year \\ 100) printOn:aStream leftPaddedTo:2 with:$0. |
|
12166 | 3138 |
] ifFalse:[ |
18761 | 3139 |
t year printOn:aStream leftPaddedTo:4 with:$0. |
12166 | 3140 |
]. |
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
3141 |
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
|
3142 |
t day printOn:aStream leftPaddedTo:2 with:$0. |
16945 | 3143 |
t hours printOn:aStream leftPaddedTo:2 with:$0. |
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
3144 |
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
|
3145 |
t seconds printOn:aStream leftPaddedTo:2 with:$0. |
5290 | 3146 |
aStream nextPut:$.. |
7512
07c56e8934f4
OS returns OSTimeInfo (instead of an Array)
Claus Gittinger <cg@exept.de>
parents:
7474
diff
changeset
|
3147 |
t milliseconds printOn:aStream leftPaddedTo:3 with:$0. |
5290 | 3148 |
|
18761 | 3149 |
(self isUtcTimestamp or:[off == 0]) ifTrue:[ |
3150 |
aStream nextPut:$Z. |
|
3151 |
] ifFalse:[ |min| |
|
3152 |
off < 0 ifTrue:[ |
|
3153 |
aStream nextPut:$+. |
|
3154 |
off := off negated. |
|
3155 |
] ifFalse:[ |
|
3156 |
aStream nextPut:$-. |
|
3157 |
]. |
|
3158 |
min := off // 60. |
|
3159 |
min // 60 printOn:aStream leftPaddedTo:2 with:$0. |
|
3160 |
min \\ 60 printOn:aStream leftPaddedTo:2 with:$0. |
|
5290 | 3161 |
]. |
3162 |
||
3163 |
" |
|
16945 | 3164 |
Timestamp now printGeneralizedOn:Transcript. Transcript cr. |
3165 |
Timestamp now printGeneralizedOn:Transcript isLocal:true. Transcript cr. |
|
8246 | 3166 |
(Timestamp fromSeconds:0) printGeneralizedOn:Transcript. Transcript cr. |
16945 | 3167 |
Time now printOn:Transcript. Transcript cr. |
3168 |
Date today printOn:Transcript. Transcript cr. |
|
3169 |
||
3170 |
Timestamp now printGeneralizedOn:Transcript isLocal:false short:false. Transcript cr. |
|
18761 | 3171 |
Timestamp now printGeneralizedOn:Transcript isLocal:true short:false. Transcript cr. |
16945 | 3172 |
UtcTimestamp now printGeneralizedOn:Transcript isLocal:false short:false. Transcript cr. |
18761 | 3173 |
UtcTimestamp now printGeneralizedOn:Transcript isLocal:true short:false. Transcript cr. |
16945 | 3174 |
|
3175 |
Date today asTimestamp printGeneralizedOn:Transcript. Transcript cr. |
|
3176 |
Date today printOn:Transcript. Transcript cr. |
|
5290 | 3177 |
" |
3178 |
||
3179 |
"Modified: / 1.7.1996 / 15:20:59 / cg" |
|
3180 |
"Modified: / 17.1.2000 / 15:53:02 / stefan" |
|
3181 |
! |
|
3182 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3183 |
printISO8601 |
22840 | 3184 |
"obsoleted due to uc/lc and print vs. printString confusion" |
3185 |
||
16988 | 3186 |
<resource: #obsolete> |
23023 | 3187 |
"print in a format like 2014-10-17T17:08:44Z" |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3188 |
|
16988 | 3189 |
^ self printStringIso8601 |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3190 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3191 |
"Created: / 16-06-2005 / 16:11:15 / masca" |
23023 | 3192 |
"Modified (comment): / 25-05-2018 / 12:00:52 / Claus Gittinger" |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3193 |
! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3194 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3195 |
printISO8601Compressed |
22840 | 3196 |
"obsoleted due to uc/lc and print vs. printString confusion" |
3197 |
||
16988 | 3198 |
<resource: #obsolete> |
23023 | 3199 |
"return a printString in a format like 20141017T170939Z" |
16988 | 3200 |
|
3201 |
^ self printStringIso8601Compressed |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3202 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3203 |
" |
16945 | 3204 |
Timestamp now printISO8601Compressed |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3205 |
" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3206 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3207 |
"Created: / 16-06-2005 / 16:11:31 / masca" |
23023 | 3208 |
"Modified (comment): / 25-05-2018 / 12:00:47 / Claus Gittinger" |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3209 |
! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3210 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3211 |
printISO8601CompressedOn: aStream |
22840 | 3212 |
"obsoleted due to uc/lc confusion" |
3213 |
||
16988 | 3214 |
<resource: #obsolete> |
23023 | 3215 |
"print in a format like 20141017T170939Z on aStream" |
16988 | 3216 |
|
3217 |
self printIso8601CompressedOn: aStream |
|
3218 |
||
3219 |
"Created: / 16-06-2005 / 16:11:50 / masca" |
|
23023 | 3220 |
"Modified (comment): / 25-05-2018 / 12:00:42 / Claus Gittinger" |
16988 | 3221 |
! |
3222 |
||
3223 |
printISO8601On: aStream |
|
22840 | 3224 |
"obsoleted due to uc/lc confusion" |
3225 |
||
16988 | 3226 |
<resource: #obsolete> |
23023 | 3227 |
"print in a format like 2014-10-17T17:08:44Z on aStream" |
16988 | 3228 |
|
3229 |
self printIso8601On: aStream |
|
3230 |
||
3231 |
"Created: / 16-06-2005 / 16:11:07 / masca" |
|
23023 | 3232 |
"Modified (comment): / 25-05-2018 / 12:00:37 / Claus Gittinger" |
16988 | 3233 |
! |
3234 |
||
3235 |
printIso8601CompressedOn: aStream |
|
23023 | 3236 |
"print in a format like 20141017T170939Z on aStream" |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3237 |
|
23003 | 3238 |
self printIso8601FormatOn:aStream compressed:true timeSeparator:$T |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3239 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3240 |
"Created: / 16-06-2005 / 16:11:50 / masca" |
23003 | 3241 |
"Modified: / 24-05-2018 / 17:33:12 / Claus Gittinger" |
23023 | 3242 |
"Modified (comment): / 25-05-2018 / 12:00:30 / Claus Gittinger" |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3243 |
! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3244 |
|
8479 | 3245 |
printIso8601FormatOn:aStream |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3246 |
"append the iso8601 representation of the receiver to aStream. |
8479 | 3247 |
This format looks like: |
23003 | 3248 |
1999-01-01T24:00:00 |
16945 | 3249 |
or, for zero hr:min:sec, |
23003 | 3250 |
1999-01-01 |
17049 | 3251 |
Of course, a 24 hour clock is used. |
3252 |
||
23023 | 3253 |
Timezone information (eg. Z or +0100) is added for TZ and Utc stamps, |
3254 |
otherwise the reader will read as local time." |
|
17049 | 3255 |
|
23003 | 3256 |
self printIso8601FormatOn:aStream compressed:false timeSeparator:$T |
17049 | 3257 |
|
3258 |
" |
|
3259 |
Timestamp now printIso8601FormatOn:Transcript. Transcript cr. |
|
3260 |
Timestamp readIso8601FormatFrom:(Timestamp now printStringIso8601Format). |
|
3261 |
||
3262 |
UtcTimestamp now printIso8601FormatOn:Transcript. Transcript cr. |
|
3263 |
UtcTimestamp readIso8601FormatFrom:(UtcTimestamp now printStringIso8601Format). |
|
3264 |
" |
|
23003 | 3265 |
|
3266 |
"Modified: / 24-05-2018 / 17:28:36 / Claus Gittinger" |
|
23023 | 3267 |
"Modified (comment): / 25-05-2018 / 12:00:23 / Claus Gittinger" |
17049 | 3268 |
! |
3269 |
||
23003 | 3270 |
printIso8601FormatOn:aStream compressed:compact timeSeparator:sepChar |
17049 | 3271 |
"append the iso8601 representation of the receiver to aStream. |
3272 |
This format looks like: |
|
22827 | 3273 |
1999-01-01T24:00:00 |
17049 | 3274 |
or, for zero hr:min:sec, |
22827 | 3275 |
1999-01-01 |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3276 |
Of course, a 24 hour clock is used. |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3277 |
|
23023 | 3278 |
Timezone information (eg. Z or +0100) is added for TZ and Utc stamps, |
3279 |
otherwise the reader will read as local time." |
|
8479 | 3280 |
|
16975 | 3281 |
|asUTC asLocal| |
3282 |
||
16920 | 3283 |
self isUtcTimestamp ifTrue:[ |
22827 | 3284 |
asUTC := true. asLocal := false. |
16920 | 3285 |
] ifFalse:[ |
23239 | 3286 |
asUTC := false. |
3287 |
asLocal := self isLocalTimestamp. |
|
8479 | 3288 |
]. |
16920 | 3289 |
|
16975 | 3290 |
Timestamp::TimestampISO8601Builder |
23003 | 3291 |
print:self compact:compact |
22827 | 3292 |
asLocal:asLocal asUTC:asUTC withMilliseconds:true |
3293 |
timeSeparator:sepChar |
|
3294 |
on:aStream |
|
16975 | 3295 |
|
16920 | 3296 |
"/ |
3297 |
"/ |format| |
|
3298 |
"/ |
|
3299 |
"/ format := '%(year)-%(month)-%(day)T%h:%m:%s.%i'. |
|
3300 |
"/ self milliseconds = 0 ifTrue:[ |
|
3301 |
"/ format := '%(year)-%(month)-%(day)T%h:%m:%s'. |
|
3302 |
"/ self seconds = 0 ifTrue:[ |
|
3303 |
"/ format := '%(year)-%(month)-%(day)T%h:%m'. |
|
3304 |
"/ ((self hours = 0) and:[self minutes = 0]) ifTrue:[ |
|
3305 |
"/ format := '%(year)-%(month)-%(day)'. |
|
3306 |
"/ ] |
|
3307 |
"/ ] |
|
3308 |
"/ ]. |
|
16945 | 3309 |
"/ self printOn:aStream format:format |
8479 | 3310 |
|
3311 |
" |
|
22827 | 3312 |
Timestamp now printStringIso8601Format. |
3313 |
||
16945 | 3314 |
Timestamp now printIso8601FormatOn:Transcript. Transcript cr. |
8479 | 3315 |
Timestamp readIso8601FormatFrom:(Timestamp now printStringIso8601Format). |
16920 | 3316 |
|
16945 | 3317 |
UtcTimestamp now printIso8601FormatOn:Transcript. Transcript cr. |
16920 | 3318 |
UtcTimestamp readIso8601FormatFrom:(UtcTimestamp now printStringIso8601Format). |
8479 | 3319 |
" |
23003 | 3320 |
|
3321 |
"Created: / 24-05-2018 / 17:28:25 / Claus Gittinger" |
|
23023 | 3322 |
"Modified (comment): / 25-05-2018 / 12:00:14 / Claus Gittinger" |
23239 | 3323 |
"Modified: / 27-07-2018 / 11:57:21 / Stefan Vogel" |
23003 | 3324 |
! |
3325 |
||
3326 |
printIso8601FormatOn:aStream timeSeparator:sepChar |
|
3327 |
"append the iso8601 representation of the receiver to aStream. |
|
3328 |
This format looks like: |
|
3329 |
1999-01-01T24:00:00 |
|
3330 |
or, for zero hr:min:sec, |
|
3331 |
1999-01-01 |
|
3332 |
Of course, a 24 hour clock is used. |
|
3333 |
||
23023 | 3334 |
Timezone information (eg. Z or +0100) is added for TZ and Utc stamps, |
3335 |
otherwise, the reader will read as local time." |
|
23003 | 3336 |
|
3337 |
self printIso8601FormatOn:aStream compressed:false timeSeparator:sepChar |
|
3338 |
||
3339 |
" |
|
3340 |
Timestamp now printStringIso8601Format. |
|
3341 |
||
3342 |
Timestamp now printIso8601FormatOn:Transcript. Transcript cr. |
|
3343 |
Timestamp readIso8601FormatFrom:(Timestamp now printStringIso8601Format). |
|
3344 |
||
3345 |
UtcTimestamp now printIso8601FormatOn:Transcript. Transcript cr. |
|
3346 |
UtcTimestamp readIso8601FormatFrom:(UtcTimestamp now printStringIso8601Format). |
|
3347 |
" |
|
3348 |
||
3349 |
"Modified: / 24-05-2018 / 17:28:28 / Claus Gittinger" |
|
23023 | 3350 |
"Modified (comment): / 25-05-2018 / 11:59:57 / Claus Gittinger" |
8479 | 3351 |
! |
3352 |
||
16988 | 3353 |
printIso8601On: aStream |
23023 | 3354 |
"print in a format like 2014-10-17T17:08:44Z on aStream" |
16988 | 3355 |
|
3356 |
TimestampISO8601Builder print: self on: aStream |
|
3357 |
||
3358 |
"Created: / 16-06-2005 / 16:11:07 / masca" |
|
23023 | 3359 |
"Modified (comment): / 25-05-2018 / 11:59:22 / Claus Gittinger" |
16988 | 3360 |
! |
3361 |
||
241 | 3362 |
printOn:aStream |
275 | 3363 |
"append a user readable representation of the receiver to aStream. |
3364 |
The format is compatible with readFromString:, but not with readFrom:." |
|
3365 |
||
16975 | 3366 |
|asUTC asLocal| |
3367 |
||
3368 |
self isUtcTimestamp ifTrue:[ |
|
23239 | 3369 |
asUTC := true. asLocal := false. |
16975 | 3370 |
] ifFalse:[ |
23239 | 3371 |
asLocal := self isLocalTimestamp. |
16975 | 3372 |
]. |
3373 |
||
3374 |
Timestamp::TimestampISO8601Builder |
|
23239 | 3375 |
print:self compact:false |
3376 |
asLocal:asLocal asUTC:asUTC withMilliseconds:true |
|
3377 |
timeSeparator:(Character space) |
|
3378 |
on:aStream |
|
16975 | 3379 |
|
16955 | 3380 |
"/ self printOn:aStream format:'%(year)-%(mon)-%(day) %h:%m:%s.%i' |
16945 | 3381 |
"/ self printOn:aStream format:'%(Day)-%(mon)-%(year) %h:%m:%s.%i' |
3382 |
"/ self printOn:aStream format:'%(mon)/%(Day)/%(year) %h:%m:%s.%i' |
|
92 | 3383 |
|
3384 |
" |
|
16975 | 3385 |
|tHere tNewYork| |
3386 |
||
16945 | 3387 |
Timestamp now printOn:Transcript. Transcript cr. |
16955 | 3388 |
Timestamp now asUtcTimestamp printOn:Transcript. Transcript cr. |
16975 | 3389 |
(Timestamp now asTZTimestamp:(Timestamp utcOffsetFrom:'EST')) printOn:Transcript. Transcript cr. |
3390 |
||
3391 |
tHere := Timestamp now. |
|
3392 |
tNewYork := tHere asTZTimestamp:(Timestamp utcOffsetFrom:'EST'). |
|
3393 |
tHere printOn:Transcript. Transcript cr. |
|
3394 |
tNewYork printOn:Transcript. Transcript cr. |
|
16955 | 3395 |
|
8246 | 3396 |
(Timestamp fromSeconds:0) printOn:Transcript. Transcript cr. |
16945 | 3397 |
Time now printOn:Transcript. Transcript cr. |
3398 |
Date today printOn:Transcript. Transcript cr. |
|
3399 |
||
3400 |
Time now asTimestamp printOn:Transcript. Transcript cr. |
|
3401 |
Timestamp now printOn:Transcript. Transcript cr. |
|
3402 |
||
3403 |
Date today asTimestamp printOn:Transcript. Transcript cr. |
|
3404 |
Date today printOn:Transcript. Transcript cr. |
|
92 | 3405 |
" |
1501 | 3406 |
|
23239 | 3407 |
"Modified: / 01-07-1996 / 15:20:59 / cg" |
3408 |
"Modified: / 27-07-2018 / 11:58:58 / Stefan Vogel" |
|
5719
cf09067dbd1d
can do millisecondDelta easier
Claus Gittinger <cg@exept.de>
parents:
5678
diff
changeset
|
3409 |
! |
30 | 3410 |
|
7474 | 3411 |
printRFC1123FormatOn:aStream |
3412 |
"append the RFC1123 representation of the receiver to aStream. |
|
3413 |
This format is used in HTTP requests and looks like: |
|
17006 | 3414 |
'Fri, 04 Jul 2003 15:56:11 GMT' |
7671 | 3415 |
(always GMT and all names in english)" |
3416 |
||
3417 |
"/ HTTP-date = rfc1123-date | rfc850-date | asctime-date |
|
3418 |
"/ |
|
3419 |
"/ rfc1123-date = wkday "," SP date1 SP time SP "GMT" |
|
3420 |
"/ rfc850-date = weekday "," SP date2 SP time SP "GMT" |
|
3421 |
"/ asctime-date = wkday SP date3 SP time SP 4DIGIT |
|
3422 |
"/ |
|
3423 |
"/ date1 = 2DIGIT SP month SP 4DIGIT |
|
3424 |
"/ ; day month year (e.g., 02 Jun 1982) |
|
3425 |
"/ date2 = 2DIGIT "-" month "-" 2DIGIT |
|
3426 |
"/ ; day-month-year (e.g., 02-Jun-82) |
|
3427 |
"/ date3 = month SP ( 2DIGIT | ( SP 1DIGIT )) |
|
3428 |
"/ ; month day (e.g., Jun 2) |
|
3429 |
"/ |
|
3430 |
"/ time = 2DIGIT ":" 2DIGIT ":" 2DIGIT |
|
3431 |
"/ ; 00:00:00 - 23:59:59 |
|
3432 |
"/ |
|
3433 |
"/ wkday = "Mon" | "Tue" | "Wed" |
|
3434 |
"/ | "Thu" | "Fri" | "Sat" | "Sun" |
|
3435 |
"/ |
|
3436 |
"/ weekday = "Monday" | "Tuesday" | "Wednesday" |
|
3437 |
"/ | "Thursday" | "Friday" | "Saturday" | "Sunday" |
|
3438 |
"/ |
|
3439 |
"/ month = "Jan" | "Feb" | "Mar" | "Apr" |
|
3440 |
"/ | "May" | "Jun" | "Jul" | "Aug" |
|
3441 |
"/ | "Sep" | "Oct" | "Nov" | "Dec" |
|
7474 | 3442 |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3443 |
|timeInfo| |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3444 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3445 |
timeInfo := self asUtcTimestamp timeInfo. |
7474 | 3446 |
|
7734 | 3447 |
aStream nextPutAll:(#('Mon' 'Tue' 'Wed' 'Thu' 'Fri' 'Sat' 'Sun') at:timeInfo dayInWeek); |
17006 | 3448 |
nextPutAll:', '. |
7734 | 3449 |
timeInfo day printOn:aStream leftPaddedTo:2 with:$0. |
7671 | 3450 |
aStream space. |
7734 | 3451 |
aStream nextPutAll:(#('Jan' 'Feb' 'Mar' 'Apr' 'May' 'Jun' 'Jul' 'Aug' 'Sep' 'Oct' 'Nov' 'Dec') at:timeInfo month). |
7671 | 3452 |
|
16986 | 3453 |
"/ the following is too slow for heavy use |
3454 |
"/ timeInfo printOn:aStream format:'%(ShortDayName), %(day) %(ShortMonthName) %y %h:%m:%s GMT' language:#en. |
|
7677 | 3455 |
|
3456 |
aStream nextPut:Character space. |
|
7734 | 3457 |
timeInfo year printOn:aStream. |
7677 | 3458 |
aStream nextPut:Character space. |
7734 | 3459 |
timeInfo hours printOn:aStream leftPaddedTo:2 with:$0. |
7677 | 3460 |
aStream nextPut:$:. |
7734 | 3461 |
timeInfo minutes printOn:aStream leftPaddedTo:2 with:$0. |
7677 | 3462 |
aStream nextPut:$:. |
7734 | 3463 |
timeInfo seconds printOn:aStream leftPaddedTo:2 with:$0. |
7677 | 3464 |
aStream nextPutAll:' GMT'. |
3465 |
||
7474 | 3466 |
" |
17006 | 3467 |
String streamContents:[:s| Timestamp now printRFC1123FormatOn:s] |
7474 | 3468 |
" |
3469 |
! |
|
3470 |
||
3471 |
printStringRFC1123Format |
|
3472 |
"return the RFC1123 representation of the receiver. |
|
3473 |
This format is used in HTTP requests and looks like: |
|
17006 | 3474 |
'Fri, 04 Jul 2003 15:56:11 GMT' |
7474 | 3475 |
(always GMT)" |
3476 |
||
3477 |
^ String streamContents:[:s | self printRFC1123FormatOn:s] |
|
3478 |
||
3479 |
" |
|
8246 | 3480 |
Timestamp now printStringRFC1123Format |
7474 | 3481 |
" |
3482 |
! |
|
3483 |
||
241 | 3484 |
storeOn:aStream |
275 | 3485 |
"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
|
3486 |
receiver via readFrom: |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
3487 |
Use a OS/architecture independent format" |
275 | 3488 |
|
16945 | 3489 |
aStream nextPut:$(; |
17067 | 3490 |
nextPutAll:self storeStringClass name; |
3491 |
nextPutAll:' readIso8601FormatFrom:'''. |
|
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
3492 |
self printIso8601FormatOn:aStream. |
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
3493 |
aStream nextPutAll:''')'. |
54 | 3494 |
|
241 | 3495 |
" |
16945 | 3496 |
Timestamp now storeString |
30 | 3497 |
|
8822
10d99a9248f2
#storeOn: stores in ISO 8601 format.
Stefan Vogel <sv@exept.de>
parents:
8797
diff
changeset
|
3498 |
Object readFrom:(Timestamp now storeString) readStream |
8246 | 3499 |
Timestamp readFrom:(Timestamp now storeString) readStream |
241 | 3500 |
" |
17049 | 3501 |
! |
3502 |
||
3503 |
storeStringClass |
|
3504 |
^ self class |
|
30 | 3505 |
! ! |
699 | 3506 |
|
8246 | 3507 |
!Timestamp methodsFor:'private'! |
699 | 3508 |
|
22834 | 3509 |
additionalPicoseconds |
3510 |
"return the additional picoseconds (0..999999999). |
|
3511 |
These must alwyas be smaller than 1000*1000*1000 (i.e. 1ms), |
|
3512 |
to avoid overflow into the millis. |
|
3513 |
These are to be added to any milliseconds" |
|
3514 |
||
3515 |
^ additionalPicoseconds ? 0. |
|
3516 |
||
3517 |
" |
|
3518 |
Timestamp now picoseconds |
|
3519 |
Timestamp nowWithMicroseconds picoseconds |
|
3520 |
" |
|
3521 |
! |
|
3522 |
||
3523 |
additionalPicoseconds:anInteger |
|
3524 |
"set the additional picoseconds (0..999999999). |
|
3525 |
These must alwyas be smaller than 1000*1000*1000 (i.e. 1ms), |
|
3526 |
to avoid overflow into the millis." |
|
3527 |
||
22842 | 3528 |
self assert:(anInteger isInteger). |
22834 | 3529 |
self assert:(anInteger < (1000*1000*1000)). |
3530 |
additionalPicoseconds:= anInteger |
|
3531 |
||
3532 |
" |
|
3533 |
Timestamp now picoseconds |
|
3534 |
Timestamp now additionalPicoseconds |
|
3535 |
||
3536 |
Timestamp nowWithMicroseconds picoseconds |
|
3537 |
Timestamp nowWithMicroseconds additionalPicoseconds |
|
3538 |
" |
|
3539 |
! |
|
3540 |
||
16986 | 3541 |
computeTimeInfo |
3542 |
|d t info| |
|
3543 |
||
3544 |
"/ fake an info which the OS cannot give me |
|
3545 |
d := self asDate. |
|
3546 |
t := self asTime. |
|
3547 |
info := OperatingSystem timeInfoClass new. |
|
17006 | 3548 |
info year:d year month:d month day:d day |
17067 | 3549 |
hours:t hours minutes:t minutes seconds:t seconds milliseconds:self milliseconds |
3550 |
utcOffset:(self utcOffset) dst:false dayInYear:d dayInYear dayInWeek:d dayInWeek. |
|
16986 | 3551 |
^ info |
17026 | 3552 |
|
3553 |
" |
|
17067 | 3554 |
(Timestamp year:1592 month:7 day:1 hour:12 minute:0 second:0 millisecond:555) computeTimeInfo |
3555 |
(Timestamp year:4096 month:7 day:1 hour:12 minute:0 second:0 millisecond:555) computeTimeInfo |
|
17026 | 3556 |
" |
16986 | 3557 |
! |
3558 |
||
3559 |
computeUtcTimeInfo |
|
17026 | 3560 |
|utcTimestamp d t info| |
16986 | 3561 |
|
3562 |
"/ fake an info which the OS cannot give me |
|
17026 | 3563 |
utcTimestamp := self asUtcTimestamp. |
3564 |
d := utcTimestamp asDate. |
|
3565 |
t := utcTimestamp asTime. |
|
16986 | 3566 |
info := OperatingSystem timeInfoClass new. |
17006 | 3567 |
info year:d year month:d month day:d day |
17067 | 3568 |
hours:t hours minutes:t minutes seconds:t seconds milliseconds:self milliseconds |
3569 |
utcOffset:0 dst:false dayInYear:d dayInYear dayInWeek:d dayInWeek. |
|
16986 | 3570 |
^ info |
17026 | 3571 |
|
3572 |
" |
|
17067 | 3573 |
(Timestamp year:1950 month:7 day:1 hour:12 minute:0 second:0) timeInfo |
3574 |
(Timestamp year:1592 month:7 day:1 hour:12 minute:0 second:0) computeUtcTimeInfo |
|
3575 |
(Timestamp year:4096 month:7 day:1 hour:12 minute:0 second:0) computeUtcTimeInfo |
|
17026 | 3576 |
" |
16986 | 3577 |
! |
3578 |
||
1501 | 3579 |
fromOSTime:anUninterpretedOSTime |
16967 | 3580 |
"strictly private: set the milliseconds from an OS time (since the epoch). |
16943 | 3581 |
Notice: timestamps always have millisecond precision (in contrast to Time, where it is optional)" |
699 | 3582 |
|
1501 | 3583 |
osTime := anUninterpretedOSTime |
3584 |
||
3585 |
"Created: 1.7.1996 / 14:33:21 / cg" |
|
3586 |
! |
|
3587 |
||
16942 | 3588 |
fromOSTimeWithMilliseconds:anUninterpretedOSTime |
22834 | 3589 |
"strictly private: set the milliseconds from an OS time (since the epoch). |
3590 |
Notice: timestamps always have millisecond precision (in contrast to Time, where it is optional)" |
|
16942 | 3591 |
|
3592 |
osTime := anUninterpretedOSTime |
|
3593 |
! |
|
3594 |
||
22834 | 3595 |
fromOSTimeWithMilliseconds:anUninterpretedOSTime additionalPicoseconds:picos |
22627 | 3596 |
"strictly private: set the milliseconds and picoSeconds from an OS time (since the epoch)" |
3597 |
||
3598 |
osTime := anUninterpretedOSTime. |
|
22834 | 3599 |
additionalPicoseconds := picos |
22627 | 3600 |
|
3601 |
" |
|
3602 |
Timestamp nowWithMicroseconds |
|
3603 |
" |
|
3604 |
! |
|
3605 |
||
22940 | 3606 |
getMicroseconds |
3607 |
"strictly private: return the truncated microseconds (since the epoch) in utc" |
|
3608 |
||
3609 |
|millisAsMicros| |
|
3610 |
||
3611 |
millisAsMicros := osTime * 1000. |
|
3612 |
additionalPicoseconds notNil ifTrue:[ |
|
3613 |
^ millisAsMicros + (additionalPicoseconds // (1000 * 1000)). |
|
3614 |
]. |
|
3615 |
^ millisAsMicros |
|
3616 |
||
3617 |
"Created: 1.7.1996 / 14:33:56 / cg" |
|
3618 |
! |
|
3619 |
||
1501 | 3620 |
getMilliseconds |
22873 | 3621 |
"strictly private: return the truncated milliseconds (since the epoch) in utc" |
1501 | 3622 |
|
17006 | 3623 |
^ osTime |
1501 | 3624 |
|
3625 |
"Created: 1.7.1996 / 14:33:56 / cg" |
|
699 | 3626 |
! |
3627 |
||
3628 |
getSeconds |
|
22280 | 3629 |
"strictly private: return the (truncated) seconds (since the epoch) in utc" |
699 | 3630 |
|
17006 | 3631 |
^ osTime // 1000 |
22280 | 3632 |
|
3633 |
"Modified (comment): / 21-09-2017 / 18:50:23 / cg" |
|
699 | 3634 |
! |
3635 |
||
22873 | 3636 |
osTime:aTime |
3637 |
"set the internal representation of the time" |
|
3638 |
||
3639 |
osTime := aTime. |
|
3640 |
! |
|
3641 |
||
3642 |
setMicrosecond:aNumber |
|
3643 |
"change the sub-second fractional part only (leaves everything above seconds unchanged)" |
|
3644 |
||
3645 |
self |
|
23239 | 3646 |
setMilliseconds:(osTime // 1000) * 1000 "/ strip off any sub-second part |
22989 | 3647 |
additionalPicoseconds:(aNumber * 1000000) truncated. "/ set picos |
22873 | 3648 |
|
3649 |
" |
|
3650 |
Timestamp now setMicrosecond:15 - 15 microseconds after the current second's start |
|
3651 |
Timestamp now setMicrosecond:0.1 - 100 nanoseconds after the current second's start |
|
3652 |
" |
|
22989 | 3653 |
|
23239 | 3654 |
"Modified: / 27-07-2018 / 10:34:18 / Stefan Vogel" |
22873 | 3655 |
! |
3656 |
||
3657 |
setMillisecond:aNumber |
|
3658 |
"change the sub-second fractional part only (leaves everything above seconds unchanged)" |
|
3659 |
||
3660 |
self |
|
23239 | 3661 |
setMilliseconds:(osTime // 1000) * 1000 "/ strip off any sub-second part |
22989 | 3662 |
additionalPicoseconds:(aNumber * 1000000000) truncated. "/ set picos |
22873 | 3663 |
|
3664 |
" |
|
3665 |
Timestamp now setMillisecond:15 - 15 milliseconds after the current second's start |
|
3666 |
Timestamp now setMillisecond:0.05 - 50 microseconds after the current second's start |
|
3667 |
" |
|
22989 | 3668 |
|
23239 | 3669 |
"Modified: / 27-07-2018 / 10:34:42 / Stefan Vogel" |
22873 | 3670 |
! |
3671 |
||
1501 | 3672 |
setMilliseconds:millis |
16986 | 3673 |
"strictly private: set the milliseconds (since the epoch)" |
1501 | 3674 |
|
17006 | 3675 |
osTime := millis. |
1501 | 3676 |
|
3677 |
"Modified: 20.12.1995 / 11:46:36 / stefan" |
|
3678 |
"Created: 1.7.1996 / 14:34:24 / cg" |
|
3679 |
! |
|
3680 |
||
22873 | 3681 |
setMilliseconds:millis additionalPicoseconds:picos |
3682 |
"strictly private: set the milliseconds (since the epoch) and additional picos" |
|
3683 |
||
3684 |
|rest newMillis newPicos| |
|
3685 |
||
3686 |
millis isInteger ifTrue:[ |
|
3687 |
newMillis := millis. |
|
3688 |
newPicos := 0. |
|
3689 |
] ifFalse:[ |
|
3690 |
newMillis := millis truncated. |
|
3691 |
rest := millis - newMillis. |
|
22989 | 3692 |
newPicos := (rest * 1000000000) truncated. |
22873 | 3693 |
]. |
3694 |
||
3695 |
picos ~~ 0 ifTrue:[ |
|
3696 |
newPicos := newPicos + picos. |
|
22989 | 3697 |
newMillis := newMillis + (newPicos // 1000000000). |
3698 |
newPicos := (newPicos \\ 1000000000) truncated. |
|
22873 | 3699 |
]. |
3700 |
osTime := newMillis. |
|
3701 |
additionalPicoseconds := newPicos. |
|
22989 | 3702 |
|
3703 |
"Modified: / 22-05-2018 / 16:50:34 / Stefan Vogel" |
|
22873 | 3704 |
! |
3705 |
||
3706 |
setNanosecond:aNumber |
|
3707 |
"change the sub-second fractional part only (leaves everything above seconds unchanged)" |
|
3708 |
||
3709 |
self |
|
23239 | 3710 |
setMilliseconds:(osTime // 1000) * 1000 "/ strip off any sub-second part |
22873 | 3711 |
additionalPicoseconds:(aNumber * 1000) rounded. "/ set picos |
3712 |
||
3713 |
" |
|
3714 |
Timestamp now setNanosecond:15 - 15 nanoseconds after the current second's start |
|
3715 |
Timestamp now setNanosecond:0.1 - 10 picoseconds after the current second's start |
|
3716 |
" |
|
23239 | 3717 |
|
3718 |
"Modified: / 27-07-2018 / 10:34:52 / Stefan Vogel" |
|
22873 | 3719 |
! |
3720 |
||
699 | 3721 |
setSeconds:secs |
3722 |
"strictly private: set the seconds (since whatever)" |
|
3723 |
||
17006 | 3724 |
osTime := (secs * 1000). |
795 | 3725 |
|
3726 |
"Modified: 20.12.1995 / 11:46:36 / stefan" |
|
1501 | 3727 |
"Modified: 1.7.1996 / 14:34:10 / cg" |
5853 | 3728 |
! |
3729 |
||
16986 | 3730 |
timeInfo |
17006 | 3731 |
(osTime between:MinOSTime and:MaxOSTime) ifFalse:[ |
17067 | 3732 |
"/ fake an info which the OS cannot give me |
3733 |
^ self computeTimeInfo |
|
16986 | 3734 |
]. |
3735 |
||
3736 |
^ OperatingSystem computeTimeAndDateFrom:osTime |
|
17026 | 3737 |
|
3738 |
" |
|
17067 | 3739 |
(Timestamp year:1950 month:7 day:1 hour:12 minute:0 second:0) timeInfo |
3740 |
(UtcTimestamp year:1950 month:7 day:1 hour:12 minute:0 second:0) timeInfo |
|
17026 | 3741 |
" |
16986 | 3742 |
! |
3743 |
||
5853 | 3744 |
utcSecondsSince1970 |
3745 |
"return the UTC seconds since 1970" |
|
3746 |
||
9430
919e0cb2257c
Fix for utc botch when retrieving seconds since 1901
Stefan Vogel <sv@exept.de>
parents:
9416
diff
changeset
|
3747 |
^ self getSeconds |
5853 | 3748 |
|
3749 |
" |
|
8246 | 3750 |
Timestamp now utcSecondsSince1970 |
5853 | 3751 |
" |
17026 | 3752 |
! |
3753 |
||
3754 |
utcTimeInfo |
|
3755 |
(osTime between:MinOSTime and:MaxOSTime) ifFalse:[ |
|
17067 | 3756 |
"/ fake an info which the OS cannot give me |
3757 |
^ self computeUtcTimeInfo |
|
17026 | 3758 |
]. |
3759 |
||
3760 |
^ OperatingSystem computeUTCTimeAndDateFrom:osTime |
|
3761 |
||
3762 |
" |
|
17067 | 3763 |
(Timestamp year:1950 month:7 day:1 hour:12 minute:0 second:0) timeInfo |
3764 |
(Timestamp year:1950 month:7 day:1 hour:12 minute:0 second:0) utcTimeInfo |
|
17026 | 3765 |
" |
699 | 3766 |
! ! |
3767 |
||
22914 | 3768 |
!Timestamp methodsFor:'queries'! |
3769 |
||
3770 |
speciesForCompare |
|
3771 |
"all of my subclass instances can be compared, |
|
3772 |
because they all hold the UTC time internally" |
|
3773 |
||
3774 |
^ Timestamp |
|
3775 |
! ! |
|
3776 |
||
3777 |
||
3778 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3779 |
!Timestamp methodsFor:'testing'! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3780 |
|
16967 | 3781 |
isLocalTimestamp |
23003 | 3782 |
"return true, if I am a local timestamp (i.e. with no TZ info)" |
16986 | 3783 |
|
16967 | 3784 |
^ true |
23003 | 3785 |
|
3786 |
"Modified (comment): / 24-05-2018 / 17:29:32 / Claus Gittinger" |
|
3787 |
! |
|
3788 |
||
3789 |
isTZTimestamp |
|
3790 |
"return true, if I am a timestamp with TZ info" |
|
3791 |
||
3792 |
^ false |
|
3793 |
||
3794 |
"Created: / 24-05-2018 / 17:30:25 / Claus Gittinger" |
|
16967 | 3795 |
! |
3796 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3797 |
isTimestamp |
16986 | 3798 |
"return true, if I am a timestamp" |
3799 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3800 |
^ true |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3801 |
! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3802 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3803 |
isUtcTimestamp |
16986 | 3804 |
"return true, if I am a utc timestamp" |
3805 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3806 |
^ false |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3807 |
! ! |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3808 |
|
8396
b13503dbc53c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8286
diff
changeset
|
3809 |
!Timestamp methodsFor:'visiting'! |
b13503dbc53c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8286
diff
changeset
|
3810 |
|
b13503dbc53c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8286
diff
changeset
|
3811 |
acceptVisitor:aVisitor with:aParameter |
16718 | 3812 |
"dispatch for visitor pattern; send #visitTimestamp:with: to aVisitor." |
3813 |
||
8396
b13503dbc53c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8286
diff
changeset
|
3814 |
^ aVisitor visitTimestamp:self with:aParameter |
b13503dbc53c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8286
diff
changeset
|
3815 |
! ! |
b13503dbc53c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8286
diff
changeset
|
3816 |
|
22873 | 3817 |
!Timestamp::TimestampBuilderAbstract class methodsFor:'documentation'! |
3818 |
||
3819 |
documentation |
|
3820 |
" |
|
3821 |
documentation to be added. |
|
3822 |
||
3823 |
[author:] |
|
3824 |
cg |
|
3825 |
||
3826 |
[instance variables:] |
|
3827 |
||
3828 |
[class variables:] |
|
3829 |
||
3830 |
[see also:] |
|
3831 |
||
3832 |
" |
|
3833 |
! |
|
3834 |
||
3835 |
examples |
|
3836 |
" |
|
3837 |
||
3838 |
more examples to be added: |
|
3839 |
[exBegin] |
|
3840 |
... add code fragment for |
|
3841 |
... executable example here ... |
|
3842 |
[exEnd] |
|
3843 |
" |
|
3844 |
! ! |
|
3845 |
||
11993 | 3846 |
!Timestamp::TimestampBuilderAbstract methodsFor:'error reporting'! |
3847 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3848 |
malformed:aString |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3849 |
TimeConversionError raiseErrorString:(' - ', aString) |
11993 | 3850 |
|
3851 |
"Created: / 15-06-2005 / 15:54:04 / masca" |
|
3852 |
! ! |
|
3853 |
||
3854 |
!Timestamp::TimestampBuilderAbstract methodsFor:'support'! |
|
3855 |
||
3856 |
addHoursAndMinutes: arrayWithHoursAndMinutes |
|
3857 |
"Add the given number of hours and minutes to the current timestamp state. If the time |
|
3858 |
is to be subtracted, both numbers in the array must be negated. When the are not the same |
|
3859 |
sign, the behavior may be strange. It's intended only for time zone corrections, where |
|
16977 | 3860 |
not more than 14 (in fact, 23) hours is added or subtracted (ie. date can be modified only |
11993 | 3861 |
one day forward or backward)." |
3862 |
||
3863 |
| hours minutes | |
|
16975 | 3864 |
|
11993 | 3865 |
hours := arrayWithHoursAndMinutes first. |
3866 |
minutes := arrayWithHoursAndMinutes second. |
|
3867 |
||
16975 | 3868 |
utcOffset := (((hours * 60) + minutes) * 60). |
3869 |
||
11993 | 3870 |
minutes isZero ifFalse: [ |
19915 | 3871 |
minute := minute + minutes. |
3872 |
minute >= 60 ifTrue: [ |
|
3873 |
hours := hours + 1. |
|
3874 |
minute := minute - 60. |
|
3875 |
]. |
|
3876 |
minute < 0 ifTrue: [ |
|
3877 |
hours := hours - 1. |
|
3878 |
minute := minute + 60. |
|
3879 |
] |
|
11993 | 3880 |
]. |
3881 |
||
3882 |
"Hours may get zero by time zone specification or by minutes modifications above." |
|
3883 |
hours isZero ifTrue: [^self]. |
|
3884 |
||
3885 |
"Add or subtract the hour and make date corrections if necessary." |
|
3886 |
hour := hour + hours. |
|
3887 |
hour < 0 ifTrue: [ |
|
19915 | 3888 |
"Oops, got to previous day, must adjust even the date." |
3889 |
hour := 24 - ((hour negated) \\ 24). |
|
3890 |
day := day - 1. |
|
3891 |
day <= 0 ifTrue: [ |
|
3892 |
"Go to previous month..." |
|
3893 |
month := month - 1. |
|
3894 |
month <= 0 ifTrue: [year := year - 1. month := 12]. |
|
3895 |
day := self lastDayInMonth: month |
|
3896 |
] |
|
11993 | 3897 |
]. |
3898 |
hour >= 24 ifTrue: [ |
|
19915 | 3899 |
hour := hour \\ 24. |
3900 |
day := day + 1. |
|
3901 |
day > (self lastDayInMonth: month) ifTrue: [ |
|
3902 |
month := month + 1. |
|
3903 |
month > 12 ifTrue: [year := year + 1. month := 1]. |
|
3904 |
day := 1 |
|
3905 |
] |
|
11993 | 3906 |
] |
3907 |
||
3908 |
"Created: / 15-06-2005 / 16:45:49 / masca" |
|
3909 |
"Modified: / 16-06-2005 / 15:04:45 / masca" |
|
3910 |
! |
|
3911 |
||
16836 | 3912 |
dateFromDayNumber: dayInYear |
11993 | 3913 |
"Set month and day from an absolute number of the day in the year. 1.1. is day number one." |
3914 |
||
16836 | 3915 |
|monthAndDay| |
3916 |
||
3917 |
(dayInYear between: 1 and: 365) ifFalse: [ |
|
17006 | 3918 |
(dayInYear = 366 and:[self leapYear: year]) |
3919 |
ifFalse: [self malformed: 'Bad day number: ' , dayInYear printString] |
|
11993 | 3920 |
]. |
3921 |
||
16836 | 3922 |
monthAndDay := Date monthAndDayFromDayInYear:dayInYear forYear:year. |
3923 |
month := monthAndDay at:1. |
|
3924 |
day := monthAndDay at:2 |
|
11993 | 3925 |
|
3926 |
"Created: / 15-06-2005 / 11:27:35 / masca" |
|
3927 |
"Modified: / 16-06-2005 / 12:31:37 / masca" |
|
3928 |
! |
|
3929 |
||
3930 |
dateFromWeek: weekInteger andWeekday: dayInteger |
|
3931 |
"Compute the month and day. Find the first day (weekday) in the year, maybe even |
|
3932 |
adjust the year. Both week and day are 1-based, the first week in a year is the one |
|
3933 |
with thursday (or the one containing 4.1.)." |
|
3934 |
||
16914 | 3935 |
|tmpDate| |
3936 |
||
11993 | 3937 |
"Check numbers. Year may be checked if it contains 53 weeks or 52 weeks only." |
3938 |
(dayInteger between: 1 and: 7) ifFalse: [self malformed: 'Bad weekday number: ' , dayInteger printString]. |
|
3939 |
(weekInteger between: 1 and: 53) ifFalse: [self malformed: 'Bad week number: ' , weekInteger printString]. |
|
3940 |
||
16914 | 3941 |
tmpDate := Date newDayInWeek:dayInteger week:weekInteger year:year. |
3942 |
day := tmpDate day. |
|
3943 |
month := tmpDate month. |
|
3944 |
year := tmpDate year. |
|
11993 | 3945 |
! |
3946 |
||
3947 |
isAllowedDay: anInteger |
|
3948 |
"Answer whether the given day is allowed in the current month." |
|
3949 |
||
3950 |
^anInteger between: 1 and: (self lastDayInMonth: month) |
|
3951 |
||
3952 |
"Created: / 15-06-2005 / 16:22:51 / masca" |
|
3953 |
! |
|
3954 |
||
3955 |
lastDayInMonth: anInteger |
|
3956 |
"Answer the number of the last day of the given month in the current year." |
|
3957 |
||
16836 | 3958 |
^ anInteger = 2 |
17006 | 3959 |
ifTrue: [(self leapYear: year) ifTrue: [29] ifFalse: [28]] |
3960 |
ifFalse: [#(31 28 31 30 31 30 31 31 30 31 30 31) at: month] |
|
11993 | 3961 |
|
3962 |
"Created: / 15-06-2005 / 17:12:31 / masca" |
|
3963 |
! |
|
3964 |
||
16836 | 3965 |
leapYear: anInteger |
3966 |
^ Date leapYear:anInteger. |
|
3967 |
! |
|
3968 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
3969 |
timestampWithClass:timestampClass |
11993 | 3970 |
"Answer the timestamp as it has been parsed." |
3971 |
"Notes: |
|
17016 | 3972 |
- When reading, the time has either been adjusted to UTZ/zulu or explicit offset time, |
3973 |
or is a local time stamp. |
|
3974 |
Attention: an explicit utcOffset in the input string has already been added into the hh:mm values." |
|
11993 | 3975 |
|
16975 | 3976 |
(timestampClass == UtcTimestamp) ifTrue:[ |
22873 | 3977 |
^ UtcTimestamp |
3978 |
UTCYear:year month:month day:day |
|
3979 |
hour:hour minute:minute second:second millisecond:millisecond additionalPicoseconds:picos |
|
16975 | 3980 |
]. |
3981 |
(timestampClass == TZTimestamp) ifTrue:[ |
|
22873 | 3982 |
"/ Attention: an explicit utcOffset in the input string has already been added into the hh:mm values." |
3983 |
^ ((TZTimestamp |
|
3984 |
UTCYear:year month:month day:day |
|
3985 |
hour:hour minute:minute second:second millisecond:millisecond additionalPicoseconds:picos |
|
3986 |
) utcOffset:utcOffset) |
|
16975 | 3987 |
]. |
3988 |
||
16989 | 3989 |
(isUtcTime or:[hasTimezone and:[utcOffset == 0]]) ifTrue:[ |
22873 | 3990 |
^ ((timestampClass == Timestamp) ifTrue:UtcTimestamp ifFalse:timestampClass) |
3991 |
UTCYear:year month:month day:day |
|
3992 |
hour:hour minute:minute second:second millisecond:millisecond additionalPicoseconds:picos |
|
17016 | 3993 |
]. |
3994 |
hasTimezone ifTrue:[ |
|
22873 | 3995 |
"/ Attention: an explicit utcOffset in the input string has already been added into the hh:mm values." |
3996 |
^ (((timestampClass == Timestamp) ifTrue:TZTimestamp ifFalse:timestampClass) |
|
3997 |
UTCYear:year month:month day:day |
|
3998 |
hour:hour minute:minute second:second millisecond:millisecond additionalPicoseconds:picos |
|
3999 |
) utcOffset:utcOffset |
|
17016 | 4000 |
]. |
17067 | 4001 |
"/ there was no timezone info, so make it a local timestamp again. |
22873 | 4002 |
^ timestampClass |
4003 |
year:year month:month day:day |
|
4004 |
hour:hour minute:minute second:second millisecond:millisecond additionalPicoseconds:picos |
|
16914 | 4005 |
! |
4006 |
||
4007 |
yearAlreadyReadAs:yearArg |
|
4008 |
"support for readers which may have already preread the year" |
|
4009 |
||
4010 |
year := yearArg. |
|
4011 |
yearAlreadyRead := true. |
|
11993 | 4012 |
! ! |
4013 |
||
4014 |
!Timestamp::TimestampISO8601Builder class methodsFor:'documentation'! |
|
4015 |
||
4016 |
documentation |
|
4017 |
" |
|
16945 | 4018 |
TimestampISO8601Builder is designed to read any (almost) format of ISO 8601 encoded timestamp. |
4019 |
Also, class methods can be used to print but the main reading job is done in instance protocol. |
|
16915 | 4020 |
It has been written because of insufficient abilities of Timestamp #readIso8601FormatFrom: method |
4021 |
(which was now changed to call this as well). |
|
4022 |
||
4023 |
It produces timestamps, i.e. when the string (or stream) contains only a time, an error will result |
|
11993 | 4024 |
(it may also pass in some cases but with the time undestood as date). It survives incomplete dates, |
4025 |
broken years, incomplete times and timezones. All times read with timezone difference are recomputed |
|
4026 |
to UTC before the timestamp is created (even passing across new year boundary is handled correctly). |
|
4027 |
Unknown offsets (usually local) are considered UTC - this may be wrong and more work is probably needed. |
|
4028 |
All data is checked for validity (including leap years, leap seconds,...) during reading and as soon as |
|
16945 | 4029 |
possible. |
16915 | 4030 |
For an example of what the builder can read, see the examples method and ISO 8601 itself. |
11993 | 4031 |
|
4032 |
[author:] |
|
17006 | 4033 |
Martin Dvorak (masca@volny.cz) |
11993 | 4034 |
|
4035 |
[instance variables:] |
|
17006 | 4036 |
stream A stream the builder operates on. Assigned on each call to instance method #read:, |
4037 |
so the builder instance can be reused (by at most one thread). |
|
4038 |
year Current timestamp year. No default value, date must be present. |
|
4039 |
month Current timestamp month. May change during parsing. Defaults to 1. |
|
4040 |
day Current timestamp day. Defaults to 1. |
|
4041 |
hour Current timestamp hour. Defaults to 0. |
|
4042 |
minute Current timestamp minute. Defaults to 0. |
|
4043 |
second Current timestamp second. Defaults to 0. |
|
4044 |
millisecond Current timestamp millisecond. Defaults to 0. |
|
11993 | 4045 |
|
4046 |
[see also:] |
|
17006 | 4047 |
Timestamp |
11993 | 4048 |
" |
4049 |
! |
|
4050 |
||
4051 |
examples |
|
4052 |
" |
|
21999 | 4053 |
See the unit tests in stx/goodies:regression >> RegressionTests::timeAndDateTest |
11993 | 4054 |
It covers the main features this builder has. |
4055 |
||
4056 |
Just to introduce some coding examples, try: |
|
21999 | 4057 |
Timestamp readISO8601From: (TimestampISO8601Builder print: Timestamp now). |
4058 |
UtcTimestamp readISO8601From: (TimestampISO8601Builder print: UtcTimestamp now). |
|
4059 |
Timestamp readISO8601From: (TimestampISO8601Builder print: UtcTimestamp now). |
|
4060 |
Timestamp readISO8601From: (TimestampISO8601Builder print: TZTimestamp now). |
|
16945 | 4061 |
|
4062 |
Timestamp readISO8601From:'fooBar' onError:[ Timestamp now ]. |
|
11993 | 4063 |
" |
4064 |
! |
|
4065 |
||
4066 |
history |
|
4067 |
"Created: / 16-06-2005 / 16:28:38 / masca" |
|
4068 |
! ! |
|
4069 |
||
4070 |
!Timestamp::TimestampISO8601Builder class methodsFor:'printing'! |
|
4071 |
||
4072 |
print: aTimestamp |
|
16919 | 4073 |
"Returns the printString of the given timestamp in general ISO8601 format, |
4074 |
such as '2014-11-06T11:48:09Z'. |
|
4075 |
The time is printed as UTC time" |
|
11993 | 4076 |
|
4077 |
| stream | |
|
16919 | 4078 |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4079 |
stream := '' writeStream. |
11993 | 4080 |
self print: aTimestamp on: stream. |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4081 |
^ stream contents |
11993 | 4082 |
|
16919 | 4083 |
" |
4084 |
self print:(Timestamp now) |
|
4085 |
" |
|
4086 |
||
11993 | 4087 |
"Created: / 15-06-2005 / 17:52:29 / masca" |
4088 |
! |
|
4089 |
||
16921 | 4090 |
print:aTimestamp asLocal:asLocal on:aStream |
16919 | 4091 |
"Print the given timestamp in general ISO8601 format, |
4092 |
such as '2014-11-06T11:48:09Z'. |
|
4093 |
The time is always printed as UTC time" |
|
11993 | 4094 |
|
16967 | 4095 |
self print:aTimestamp compact:false asLocal:asLocal asUTC:asLocal not withMilliseconds:true on:aStream |
16919 | 4096 |
|
4097 |
" |
|
4098 |
self print:(Timestamp now) on:Transcript |
|
4099 |
" |
|
11993 | 4100 |
|
4101 |
"Created: / 15-06-2005 / 17:56:51 / masca" |
|
4102 |
! |
|
4103 |
||
16919 | 4104 |
print:aTimestamp on:aStream |
4105 |
"Print the given timestamp in general ISO8601 format, |
|
4106 |
such as '2014-11-06T11:48:09Z'. |
|
4107 |
The time is printed as UTC time" |
|
4108 |
||
22834 | 4109 |
self |
4110 |
print:aTimestamp |
|
4111 |
compact:false asLocal:false asUTC:true |
|
4112 |
withMilliseconds:true timeSeparator:$T timeOnly:false |
|
4113 |
on:aStream |
|
16919 | 4114 |
|
4115 |
" |
|
22834 | 4116 |
self print:(Timestamp now) on:Transcript. |
4117 |
Transcript cr. |
|
4118 |
self print:(Time now) on:Transcript. |
|
4119 |
Transcript cr. |
|
4120 |
self print:(Time nowWithMilliseconds) on:Transcript. |
|
4121 |
Transcript cr. |
|
16919 | 4122 |
" |
4123 |
||
4124 |
"Created: / 15-06-2005 / 17:56:51 / masca" |
|
4125 |
! |
|
4126 |
||
4127 |
printAsLocalTime: aTimestamp on: aStream |
|
4128 |
"Print the given timestamp in general ISO8601 format, |
|
16955 | 4129 |
such as '2014-11-06T11:48:09+01'. |
16919 | 4130 |
The time is printed as local time" |
4131 |
||
22834 | 4132 |
self |
4133 |
print:aTimestamp compact:false asLocal:true asUTC:false |
|
4134 |
withMilliseconds:true timeSeparator:$T timeOnly:false |
|
4135 |
on:aStream |
|
16919 | 4136 |
|
4137 |
" |
|
17006 | 4138 |
self printAsLocalTime:(Timestamp now) on:Transcript |
16919 | 4139 |
" |
4140 |
! |
|
4141 |
||
11993 | 4142 |
printCompressed: aTimestamp |
16919 | 4143 |
"Return a printString in compressed format such as '20141106T114636Z'. |
4144 |
(for example, for timestamp interchange with mobile devices). |
|
4145 |
The time is printed as UTC time" |
|
11993 | 4146 |
|
4147 |
| stream | |
|
16919 | 4148 |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4149 |
stream := '' writeStream. |
11993 | 4150 |
self printCompressed: aTimestamp on: stream. |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4151 |
^ stream contents |
11993 | 4152 |
|
16919 | 4153 |
" |
4154 |
self printCompressed:(Timestamp now) |
|
4155 |
" |
|
4156 |
||
11993 | 4157 |
"Created: / 15-06-2005 / 17:52:52 / masca" |
4158 |
! |
|
4159 |
||
22834 | 4160 |
printCompressed:aTimestamp asLocal:asLocal on:aStream |
4161 |
"generates a compressed string representation, |
|
4162 |
(optionally as localtime) such as '20141106T114636Z'" |
|
4163 |
||
4164 |
self |
|
4165 |
print:aTimestamp |
|
4166 |
compact:true asLocal:asLocal asUTC:asLocal not |
|
4167 |
withMilliseconds:true timeSeparator:$T timeOnly:false |
|
4168 |
on:aStream |
|
4169 |
||
4170 |
" |
|
4171 |
self printCompressed:(Timestamp now) on:Transcript |
|
4172 |
" |
|
4173 |
||
4174 |
"Created: / 15-06-2005 / 17:54:17 / masca" |
|
4175 |
! |
|
4176 |
||
4177 |
printCompressed:aTimestamp on:aStream |
|
4178 |
"generates a compressed string representation, such as '20141106T114636Z'. |
|
4179 |
The time is printed as UTC time" |
|
4180 |
||
4181 |
self |
|
4182 |
print:aTimestamp |
|
4183 |
compact:true asLocal:false asUTC:true |
|
4184 |
withMilliseconds:true timeSeparator:$T timeOnly:false |
|
4185 |
on:aStream |
|
16919 | 4186 |
|
4187 |
" |
|
4188 |
self printCompressed:(Timestamp now) on:Transcript |
|
4189 |
" |
|
4190 |
||
4191 |
"Created: / 15-06-2005 / 17:54:17 / masca" |
|
4192 |
! |
|
4193 |
||
22834 | 4194 |
printCompressedAsLocalTime:aTimestamp on:aStream |
16919 | 4195 |
"generates a compressed string representation, such as '20141106T114636Z'. |
22834 | 4196 |
The time is printed as local time" |
4197 |
||
4198 |
self |
|
4199 |
print:aTimestamp |
|
4200 |
compact:true asLocal:true asUTC:false |
|
4201 |
withMilliseconds:true timeSeparator:$T timeOnly:false |
|
4202 |
on:aStream |
|
16919 | 4203 |
|
4204 |
" |
|
4205 |
self printCompressed:(Timestamp now) on:Transcript |
|
4206 |
" |
|
4207 |
||
4208 |
"Created: / 15-06-2005 / 17:54:17 / masca" |
|
4209 |
! |
|
4210 |
||
22834 | 4211 |
printTime:aTimeOrTimestamp on:aStream |
4212 |
"Print the given time in general ISO8601 format, |
|
4213 |
such as 'T11:48:09Z'. |
|
4214 |
The time is printed as UTC time. |
|
4215 |
No date is printed." |
|
4216 |
||
4217 |
self |
|
4218 |
print:aTimeOrTimestamp |
|
4219 |
compact:false asLocal:false asUTC:true |
|
4220 |
withMilliseconds:true timeSeparator:$T timeOnly:true |
|
4221 |
on:aStream |
|
16919 | 4222 |
|
4223 |
" |
|
22834 | 4224 |
self print:(Time nowWithMilliseconds) on:Transcript. |
4225 |
Transcript cr. |
|
4226 |
self printTime:(Time nowWithMilliseconds) on:Transcript. |
|
4227 |
Transcript cr. |
|
16919 | 4228 |
" |
11993 | 4229 |
|
22834 | 4230 |
"Created: / 15-06-2005 / 17:56:51 / masca" |
16919 | 4231 |
! |
4232 |
||
16967 | 4233 |
printTimeZone:tzOffsetArg on: aStream |
16919 | 4234 |
"Print the timezone delta" |
4235 |
||
4236 |
|tzOffset tzHours tzMinutes| |
|
4237 |
||
16967 | 4238 |
tzOffset := tzOffsetArg. |
17020 | 4239 |
tzOffset == 0 ifTrue:[ |
17067 | 4240 |
aStream nextPutAll:'+00'. |
17020 | 4241 |
] ifFalse:[ |
17067 | 4242 |
tzOffset := tzOffset // 60. "/ convert from seconds to minutes |
4243 |
tzOffset < 0 ifTrue:[ |
|
4244 |
tzOffset := tzOffset negated. |
|
4245 |
aStream nextPut:$+ |
|
4246 |
] ifFalse:[ |
|
4247 |
aStream nextPut:$-. |
|
4248 |
]. |
|
4249 |
||
4250 |
tzHours := tzOffset // 60. |
|
4251 |
tzMinutes := tzOffset \\ 60. |
|
4252 |
(tzHours ~= 0 or:[tzMinutes ~= 0]) ifTrue:[ |
|
4253 |
aStream |
|
4254 |
nextPutAll:(tzHours printStringRadix: 10 size: 2 fill: $0). |
|
4255 |
tzMinutes ~= 0 ifTrue:[ |
|
4256 |
aStream |
|
4257 |
nextPut: $:; |
|
4258 |
nextPutAll: (tzMinutes printStringRadix: 10 size: 2 fill: $0). |
|
4259 |
]. |
|
4260 |
]. |
|
16919 | 4261 |
]. |
4262 |
||
4263 |
" |
|
4264 |
self print:(Timestamp now) asLocal:true on:Transcript. |
|
4265 |
Transcript cr. |
|
4266 |
||
4267 |
self print:(Timestamp now) asLocal:false on:Transcript. |
|
4268 |
Transcript cr. |
|
4269 |
||
4270 |
self printCompressed:(Timestamp now) asLocal:true on:Transcript. |
|
4271 |
Transcript cr. |
|
4272 |
||
4273 |
self printCompressed:(Timestamp now) asLocal:false on:Transcript. |
|
16945 | 4274 |
Transcript cr. |
16919 | 4275 |
" |
11993 | 4276 |
! ! |
4277 |
||
16921 | 4278 |
!Timestamp::TimestampISO8601Builder class methodsFor:'printing - basic'! |
4279 |
||
22926 | 4280 |
print:aTimeOrTimestamp compact:compact asLocal:asLocal asUTC:asUTC |
4281 |
subSecondDigits:numDigits |
|
4282 |
suppressZeroSubSecondDigits:suppressZeroSubSecondDigits |
|
4283 |
timeSeparator:tSep timeOnly:timeOnly on:aStream |
|
4284 |
||
4285 |
"Print the given timestamp in general ISO8601 format, |
|
4286 |
such as '2014-11-06T11:48:09Z'. |
|
4287 |
compact: if true, the compact format (without separating dashes and colons is generated) |
|
4288 |
asLocal: if true, generates a localtime string (without any timezone info) |
|
4289 |
asUTC: if true, generates a utc string |
|
4290 |
if both are false: |
|
4291 |
generate a string depending on the type of timestamp: |
|
4292 |
if local: generate a local timezone string |
|
4293 |
if utc: generate a utc string |
|
4294 |
otherwise it is a timestamp from another timezone (TZTimestamp), then print in its timezone |
|
4295 |
numDigits: nr of post-second fractional part (i.e. 3 for millis, 6 for micros, 0 for none, #variable for as-required); |
|
4296 |
suppressZeroSubSecondDigits: to suppress zeros (i.e. the old behavior). |
|
4297 |
if timeOnly is true, only the time is printed." |
|
4298 |
||
4299 |
|aTimestamp timeInfo picos picosString | |
|
4300 |
||
4301 |
aTimestamp := aTimeOrTimestamp asTimestamp. |
|
4302 |
||
4303 |
asLocal ifTrue:[ |
|
4304 |
"/ force local |
|
4305 |
timeInfo := aTimestamp asLocalTimestamp timeInfo. |
|
4306 |
] ifFalse:[ |
|
4307 |
asUTC ifTrue:[ |
|
4308 |
"/ force utc |
|
4309 |
timeInfo := aTimestamp asUtcTimestamp timeInfo. |
|
4310 |
] ifFalse:[ |
|
4311 |
"/ in the timestamps own format |
|
4312 |
timeInfo := aTimestamp timeInfo. |
|
4313 |
] |
|
4314 |
]. |
|
4315 |
||
4316 |
timeOnly ifFalse:[ |
|
4317 |
timeInfo year printOn:aStream leftPaddedTo:4 with:$0. |
|
4318 |
compact ifFalse:[ aStream nextPut: $- ]. |
|
4319 |
timeInfo month printOn:aStream leftPaddedTo:2 with:$0. |
|
4320 |
compact ifFalse:[ aStream nextPut: $- ]. |
|
4321 |
timeInfo day printOn:aStream leftPaddedTo:2 with:$0. |
|
23028 | 4322 |
aStream nextPut:tSep. |
22926 | 4323 |
]. |
4324 |
timeInfo hours printOn:aStream leftPaddedTo:2 with:$0. |
|
4325 |
compact ifFalse:[ aStream nextPut: $:]. |
|
4326 |
timeInfo minutes printOn:aStream leftPaddedTo:2 with:$0. |
|
4327 |
||
4328 |
"always print the seconds, even if 0. |
|
4329 |
According to http://www.w3.org/TR/xmlschema11-2/#dateTime this is mandatory" |
|
4330 |
||
4331 |
compact ifFalse:[ aStream nextPut: $:]. |
|
4332 |
timeInfo seconds printOn:aStream leftPaddedTo:2 with:$0. |
|
4333 |
||
22946 | 4334 |
(numDigits == 3 and:[suppressZeroSubSecondDigits not]) ifTrue:[ |
22926 | 4335 |
"/ special case, because it is so common |
4336 |
aStream nextPut: $.. |
|
4337 |
aTimestamp milliseconds printOn:aStream leftPaddedTo:3 with:$0. |
|
4338 |
] ifFalse:[ |
|
4339 |
numDigits ~~ 0 ifTrue:[ |
|
4340 |
picos := aTimestamp picoseconds. |
|
4341 |
(suppressZeroSubSecondDigits and:[picos = 0]) ifFalse:[ |
|
4342 |
"/ not suppressed |
|
4343 |
picosString := picos printStringLeftPaddedTo:12 with:$0. |
|
4344 |
numDigits == #variable ifTrue:[ |
|
4345 |
picosString := picosString withoutTrailing:$0. |
|
4346 |
] ifFalse:[ |
|
4347 |
numDigits > 12 ifTrue:[ |
|
4348 |
picosString := picosString paddedTo:numDigits with:$0 |
|
4349 |
] ifFalse:[ |
|
4350 |
picosString := picosString copyTo:numDigits. |
|
4351 |
]. |
|
4352 |
]. |
|
4353 |
aStream nextPut: $.. |
|
4354 |
aStream nextPutAll:picosString. |
|
4355 |
] |
|
4356 |
]. |
|
4357 |
]. |
|
4358 |
||
4359 |
asUTC ifTrue:[ |
|
4360 |
aStream nextPut: $Z |
|
4361 |
] ifFalse:[ |
|
4362 |
asLocal ifFalse:[ |
|
4363 |
self printTimeZone:aTimestamp utcOffset on:aStream. |
|
4364 |
]. |
|
4365 |
]. |
|
4366 |
||
4367 |
" |
|
4368 |
Transcript cr. self |
|
4369 |
print:(Timestamp nowWithMicroseconds) |
|
4370 |
compact:false asLocal:false asUTC:true |
|
4371 |
subSecondDigits:3 |
|
4372 |
suppressZeroSubSecondDigits:false |
|
4373 |
timeSeparator:$T timeOnly:false on:Transcript |
|
4374 |
||
4375 |
Transcript cr. self |
|
4376 |
print:(Timestamp nowWithMicroseconds) |
|
4377 |
compact:false asLocal:false asUTC:true |
|
4378 |
subSecondDigits:6 |
|
4379 |
suppressZeroSubSecondDigits:false |
|
4380 |
timeSeparator:$T timeOnly:false on:Transcript |
|
4381 |
||
4382 |
Transcript cr. self |
|
4383 |
print:(Timestamp nowWithMicroseconds) |
|
4384 |
compact:false asLocal:false asUTC:true |
|
4385 |
subSecondDigits:#variable |
|
4386 |
suppressZeroSubSecondDigits:false |
|
4387 |
timeSeparator:$T timeOnly:false on:Transcript |
|
4388 |
||
4389 |
Transcript cr. self |
|
4390 |
print:(Timestamp now) |
|
4391 |
compact:false asLocal:false asUTC:true |
|
4392 |
subSecondDigits:#variable |
|
4393 |
suppressZeroSubSecondDigits:false |
|
4394 |
timeSeparator:$T timeOnly:false on:Transcript |
|
4395 |
||
4396 |
Transcript cr. self |
|
4397 |
print:(Timestamp now) |
|
4398 |
compact:false asLocal:false asUTC:true |
|
4399 |
subSecondDigits:1 |
|
4400 |
suppressZeroSubSecondDigits:false |
|
4401 |
timeSeparator:$T timeOnly:false on:Transcript |
|
4402 |
||
4403 |
Transcript cr. self |
|
4404 |
print:(Timestamp now) |
|
4405 |
compact:false asLocal:false asUTC:true |
|
4406 |
subSecondDigits:0 |
|
4407 |
suppressZeroSubSecondDigits:false |
|
4408 |
timeSeparator:$T timeOnly:false on:Transcript |
|
4409 |
" |
|
4410 |
||
4411 |
"Created: / 15-06-2005 / 17:56:51 / masca" |
|
23028 | 4412 |
"Modified: / 26-05-2018 / 13:43:00 / Claus Gittinger" |
22926 | 4413 |
! |
4414 |
||
16967 | 4415 |
print: aTimestamp compact:compact asLocal:asLocal asUTC:asUTC withMilliseconds:withMillis on: aStream |
16921 | 4416 |
"Print the given timestamp in general ISO8601 format, |
4417 |
such as '2014-11-06T11:48:09Z'. |
|
23028 | 4418 |
compact: if true, the compact format (without separating dashes and colons is generated) |
4419 |
asLocal: if true, generates a localtime string (with the machine's current timezone setting) |
|
4420 |
asUTC: if true, generates a utc string |
|
4421 |
if both are false: |
|
4422 |
generate a string depending on the type of timestamp: |
|
4423 |
if local: generate a local timezone string |
|
4424 |
if utc: generate a utc string |
|
4425 |
otherwise it is a timestamp from another timezone (TZTimestamp), then print in its timezone |
|
4426 |
withMilliseconds: if false, no milliseconds are generated" |
|
17006 | 4427 |
|
4428 |
self |
|
23028 | 4429 |
print:aTimestamp |
4430 |
compact:compact asLocal:asLocal asUTC:asUTC |
|
4431 |
withMilliseconds:withMillis |
|
4432 |
timeSeparator:$T timeOnly:false |
|
4433 |
on:aStream |
|
16975 | 4434 |
|
4435 |
" |
|
4436 |
self print:(Timestamp now) on:Transcript |
|
4437 |
self printAsLocalTime:(Timestamp now) on:Transcript |
|
4438 |
self printAsLocalTime:(Timestamp now asTZTimestamp:-7200) on:Transcript |
|
4439 |
" |
|
23028 | 4440 |
|
4441 |
"Modified: / 26-05-2018 / 13:43:39 / Claus Gittinger" |
|
16975 | 4442 |
! |
4443 |
||
4444 |
print:aTimestamp compact:compact asLocal:asLocal asUTC:asUTC withMilliseconds:withMillis timeSeparator:tSep on:aStream |
|
4445 |
"Print the given timestamp in general ISO8601 format, |
|
4446 |
such as '2014-11-06T11:48:09Z'. |
|
17422
0a01cd7cf5f2
class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents:
17172
diff
changeset
|
4447 |
compact: if true, the compact format (without separating dashes and colons is generated) |
0a01cd7cf5f2
class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents:
17172
diff
changeset
|
4448 |
asLocal: if true, generates a localtime string (without any timezone info) |
0a01cd7cf5f2
class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents:
17172
diff
changeset
|
4449 |
asUTC: if true, generates a utc string |
0a01cd7cf5f2
class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents:
17172
diff
changeset
|
4450 |
if both are false: |
0a01cd7cf5f2
class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents:
17172
diff
changeset
|
4451 |
generate a string depending on the type of timestamp: |
0a01cd7cf5f2
class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents:
17172
diff
changeset
|
4452 |
if local: generate a local timezone string |
0a01cd7cf5f2
class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents:
17172
diff
changeset
|
4453 |
if utc: generate a utc string |
0a01cd7cf5f2
class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents:
17172
diff
changeset
|
4454 |
otherwise it is a timestamp from another timezone (TZTimestamp), then print in its timezone |
0a01cd7cf5f2
class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents:
17172
diff
changeset
|
4455 |
withMilliseconds: if false, no milliseconds are generated" |
0a01cd7cf5f2
class: Timestamp::TimestampISO8601Builder
Stefan Vogel <sv@exept.de>
parents:
17172
diff
changeset
|
4456 |
|
22834 | 4457 |
self |
4458 |
print:aTimestamp |
|
4459 |
compact:compact asLocal:asLocal asUTC:asUTC |
|
4460 |
withMilliseconds:withMillis timeSeparator:tSep timeOnly:false |
|
4461 |
on:aStream |
|
4462 |
||
4463 |
" |
|
4464 |
self print:(Timestamp now) on:Transcript |
|
4465 |
self printAsLocalTime:(Timestamp now) on:Transcript |
|
4466 |
self printAsLocalTime:(Timestamp now asTZTimestamp:-7200) on:Transcript |
|
4467 |
" |
|
4468 |
||
4469 |
"Created: / 15-06-2005 / 17:56:51 / masca" |
|
4470 |
! |
|
4471 |
||
22926 | 4472 |
print:aTimeOrTimestamp compact:compact asLocal:asLocal asUTC:asUTC |
4473 |
withMilliseconds:withMillis timeSeparator:tSep timeOnly:timeOnly on:aStream |
|
4474 |
||
22834 | 4475 |
"Print the given timestamp in general ISO8601 format, |
4476 |
such as '2014-11-06T11:48:09Z'. |
|
4477 |
compact: if true, the compact format (without separating dashes and colons is generated) |
|
4478 |
asLocal: if true, generates a localtime string (without any timezone info) |
|
4479 |
asUTC: if true, generates a utc string |
|
4480 |
if both are false: |
|
4481 |
generate a string depending on the type of timestamp: |
|
4482 |
if local: generate a local timezone string |
|
4483 |
if utc: generate a utc string |
|
4484 |
otherwise it is a timestamp from another timezone (TZTimestamp), then print in its timezone |
|
4485 |
withMilliseconds: if false, no milliseconds are generated. |
|
22926 | 4486 |
if timeOnly is true, only the time is printed. |
4487 |
Warning: this has a feature (a bug) of implicitly suppressing fractional seconds, if the millis are zero. |
|
4488 |
this is strange, but for backward compatibility, left as is |
|
4489 |
(in case some printout depends on it)" |
|
4490 |
||
4491 |
|nDigits| |
|
4492 |
||
4493 |
nDigits := withMillis ifTrue:[3] ifFalse:[0]. |
|
4494 |
self |
|
4495 |
print:aTimeOrTimestamp |
|
4496 |
compact:compact asLocal:asLocal asUTC:asUTC |
|
4497 |
subSecondDigits:nDigits |
|
4498 |
suppressZeroSubSecondDigits:true |
|
4499 |
timeSeparator:tSep timeOnly:timeOnly on:aStream |
|
4500 |
||
16921 | 4501 |
|
4502 |
" |
|
4503 |
self print:(Timestamp now) on:Transcript |
|
22834 | 4504 |
self print:(Time now) on:Transcript |
16967 | 4505 |
self printAsLocalTime:(Timestamp now) on:Transcript |
4506 |
self printAsLocalTime:(Timestamp now asTZTimestamp:-7200) on:Transcript |
|
16921 | 4507 |
" |
4508 |
||
4509 |
"Created: / 15-06-2005 / 17:56:51 / masca" |
|
4510 |
! ! |
|
4511 |
||
16914 | 4512 |
!Timestamp::TimestampISO8601Builder class methodsFor:'public parsing'! |
4513 |
||
4514 |
read: stringOrStream withClass:timestampClass |
|
4515 |
^ self new read:stringOrStream withClass:timestampClass |
|
4516 |
||
4517 |
"Created: / 15-06-2005 / 17:52:03 / masca" |
|
4518 |
! |
|
4519 |
||
4520 |
read: stringOrStream withClass:timestampClass yearAlreadyReadAs:yearArg |
|
4521 |
"support for readers which may have already preread the year" |
|
4522 |
||
16945 | 4523 |
^ self new |
17006 | 4524 |
yearAlreadyReadAs:yearArg; |
4525 |
read:stringOrStream withClass:timestampClass |
|
16914 | 4526 |
|
4527 |
"Created: / 15-06-2005 / 17:52:03 / masca" |
|
4528 |
! ! |
|
4529 |
||
11993 | 4530 |
!Timestamp::TimestampISO8601Builder methodsFor:'private-reading'! |
4531 |
||
4532 |
nextDigit |
|
4533 |
| char | |
|
16939 | 4534 |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4535 |
char := stream peekOrNil. |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4536 |
char isNil ifTrue: [^-1]. |
11993 | 4537 |
|
17067 | 4538 |
char isDigit ifTrue: [ |
4539 |
stream next. |
|
4540 |
^ char codePoint - $0 codePoint |
|
4541 |
]. |
|
4542 |
^ -1 |
|
11993 | 4543 |
|
4544 |
"Created: / 14-06-2005 / 11:48:52 / masca" |
|
4545 |
! |
|
4546 |
||
4547 |
nextDigitOrError |
|
4548 |
||
4549 |
| digit | |
|
4550 |
digit := self nextDigit. |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4551 |
^ digit < 0 |
17006 | 4552 |
ifTrue: [self malformed: 'No digit found'] |
4553 |
ifFalse: [digit] |
|
11993 | 4554 |
|
4555 |
"Created: / 15-06-2005 / 10:57:00 / masca" |
|
4556 |
"Modified: / 15-06-2005 / 17:22:52 / masca" |
|
4557 |
! |
|
4558 |
||
4559 |
nextDigits: anInteger |
|
4560 |
||
4561 |
| char number | |
|
4562 |
number := 0. |
|
4563 |
anInteger timesRepeat: [ |
|
17006 | 4564 |
char := stream peekOrNil. |
4565 |
char ifNil: [self malformed: 'Stream does not contain all ' , anInteger printString , ' digits']. |
|
4566 |
char isDigit |
|
4567 |
ifTrue: [ |
|
4568 |
stream next. |
|
4569 |
number := number * 10 + char codePoint - $0 codePoint] |
|
4570 |
ifFalse: [self malformed: 'Requested ' , anInteger printString , ' digits not found'] |
|
11993 | 4571 |
]. |
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4572 |
^ number |
11993 | 4573 |
|
4574 |
"Created: / 14-06-2005 / 11:57:22 / masca" |
|
4575 |
"Modified: / 15-06-2005 / 15:54:29 / masca" |
|
4576 |
! ! |
|
4577 |
||
16914 | 4578 |
!Timestamp::TimestampISO8601Builder methodsFor:'public processing'! |
11993 | 4579 |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4580 |
read:stringOrStream withClass:timestampClass |
11993 | 4581 |
| peek | |
4582 |
||
4583 |
stream := stringOrStream readStream. |
|
4584 |
||
4585 |
month := day := 1. |
|
4586 |
hour := minute := second := millisecond := 0. |
|
16975 | 4587 |
isUtcTime := hasTimezone := false. |
4588 |
utcOffset := 0. |
|
11993 | 4589 |
|
16936 | 4590 |
yearAlreadyRead ~~ true ifTrue:[ |
17465 | 4591 |
"Read the year. This will read and swallow up to four year digits." |
4592 |
self readYear. |
|
16923 | 4593 |
]. |
11993 | 4594 |
|
4595 |
"Check if date has been read, ie. T or space necountered. If yes, read the time. |
|
4596 |
There is possible inconsistency - a dash may be read followed by T, which is not |
|
4597 |
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
|
4598 |
peek := stream peekOrNil. |
11993 | 4599 |
peek ifNil: [ |
17465 | 4600 |
"End of stream, only year has been read." |
4601 |
^ self timestampWithClass:timestampClass]. |
|
16955 | 4602 |
peek == $- ifTrue: [ |
17465 | 4603 |
"Skip the dash after year, if present." |
4604 |
stream next. |
|
4605 |
peek := stream peekOrNil]. |
|
11993 | 4606 |
peek := peek asUppercase. |
4607 |
||
17465 | 4608 |
(peek == $T or: [peek == Character space]) |
4609 |
ifTrue: [ |
|
4610 |
"Got time signature. Skip the signature, read time and answer the timestamp." |
|
4611 |
stream next. |
|
4612 |
peek == Character space ifTrue:[stream skipSeparators]. |
|
4613 |
self readTime. |
|
4614 |
self readTimezone. |
|
4615 |
^ self timestampWithClass:timestampClass |
|
4616 |
] |
|
4617 |
ifFalse: [ |
|
4618 |
"Date not read completely yet, expecting month/day or week/day or day" |
|
4619 |
peek == $W |
|
4620 |
ifTrue: [ |
|
4621 |
"Parse week number and (possibly) day number." |
|
4622 |
stream next. |
|
4623 |
self readWeekNumber] |
|
4624 |
ifFalse: [ |
|
4625 |
"Got digit, read month number followed by day or day number." |
|
4626 |
self readMonthOrDay] |
|
4627 |
]. |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4628 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4629 |
peek := stream peekOrNil. |
11993 | 4630 |
peek ifNil: [ |
22873 | 4631 |
"End of stream, only date has been read." |
17465 | 4632 |
^ self timestampWithClass:timestampClass]. |
16955 | 4633 |
|
4634 |
(peek asUppercase == $T or: [peek == Character space]) |
|
17465 | 4635 |
ifTrue: [ |
4636 |
"Got time signature, expecting time follows. Otherwise only date was in the stream." |
|
4637 |
stream next. |
|
4638 |
peek == Character space ifTrue:[stream skipSeparators]. |
|
4639 |
self readTime. |
|
4640 |
self readTimezone |
|
4641 |
]. |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4642 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4643 |
^ self timestampWithClass:timestampClass |
11993 | 4644 |
|
4645 |
"Created: / 14-06-2005 / 11:45:04 / masca" |
|
4646 |
"Modified: / 16-06-2005 / 10:15:35 / masca" |
|
4647 |
! ! |
|
4648 |
||
4649 |
!Timestamp::TimestampISO8601Builder methodsFor:'reading'! |
|
4650 |
||
16914 | 4651 |
readFraction |
4652 |
"Read an arbitrary number of digits representing a fraction." |
|
4653 |
||
16939 | 4654 |
^ Fraction readDecimalFractionFrom:stream onError:[self malformed: 'Missing digits after fraction separator']. |
22873 | 4655 |
|
4656 |
" |
|
4657 |
(Fraction readDecimalFractionFrom:'12345' readStream onError:nil) |
|
4658 |
" |
|
16914 | 4659 |
! |
4660 |
||
11993 | 4661 |
readMilliseconds |
22873 | 4662 |
"Read an arbitrary number of digits representing the fractional part |
4663 |
(used to be milliseconds, but now we can represent anything down to pico seconds" |
|
4664 |
||
4665 |
|fraction ms| |
|
4666 |
||
4667 |
fraction := self readFraction. "/ 0 .. 0.99999... |
|
4668 |
ms := (fraction * 1000). "/ 0 .. 999.999999 |
|
4669 |
millisecond := (ms // 1). "/ 0 .. 999 |
|
4670 |
picos := (ms \\ 1) * (1000 * 1000 * 1000). |
|
11993 | 4671 |
|
4672 |
"Created: / 15-06-2005 / 15:25:45 / masca" |
|
4673 |
! |
|
4674 |
||
4675 |
readMonthOrDay |
|
4676 |
"Read month number, optionally followed by day, or absolute day number (three digit)." |
|
4677 |
||
4678 |
| dayDigit1 dayDigit2 | |
|
4679 |
month := self nextDigits: 2. |
|
4680 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4681 |
stream peekOrNil = $- |
17006 | 4682 |
ifTrue: [ |
4683 |
"Got dash. Day number must follow." |
|
4684 |
stream next. |
|
4685 |
day := self nextDigits: 2. |
|
4686 |
(self isAllowedDay: day) ifFalse: [self malformed: 'Bad day: ' , day printString]. |
|
4687 |
^self]. |
|
11993 | 4688 |
|
4689 |
dayDigit1 := self nextDigit. |
|
4690 |
dayDigit1 < 0 ifTrue: [ |
|
17006 | 4691 |
"No more digits than month, leave day unspecified." |
4692 |
(month between: 1 and: 12) ifFalse: [self malformed: 'Bad month: ' , month printString]. |
|
4693 |
^self]. |
|
11993 | 4694 |
|
4695 |
dayDigit2 := self nextDigit. |
|
4696 |
dayDigit2 < 0 |
|
17006 | 4697 |
ifTrue: [ |
4698 |
"Read only three digits, this is absolute day number in a year." |
|
4699 |
self dateFromDayNumber: month * 10 + dayDigit1] |
|
4700 |
ifFalse: [ |
|
4701 |
"Read four digits. So there's month and day." |
|
4702 |
(month between: 1 and: 12) ifFalse: [self malformed: 'Bad month: ' , month printString]. |
|
4703 |
day := dayDigit1 * 10 + dayDigit2. |
|
4704 |
(self isAllowedDay: day) ifFalse: [self malformed: 'Bad day: ' , day printString]] |
|
11993 | 4705 |
|
4706 |
"Created: / 15-06-2005 / 11:12:02 / masca" |
|
4707 |
"Modified: / 16-06-2005 / 11:47:34 / masca" |
|
4708 |
! |
|
4709 |
||
4710 |
readTime |
|
22873 | 4711 |
"Date already read, don't mind it. |
4712 |
Read only the time value." |
|
11993 | 4713 |
|
16914 | 4714 |
| peek f | |
11993 | 4715 |
|
4716 |
hour := self nextDigits: 2. |
|
4717 |
(hour between: 0 and: 24) ifFalse: [self malformed: 'Bad hour: ' , hour printString]. |
|
4718 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4719 |
peek := stream peekOrNil. |
16914 | 4720 |
peek isNil ifTrue: [^self]. |
4721 |
(peek == $:) ifTrue: [ |
|
20817 | 4722 |
"/ read minutes |
4723 |
stream next. |
|
4724 |
minute := self nextDigits: 2. |
|
16914 | 4725 |
] ifFalse: [ |
20817 | 4726 |
peek isDigit ifTrue: [ |
4727 |
"/ read minutes |
|
4728 |
minute := self nextDigits: 2. |
|
4729 |
] ifFalse:[ |
|
4730 |
(peek == $. or:[peek == $,]) ifTrue:[ |
|
4731 |
stream next. |
|
4732 |
minute := self readFraction * 60. |
|
4733 |
] ifFalse:[ |
|
4734 |
^ self. |
|
4735 |
]. |
|
4736 |
] |
|
16914 | 4737 |
]. |
4738 |
||
4739 |
minute isInteger ifFalse:[ |
|
20817 | 4740 |
f := minute. |
4741 |
minute := f truncated. |
|
4742 |
second := (f - minute) * 60. |
|
4743 |
second isInteger ifFalse:[ |
|
4744 |
f := second. |
|
4745 |
second := f truncated. |
|
4746 |
millisecond := (f - second) * 1000. |
|
4747 |
millisecond := millisecond rounded. |
|
4748 |
]. |
|
16914 | 4749 |
]. |
11993 | 4750 |
(minute between: 0 and: 59) ifFalse: [self malformed: 'Bad minute: ' , minute printString]. |
4751 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4752 |
peek := stream peekOrNil. |
16914 | 4753 |
peek isNil ifTrue: [^self]. |
4754 |
(peek == $:) ifTrue: [ |
|
20817 | 4755 |
"/ read seconds |
4756 |
stream next. |
|
4757 |
second := self nextDigits: 2. |
|
16914 | 4758 |
] ifFalse: [ |
20817 | 4759 |
peek isDigit ifTrue: [ |
4760 |
"/ read seconds |
|
4761 |
second := self nextDigits: 2. |
|
4762 |
] ifFalse:[ |
|
4763 |
(peek == $. or:[peek == $,]) ifTrue:[ |
|
4764 |
stream next. |
|
4765 |
second := self readFraction * 60. |
|
4766 |
] ifFalse:[ |
|
4767 |
^ self. |
|
4768 |
]. |
|
4769 |
] |
|
16914 | 4770 |
]. |
4771 |
||
4772 |
second isInteger ifFalse:[ |
|
20817 | 4773 |
f := second. |
4774 |
second := f truncated. |
|
4775 |
millisecond := (f - second) * 1000. |
|
4776 |
millisecond := millisecond rounded. |
|
16914 | 4777 |
]. |
11993 | 4778 |
(second between: 0 and: 59) ifFalse: [ |
20817 | 4779 |
"Seconds are usually in this range, do a special check for leap seconds." |
4780 |
second <= 61 |
|
4781 |
ifTrue: [ |
|
4782 |
"Leap seconds can occur only on midnight on 31.12. or 30.6. Don't check year |
|
4783 |
as it's not deterministic." |
|
4784 |
(minute = 59 and: [hour = 23 and: [(month = 12 and: [day = 31]) or: [month = 6 and: [day = 30]]]]) |
|
4785 |
ifFalse: [self malformed: 'Bad leap second']] |
|
4786 |
ifFalse: [self malformed: 'Bad second: ' , second printString] |
|
11993 | 4787 |
]. |
4788 |
||
4789 |
"Hour, minute and second read. Read appendices." |
|
16914 | 4790 |
((peek := stream peekOrNil) == $. or:[peek == $,]) |
20817 | 4791 |
ifTrue: [ |
4792 |
"Read dot. Skip it and read milliseconds." |
|
4793 |
stream next. |
|
4794 |
self readMilliseconds]. |
|
11993 | 4795 |
|
4796 |
hour = 24 ifTrue: [ |
|
20817 | 4797 |
(minute = 0 and: [second = 0 and: [millisecond = 0]]) |
4798 |
ifTrue: [ |
|
4799 |
"On 24 hour, advance to the next day." |
|
4800 |
"hour := 0. |
|
4801 |
self addMinutes: 1440"] |
|
4802 |
ifFalse: [self malformed: 'Bad 24 hour (minutes, seconds and millis not 0)'] |
|
11993 | 4803 |
] |
4804 |
||
4805 |
"Created: / 14-06-2005 / 17:27:00 / masca" |
|
4806 |
"Modified: / 30-06-2005 / 11:34:38 / masca" |
|
4807 |
! |
|
4808 |
||
4809 |
readTimezone |
|
4810 |
"Read time zone information. There are three possibilities of what can occur. |
|
22873 | 4811 |
If there is nothing more to read, the offset is unknown - this is treated as |
4812 |
Zulu time as this may not be true." |
|
11993 | 4813 |
|
19916 | 4814 |
| peek tzOffset | |
16975 | 4815 |
|
11993 | 4816 |
peek := stream peek. |
4817 |
peek ifNil: [^self]. |
|
4818 |
peek := peek asUppercase. |
|
4819 |
||
4820 |
"If the time is in Zulu, don't modify the timestamp. This makes the machine |
|
22873 | 4821 |
run in Zulu time zone, maybe some corrections would be nice." |
19916 | 4822 |
peek == $Z ifTrue: [ |
4823 |
"Time read, skip Zulu signature and exit." |
|
4824 |
isUtcTime := true. |
|
4825 |
stream next. |
|
4826 |
^ self |
|
4827 |
]. |
|
4828 |
||
4829 |
(peek == $+ or:[peek == $-]) ifTrue: [ |
|
4830 |
"Read a plus/minus, expect a negative/positive time zone difference." |
|
4831 |
hasTimezone := true. |
|
4832 |
stream next. |
|
4833 |
tzOffset := self readTimezoneOffset. |
|
19917 | 4834 |
peek == $+ ifTrue:[ |
19916 | 4835 |
tzOffset := tzOffset collect: [:e | e negated]. |
4836 |
]. |
|
4837 |
self addHoursAndMinutes: tzOffset. |
|
4838 |
^ self |
|
4839 |
]. |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4840 |
|
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4841 |
"This is local time" |
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4842 |
isUtcTime := false. |
16975 | 4843 |
hasTimezone := false. |
11993 | 4844 |
|
4845 |
"Created: / 16-06-2005 / 09:54:21 / masca" |
|
4846 |
! |
|
4847 |
||
4848 |
readTimezoneOffset |
|
4849 |
"Read time zone offset as a number minutes. Generally, there should be hours only |
|
22873 | 4850 |
but as the format introduces minutes in offsets, we must accept them. |
4851 |
(actually: there are countries with half-hour offsets!!)" |
|
11993 | 4852 |
|
4853 |
| hours digit | |
|
4854 |
||
4855 |
"Read hours." |
|
4856 |
hours := self nextDigits: 2. |
|
4857 |
(hours between: 0 and: 12) ifFalse: [self malformed: 'Bad offset hour: ' , hours printString]. |
|
4858 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4859 |
stream peekOrNil = $: |
22873 | 4860 |
ifTrue: [ |
4861 |
"Colon read, minutes must follow." |
|
4862 |
stream next. |
|
4863 |
digit := self nextDigits: 2. |
|
4864 |
(digit between: 0 and: 59) ifFalse: [self malformed: 'Bad offset minute: ' , digit printString]. |
|
4865 |
^Array with: hours with: digit]. |
|
11993 | 4866 |
|
4867 |
"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
|
4868 |
check boundaries." |
11993 | 4869 |
digit := self nextDigit. |
4870 |
digit < 0 ifTrue: [^Array with: hours with: 0]. |
|
4871 |
digit >= 6 ifTrue: [self malformed: 'Bad offset minute: ' , (digit * 10) printString]. |
|
4872 |
||
4873 |
"Read the last digit of offset, it must be present." |
|
4874 |
^Array with: hours with: digit * 10 + self nextDigitOrError |
|
4875 |
||
4876 |
"Created: / 15-06-2005 / 15:35:41 / masca" |
|
4877 |
"Modified: / 15-06-2005 / 17:45:58 / masca" |
|
4878 |
! |
|
4879 |
||
4880 |
readWeekNumber |
|
22873 | 4881 |
"Read week number. It is always two digits long." |
11993 | 4882 |
|
16914 | 4883 |
| week dayInWeek digit | |
4884 |
||
11993 | 4885 |
week := self nextDigits: 2. |
4886 |
||
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4887 |
stream peekOrNil = $- |
22873 | 4888 |
ifTrue: [ |
4889 |
"Got dash, day number must follow." |
|
4890 |
stream next. |
|
4891 |
digit := self nextDigit. |
|
4892 |
digit < 0 ifTrue: [self malformed: 'Bad weekday number']. |
|
4893 |
digit > 7 ifTrue: [self malformed: 'Bad weekday number']. |
|
4894 |
self dateFromWeek: week andWeekday: digit. |
|
4895 |
^self]. |
|
11993 | 4896 |
|
4897 |
"Read day number that follows the week. If the number is not given, consider it monday." |
|
16914 | 4898 |
dayInWeek := self nextDigit. |
4899 |
dayInWeek <= 0 ifTrue: [dayInWeek := 1]. |
|
4900 |
dayInWeek > 7 ifTrue: [self malformed: 'Bad weekday number']. |
|
4901 |
||
4902 |
self dateFromWeek: week andWeekday: dayInWeek |
|
11993 | 4903 |
|
4904 |
"Created: / 14-06-2005 / 12:06:47 / masca" |
|
4905 |
"Modified: / 15-06-2005 / 15:53:34 / masca" |
|
4906 |
! |
|
4907 |
||
4908 |
readYear |
|
4909 |
"Read YYYY or :Y (broken decade) from the stream. Also handles correctly YY- and YYY-." |
|
4910 |
||
4911 |
| read peek | |
|
13236
74872163b47b
Support subclass UtcTimestamp -
Stefan Vogel <sv@exept.de>
parents:
13225
diff
changeset
|
4912 |
stream peekOrNil = $: |
17465 | 4913 |
ifTrue: [ |
4914 |
"Broken two digit year > 1999 follows." |
|
4915 |
stream next. |
|
4916 |
year := self nextDigitOrError + 2000. |
|
4917 |
^self]. |
|
11993 | 4918 |
|
4919 |
"Expecting two-, three- or four-digit year" |
|
4920 |
"Read the first two digits. They must be there." |
|
4921 |
read := self nextDigits: 2. |
|
4922 |
||
4923 |
"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
|
4924 |
peek := stream peekOrNil. |
11993 | 4925 |
peek ifNil: [^self]. |
4926 |
||
17067 | 4927 |
((peek == $-) or:[peek == $W]) |
17465 | 4928 |
ifTrue: [ |
4929 |
"OK, got two digits. These are expected to be the year after 1970." |
|
4930 |
year := read < 70 |
|
4931 |
ifTrue: [read + 2000] |
|
4932 |
ifFalse: [read + 1900] |
|
4933 |
] ifFalse: [ |
|
4934 |
"Read the next digit for the case of three-digit year after 1900 (ie. year > 1999)." |
|
4935 |
read := read * 10 + self nextDigitOrError. |
|
4936 |
peek := stream peekOrNil. |
|
4937 |
(peek isNil or: [peek == $-]) |
|
4938 |
ifTrue: [ |
|
4939 |
"Read three digit year, return it." |
|
4940 |
year := read + 1900 |
|
4941 |
] ifFalse: [ |
|
4942 |
"Read the fourth digit of the year. These can be month digits but the |
|
4943 |
two-digit year format is deprecated anyway." |
|
4944 |
read := read * 10 + self nextDigitOrError. |
|
4945 |
year := read. |
|
4946 |
] |
|
4947 |
] |
|
11993 | 4948 |
|
4949 |
"Created: / 14-06-2005 / 12:01:11 / masca" |
|
4950 |
"Modified: / 15-06-2005 / 17:31:56 / masca" |
|
4951 |
! ! |
|
4952 |
||
8246 | 4953 |
!Timestamp class methodsFor:'documentation'! |
699 | 4954 |
|
4955 |
version |
|
18761 | 4956 |
^ '$Header$' |
12164
b87f20d77369
added: #readShortGeneralizedFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
11994
diff
changeset
|
4957 |
! |
b87f20d77369
added: #readShortGeneralizedFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
11994
diff
changeset
|
4958 |
|
b87f20d77369
added: #readShortGeneralizedFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
11994
diff
changeset
|
4959 |
version_CVS |
18761 | 4960 |
^ '$Header$' |
699 | 4961 |
! ! |
8246 | 4962 |
|
14713 | 4963 |
|
8246 | 4964 |
Timestamp initialize! |